Commit 198ec637 by Őry Máté

dashboard: add Vm{Create,Download}DiskForm

parent d84501eb
......@@ -846,6 +846,12 @@ class LeaseForm(forms.ModelForm):
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):
size_in_bytes = self.cleaned_data.get("size")
......@@ -854,66 +860,23 @@ class LeaseForm(forms.ModelForm):
" GB or MB!"))
return size_in_bytes
def clean(self):
cleaned_data = self.cleaned_data
size = cleaned_data.get("size")
url = cleaned_data.get("url")
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
def helper(self):
helper = FormHelper(self)
helper.form_tag = False
return helper
if self.is_template:
inst = InstanceTemplate.objects.get(pk=self.object_pk)
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)
kwargs = {
'name': data['name'],
'url': data['url'],
Disk.create_from_url_async(instance=inst, user=self.user,
d = None
return d
class VmDownloadDiskForm(forms.Form):
name = forms.CharField(max_length=100, label=_("Name"))
url = forms.CharField()
def helper(self):
helper = FormHelper()
helper.form_show_labels = False
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, "
Field("url", placeholder=_("URL to an ISO image")),
_("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"),
helper = FormHelper(self)
helper.add_input(Submit("submit", _("Create"),
css_class="btn btn-success"))
helper.form_tag = False
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