2015-02-27 12:25:41 +00:00
|
|
|
import re
|
|
|
|
from django import forms
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2015-02-27 12:44:44 +00:00
|
|
|
from create.models import Flavor
|
2018-09-14 13:23:25 +00:00
|
|
|
from webvirtcloud.settings import QEMU_CONSOLE_LISTEN_ADDRESSES
|
2015-02-27 12:25:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
class FlavorAddForm(forms.Form):
|
|
|
|
label = forms.CharField(label="Name",
|
|
|
|
error_messages={'required': _('No flavor name has been entered')},
|
2019-11-08 17:07:02 +00:00
|
|
|
max_length=64)
|
2015-02-27 12:25:41 +00:00
|
|
|
vcpu = forms.IntegerField(label="VCPU",
|
|
|
|
error_messages={'required': _('No VCPU has been entered')}, )
|
|
|
|
disk = forms.IntegerField(label="HDD",
|
|
|
|
error_messages={'required': _('No HDD image has been entered')}, )
|
|
|
|
memory = forms.IntegerField(label="RAM",
|
|
|
|
error_messages={'required': _('No RAM size has been entered')}, )
|
|
|
|
|
|
|
|
def clean_name(self):
|
|
|
|
label = self.cleaned_data['label']
|
|
|
|
have_symbol = re.match('^[a-zA-Z0-9._-]+$', label)
|
|
|
|
if not have_symbol:
|
|
|
|
raise forms.ValidationError(_('The flavor name must not contain any special characters'))
|
2019-11-08 17:07:02 +00:00
|
|
|
elif len(label) > 64:
|
2015-02-27 12:25:41 +00:00
|
|
|
raise forms.ValidationError(_('The flavor name must not exceed 20 characters'))
|
|
|
|
try:
|
|
|
|
Flavor.objects.get(label=label)
|
|
|
|
except Flavor.DoesNotExist:
|
|
|
|
return label
|
|
|
|
raise forms.ValidationError(_('Flavor name is already use'))
|
|
|
|
|
|
|
|
|
|
|
|
class NewVMForm(forms.Form):
|
|
|
|
name = forms.CharField(error_messages={'required': _('No Virtual Machine name has been entered')},
|
2019-11-08 17:07:02 +00:00
|
|
|
max_length=64)
|
2019-12-13 13:47:51 +00:00
|
|
|
firmware = forms.CharField(max_length=50, required=False)
|
2015-02-27 12:25:41 +00:00
|
|
|
vcpu = forms.IntegerField(error_messages={'required': _('No VCPU has been entered')})
|
2019-12-13 13:47:51 +00:00
|
|
|
vcpu_mode = forms.CharField(max_length=20, required=False)
|
2015-02-27 12:25:41 +00:00
|
|
|
disk = forms.IntegerField(required=False)
|
|
|
|
memory = forms.IntegerField(error_messages={'required': _('No RAM size has been entered')})
|
2018-11-16 13:03:32 +00:00
|
|
|
networks = forms.CharField(error_messages={'required': _('No Network pool has been choosen')})
|
2018-09-24 11:41:13 +00:00
|
|
|
nwfilter = forms.CharField(required=False)
|
2015-02-27 12:25:41 +00:00
|
|
|
storage = forms.CharField(max_length=20, required=False)
|
|
|
|
template = forms.CharField(required=False)
|
|
|
|
images = forms.CharField(required=False)
|
2016-04-17 21:41:40 +00:00
|
|
|
cache_mode = forms.CharField(error_messages={'required': _('Please select HDD cache mode')})
|
2015-02-27 12:25:41 +00:00
|
|
|
hdd_size = forms.IntegerField(required=False)
|
|
|
|
meta_prealloc = forms.BooleanField(required=False)
|
|
|
|
virtio = forms.BooleanField(required=False)
|
2018-11-26 12:40:02 +00:00
|
|
|
qemu_ga = forms.BooleanField(required=False)
|
2015-02-27 12:25:41 +00:00
|
|
|
mac = forms.CharField(required=False)
|
2019-12-13 13:47:51 +00:00
|
|
|
console_pass = forms.CharField(required=False, empty_value="", widget=forms.PasswordInput())
|
|
|
|
graphics = forms.CharField(error_messages={'required': _('Please select a graphics type')})
|
|
|
|
video = forms.CharField(error_messages={'required': _('Please select a video driver')})
|
2018-09-14 13:23:25 +00:00
|
|
|
listener_addr = forms.ChoiceField(required=True, widget=forms.RadioSelect, choices=QEMU_CONSOLE_LISTEN_ADDRESSES)
|
2015-02-27 12:25:41 +00:00
|
|
|
|
|
|
|
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 name of the virtual machine must not contain any special characters'))
|
2019-11-08 17:07:02 +00:00
|
|
|
elif len(name) > 64:
|
2015-02-27 12:25:41 +00:00
|
|
|
raise forms.ValidationError(_('The name of the virtual machine must not exceed 20 characters'))
|
|
|
|
return name
|
2018-09-14 13:23:25 +00:00
|
|
|
|