2015-02-27 09:28:22 +00:00
|
|
|
import re
|
|
|
|
from django import forms
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
|
|
|
|
|
|
|
class AddStgPool(forms.Form):
|
2020-07-13 09:33:09 +00:00
|
|
|
name = forms.CharField(error_messages={'required': _('No pool name has been entered')}, max_length=20)
|
2015-02-27 09:28:22 +00:00
|
|
|
stg_type = forms.CharField(max_length=10)
|
2020-07-13 09:33:09 +00:00
|
|
|
target = forms.CharField(error_messages={'required': _('No path has been entered')}, max_length=100, required=False)
|
2015-02-27 09:28:22 +00:00
|
|
|
source = forms.CharField(max_length=100, required=False)
|
|
|
|
ceph_user = forms.CharField(required=False)
|
|
|
|
ceph_host = forms.CharField(required=False)
|
|
|
|
ceph_pool = forms.CharField(required=False)
|
|
|
|
secret = forms.CharField(required=False)
|
|
|
|
netfs_host = forms.CharField(required=False)
|
|
|
|
source_format = forms.CharField(required=False)
|
|
|
|
|
|
|
|
def clean_name(self):
|
|
|
|
name = self.cleaned_data['name']
|
|
|
|
have_symbol = re.match('^[a-zA-Z0-9._-]+$', name)
|
|
|
|
if not have_symbol:
|
|
|
|
raise forms.ValidationError(_('The pool name must not contain any special characters'))
|
|
|
|
elif len(name) > 20:
|
|
|
|
raise forms.ValidationError(_('The pool name must not exceed 20 characters'))
|
|
|
|
return name
|
|
|
|
|
|
|
|
def clean_target(self):
|
|
|
|
storage_type = self.cleaned_data['stg_type']
|
|
|
|
target = self.cleaned_data['target']
|
|
|
|
have_symbol = re.match('^[a-zA-Z0-9/]+$', target)
|
2015-03-11 19:31:08 +00:00
|
|
|
if storage_type == 'dir' or storage_type == 'netfs':
|
|
|
|
if not have_symbol:
|
|
|
|
raise forms.ValidationError(_('The target must not contain any special characters'))
|
|
|
|
if storage_type == 'dir' or storage_type == 'netfs':
|
2015-02-27 09:28:22 +00:00
|
|
|
if not target:
|
|
|
|
raise forms.ValidationError(_('No path has been entered'))
|
|
|
|
return target
|
|
|
|
|
|
|
|
def clean_source(self):
|
|
|
|
storage_type = self.cleaned_data['stg_type']
|
|
|
|
source = self.cleaned_data['source']
|
|
|
|
have_symbol = re.match('^[a-zA-Z0-9\/]+$', source)
|
|
|
|
if storage_type == 'logical' or storage_type == 'netfs':
|
|
|
|
if not source:
|
2020-06-10 08:15:14 +00:00
|
|
|
raise forms.ValidationError(_('No device or path has been entered'))
|
2015-02-27 09:28:22 +00:00
|
|
|
if not have_symbol:
|
2020-06-10 08:15:14 +00:00
|
|
|
raise forms.ValidationError(_('The disk source must not contain any special characters'))
|
2015-02-27 09:28:22 +00:00
|
|
|
return source
|
|
|
|
|
|
|
|
|
2020-07-13 09:33:09 +00:00
|
|
|
class CreateVolumeForm(forms.Form):
|
2018-07-25 06:33:06 +00:00
|
|
|
name = forms.CharField(max_length=120)
|
2020-07-13 09:33:09 +00:00
|
|
|
format = forms.ChoiceField(required=True, choices=(('qcow2', 'qcow2 (recommended)'), ('qcow', 'qcow'), ('raw', 'raw')))
|
2015-02-27 09:28:22 +00:00
|
|
|
size = forms.IntegerField()
|
|
|
|
meta_prealloc = forms.BooleanField(required=False)
|
|
|
|
|
|
|
|
def clean_name(self):
|
|
|
|
name = self.cleaned_data['name']
|
|
|
|
have_symbol = re.match('^[a-zA-Z0-9._-]+$', name)
|
|
|
|
if not have_symbol:
|
|
|
|
raise forms.ValidationError(_('The image name must not contain any special characters'))
|
|
|
|
return name
|
|
|
|
|
|
|
|
|
|
|
|
class CloneImage(forms.Form):
|
2018-07-25 06:33:06 +00:00
|
|
|
name = forms.CharField(max_length=120)
|
|
|
|
image = forms.CharField(max_length=120)
|
2015-02-27 09:28:22 +00:00
|
|
|
convert = forms.BooleanField(required=False)
|
2020-07-13 09:33:09 +00:00
|
|
|
format = forms.ChoiceField(required=False, choices=(('qcow2', 'qcow2 (recommended)'), ('qcow', 'qcow'), ('raw', 'raw')))
|
2015-02-27 09:28:22 +00:00
|
|
|
meta_prealloc = forms.BooleanField(required=False)
|
|
|
|
|
|
|
|
def clean_name(self):
|
|
|
|
name = self.cleaned_data['name']
|
|
|
|
have_symbol = re.match('^[a-zA-Z0-9._-]+$', name)
|
|
|
|
if not have_symbol:
|
|
|
|
raise forms.ValidationError(_('The image name must not contain any special characters'))
|
2018-07-25 06:33:06 +00:00
|
|
|
elif len(name) > 120:
|
|
|
|
raise forms.ValidationError(_('The image name must not exceed 120 characters'))
|
2015-02-27 09:28:22 +00:00
|
|
|
return name
|