Commit b86972f5 by Guba Sándor

instance: added save_as_async and refactored save_as

parent 0e472d2f
......@@ -968,7 +968,14 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
for net in self.interface_set.all():
net.deploy()
def save_as_template(self, name, **kwargs):
def save_as_template_async(self, name, user=None, **kwargs):
return local_tasks.save_as_template.apply_async(
args=[self, name, user, kwargs], queue="localhost.man")
def save_as_template(self, name, task_uuid=None, user=None,
timeout=300, **kwargs):
with instance_activity(code_suffix="save_as_template", instance=self,
task_uuid=task_uuid, user=user):
# prepare parameters
kwargs.setdefault('name', name)
kwargs.setdefault('description', self.description)
......@@ -991,13 +998,13 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
except Disk.WrongDiskTypeError:
return disk
# copy disks
disks = [__try_save_disk(disk) for disk in self.disks.all()]
kwargs.setdefault('disks', disks)
# create template and do additional setup
tmpl = InstanceTemplate(**kwargs)
tmpl.full_clean()
logger.info("Clean utani save")
tmpl.save()
tmpl.disks.add(*[__try_save_disk(disk)
for disk in self.disks.all()])
# save template
tmpl.save()
try:
......
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