Commit 198ec637 by Őry Máté

dashboard: add Vm{Create,Download}DiskForm

parent d84501eb
...@@ -846,6 +846,12 @@ class LeaseForm(forms.ModelForm): ...@@ -846,6 +846,12 @@ class LeaseForm(forms.ModelForm):
model = Lease model = Lease
class VmCreateDiskForm(forms.Form):
name = forms.CharField(max_length=100, label=_("Name"))
size = forms.CharField(
widget=FileSizeWidget, initial=10<<30, label=_('Size'),
help_text=_('Size of disk to create in bytes or with units '
'like MB or GB.'))
def clean_size(self): def clean_size(self):
size_in_bytes = self.cleaned_data.get("size") size_in_bytes = self.cleaned_data.get("size")
...@@ -854,66 +860,23 @@ class LeaseForm(forms.ModelForm): ...@@ -854,66 +860,23 @@ class LeaseForm(forms.ModelForm):
" GB or MB!")) " GB or MB!"))
return size_in_bytes return size_in_bytes
def clean(self): @property
cleaned_data = self.cleaned_data def helper(self):
size = cleaned_data.get("size") helper = FormHelper(self)
url = cleaned_data.get("url") helper.form_tag = False
return helper
if not size and not url:
msg = _("You have to either specify size or URL")
self._errors[_("Global")] = self.error_class([msg])
return cleaned_data
def save(self, commit=True):
data = self.cleaned_data
if self.is_template: class VmDownloadDiskForm(forms.Form):
inst = InstanceTemplate.objects.get(pk=self.object_pk) name = forms.CharField(max_length=100, label=_("Name"))
else: url = forms.CharField()
inst = Instance.objects.get(pk=self.object_pk)
if data['size']:
kwargs = {
'name': data['name'],
'type': "qcow2-norm",
'datastore': DataStore.objects.all()[0],
'size': data['size'],
}
d = Disk.create_empty(instance=inst, user=self.user, **kwargs)
else:
kwargs = {
'name': data['name'],
'url': data['url'],
}
Disk.create_from_url_async(instance=inst, user=self.user,
**kwargs)
d = None
return d
@property @property
def helper(self): def helper(self):
helper = FormHelper() helper = FormHelper(self)
helper.form_show_labels = False helper.add_input(Submit("submit", _("Create"),
helper.layout = Layout(
Field("is_template", type="hidden"),
Field("object_pk", type="hidden"),
Field("name", placeholder=_("Name")),
Field("size", placeholder=_("Disk size (for example: 20GB, "
"1500MB)")),
Field("url", placeholder=_("URL to an ISO image")),
AnyTag(
"div",
HTML(
_("Either specify the size for an empty disk or a URL "
"to an ISO image!")
),
css_class="alert alert-info",
style="padding: 5px; text-align: justify;",
),
)
helper.add_input(Submit("submit", _("Add"),
css_class="btn btn-success")) css_class="btn btn-success"))
helper.form_tag = False
return helper return helper
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment