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