Commit d4737b15 by Kálmán Viktor

dashboard: add disks via URL in template edit

parent 5cbfba57
from datetime import timedelta from datetime import timedelta
import uuid
from django.contrib.auth.models import User from django.contrib.auth.models import User
...@@ -759,26 +758,29 @@ class DiskAddForm(forms.Form): ...@@ -759,26 +758,29 @@ class DiskAddForm(forms.Form):
def save(self, commit=True): def save(self, commit=True):
data = self.cleaned_data data = self.cleaned_data
if data['size']:
d = Disk(
name=data['name'],
filename=str(uuid.uuid4()),
datastore=DataStore.objects.all()[0],
type="qcow2-norm",
size=data['size'],
dev_num="a",
)
d.save()
else:
# TODO
d = None
if self.is_template: if self.is_template:
vm_or_temp = InstanceTemplate.objects.get(pk=self.object_pk) inst = InstanceTemplate.objects.get(pk=self.object_pk)
else: else:
vm_or_temp = Instance.objects.get(pk=self.object_pk) inst = Instance.objects.get(pk=self.object_pk)
vm_or_temp.disks.add(d) if data['size']:
kwargs = {
'name': data['name'],
'type': "qcow2-norm",
'datastore': DataStore.objects.all()[0],
'size': data['size'],
'dev_num': "a",
}
d = Disk.create_empty(instance=inst, user=None, **kwargs)
else:
kwargs = {
'name': data['name'],
'datastore': DataStore.objects.all()[0],
'dev_num': "a",
}
Disk.create_from_url_async(data['url'], instance=inst,
user=None, **kwargs)
d = None
return d return d
......
...@@ -9,7 +9,7 @@ from .views import ( ...@@ -9,7 +9,7 @@ from .views import (
FavouriteView, NodeStatus, GroupList, TemplateDelete, LeaseDelete, FavouriteView, NodeStatus, GroupList, TemplateDelete, LeaseDelete,
VmGraphView, TemplateAclUpdateView, GroupDetailView, GroupDelete, VmGraphView, TemplateAclUpdateView, GroupDetailView, GroupDelete,
GroupAclUpdateView, GroupUserDelete, NotificationView, NodeGraphView, GroupAclUpdateView, GroupUserDelete, NotificationView, NodeGraphView,
VmMigrateView, DiskAddVie, VmDetailVncTokenView, VmMigrateView, DiskAddView, VmDetailVncTokenView,
) )
urlpatterns = patterns( urlpatterns = patterns(
......
...@@ -744,11 +744,13 @@ class TemplateDetail(LoginRequiredMixin, SuccessMessageMixin, UpdateView): ...@@ -744,11 +744,13 @@ class TemplateDetail(LoginRequiredMixin, SuccessMessageMixin, UpdateView):
return super(TemplateDetail, self).get(request, *args, **kwargs) return super(TemplateDetail, self).get(request, *args, **kwargs)
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
obj = self.get_object()
context = super(TemplateDetail, self).get_context_data(**kwargs) context = super(TemplateDetail, self).get_context_data(**kwargs)
context['acl'] = get_vm_acl_data(self.get_object()) context['acl'] = get_vm_acl_data(obj)
context['disks'] = obj.disks.all()
context['disk_add_form'] = DiskAddForm( context['disk_add_form'] = DiskAddForm(
is_template=True, is_template=True,
object_pk=self.get_object().pk, object_pk=obj.pk,
prefix="disk", prefix="disk",
) )
return context return context
......
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