Commit aea984d1 by Guba Sándor

operations: SaveAsTemplateOperation refactor

Saving disks synchronously.
parent 956c4a08
......@@ -8,7 +8,6 @@ from django.utils.translation import ugettext_lazy as _
from celery.exceptions import TimeLimitExceeded
from common.operations import Operation, register_operation
from storage.models import Disk
from .tasks.local_tasks import async_instance_operation, async_node_operation
from .models import (
Instance, InstanceActivity, InstanceTemplate, Node, NodeActivity,
......@@ -224,20 +223,24 @@ class SaveAsTemplateOperation(InstanceOperation):
}
params.update(kwargs)
from storage.models import Disk
def __try_save_disk(disk):
try:
return disk.save_as()
except Disk.WrongDiskTypeError:
return disk
with activity.sub_activity('saving_disks'):
disks = [__try_save_disk(disk)
for disk in self.instance.disks.all()]
# create template and do additional setup
tmpl = InstanceTemplate(**params)
tmpl.full_clean() # Avoiding database errors.
tmpl.save()
try:
with activity.sub_activity('saving_disks'):
tmpl.disks.add(*[__try_save_disk(disk)
for disk in self.instance.disks.all()])
tmpl.disks.add(*disks)
# create interface templates
for i in self.instance.interface_set.all():
i.save_as_template(tmpl)
......
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