Commit 9daef8ff by Dudás Ádám

vm: discard incomplete template on error

fixes #67
parent 6ab9e981
...@@ -935,23 +935,31 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel): ...@@ -935,23 +935,31 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
kwargs.setdefault('access_method', self.access_method) kwargs.setdefault('access_method', self.access_method)
kwargs.setdefault('system', self.template.system kwargs.setdefault('system', self.template.system
if self.template else None) if self.template else None)
# create template and do additional setup
tmpl = InstanceTemplate(**kwargs) def __try_save_disk(disk):
# save template
tmpl.save()
# create related entities
for disk in self.disks.all():
try: try:
d = disk.save_as() return disk.save_as()
except Disk.WrongDiskTypeError: except Disk.WrongDiskTypeError:
d = disk return disk
tmpl.disks.add(d) # copy disks
disks = [__try_save_disk(disk) for disk in self.disks.all()]
kwargs.setdefault('disks', disks)
for i in self.interface_set.all(): # create template and do additional setup
i.save_as_template(tmpl) tmpl = InstanceTemplate(**kwargs)
return tmpl # save template
tmpl.save()
try:
# create interface templates
for i in self.interface_set.all():
i.save_as_template(tmpl)
except:
tmpl.delete()
raise
else:
return tmpl
def shutdown_and_save_as_template(self, name, user=None, task_uuid=None, def shutdown_and_save_as_template(self, name, user=None, task_uuid=None,
**kwargs): **kwargs):
......
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