27 from django
import forms
28 from django.utils.translation
import ugettext_lazy
as _
30 from wi.forms.vm
import EditVMForm
31 from wi.utils
import parsing
32 from wi.utils.forms
import NumberChoice
33 from wi.utils.views
import make_request
34 from wi.utils.widgets
import SelectWithDisabled, CheckboxSelectMultipleWithDisabled
42 image_id = forms.CharField(widget=forms.HiddenInput())
45 super(CreateFarmForm1, self).
__init__(*args, **kwargs)
52 if int(self.cleaned_data[
'image_id']) < 0:
53 raise forms.ValidationError(_(
"Please select an image."))
55 return int(self.cleaned_data[
'image_id'])
64 rest_data = kwargs.pop(
'rest_data')
66 super(CreateFarmForm2, self).
__init__(*args, **kwargs)
68 self.fields[
'head_template_id'] = forms.ChoiceField(choices=parsing.parse_template_names(rest_data),
70 widget=SelectWithDisabled(attrs=dict()),
71 label=_(
'Head template'))
73 self.fields[
'worker_template_id'] = forms.ChoiceField(choices=parsing.parse_template_names(rest_data),
75 widget=SelectWithDisabled(attrs=dict()),
76 label=_(
'Worker node template'),
77 help_text=_(
'Template of worker nodes - worker nodes parameters'))
79 self.fields[
'count'] = forms.ChoiceField(choices=NumberChoice(24),
81 widget=forms.Select(attrs=dict({
'class':
'xsmall'})),
82 label=_(
'Number of worker nodes'),
83 help_text=_(
'Number of worker nodes - (other than head)'))
90 if int(self.cleaned_data[
'head_template_id']) < 0:
91 raise forms.ValidationError(_(
"Please select a template."))
93 return int(self.cleaned_data[
'head_template_id'])
100 if int(self.cleaned_data[
'worker_template_id']) < 0:
101 raise forms.ValidationError(_(
"Please select a template."))
103 return int(self.cleaned_data[
'worker_template_id'])
110 return int(self.cleaned_data[
'count'])
117 if not self.cleaned_data.get(
'count')
or not self.cleaned_data.get(
'worker_template_id')
or not self.cleaned_data.get(
'head_template_id'):
121 {
'count': self.cleaned_data.get(
'count'),
122 'template_id': self.cleaned_data.get(
'worker_template_id'),
123 'head_template_id': self.cleaned_data.get(
'head_template_id')
126 if response[
'status'] ==
'ok' and response[
'data'] ==
False:
127 raise forms.ValidationError(_(
"Not enough resources. Choose smaller farm or try again later."))
129 return self.cleaned_data
138 rest_data = kwargs.pop(
'rest_data')
139 super(CreateFarmForm3, self).
__init__(*args, **kwargs)
141 self.fields[
'public_ip_id'] = forms.ChoiceField(choices=parsing.parse_ips(rest_data),
143 widget=SelectWithDisabled(attrs=dict()),
144 label=_(
'Assign IP address'),
145 help_text=_(
'Public IP address - To request new IP address go to: VM Resources -> Elastic IP addresses'))
147 self.fields[
'disk_list'] = forms.MultipleChoiceField(choices=parsing.parse_disks(rest_data,
False),
149 widget=CheckboxSelectMultipleWithDisabled,
150 label=_(
'Attach disk volume'),
151 help_text=_(
'Virtual disk - '))
153 self.fields[
'iso_list'] = forms.ChoiceField(choices=parsing.parse_iso(rest_data),
155 widget=SelectWithDisabled(attrs=dict()),
156 label=_(
"Attach ISO image"))
158 self.fields[
'vnc'] = forms.BooleanField(required=
False,
160 widget=forms.CheckboxInput(attrs={
'class':
'checkbox'}),
161 help_text=_(
'VNC - Enable/Disable VNC redirection'))
163 self.fields.keyOrder = [
'public_ip_id',
'disk_list',
'iso_list',
'vnc']
170 return int(self.cleaned_data[
'public_ip_id'])
177 for i
in self.cleaned_data[
'disk_list']:
180 return [int(a)
for a
in self.cleaned_data[
'disk_list']]
187 if int(self.cleaned_data[
'iso_list']) < 0:
189 return [int(self.cleaned_data[
'iso_list'])]
198 super(CreateFarmForm4, self).
__init__(*args, **kwargs)
199 self.fields.keyOrder = [
'name',
'description']