Commit 1311ddb3 by Bach Dániel

Merge branch 'feature-abort-save_as-rebased' into 'master'

Feature: abort save as
parents 00227f21 4cb0af54
......@@ -134,6 +134,7 @@ class Disk(AclBase, TimeStampedModel):
self.disk = disk
class DiskIsNotReady(Exception):
""" Exception for operations that need a deployed disk.
"""
......@@ -394,7 +395,7 @@ class Disk(AclBase, TimeStampedModel):
args=[self.datastore.path, self.filename],
queue=queue_name).get(timeout=timeout)
def save_as(self, user=None, task_uuid=None, timeout=300):
def save_as(self, task=None, user=None, task_uuid=None, timeout=300):
"""Save VM as template.
Based on disk type:
......@@ -429,10 +430,18 @@ class Disk(AclBase, TimeStampedModel):
type=new_type)
queue_name = self.get_remote_queue_name("storage", priority="slow")
storage_tasks.merge.apply_async(args=[self.get_disk_desc(),
disk.get_disk_desc()],
queue=queue_name
).get() # Timeout
disk.is_ready = True
disk.save()
remote = storage_tasks.merge.apply_async(kwargs={
"old_json": self.get_disk_desc(),
"new_json": disk.get_disk_desc()},
queue=queue_name
) # Timeout
while True:
try:
remote.get(timeout=5)
break
except TimeoutError:
if task is not None and task.is_aborted():
AbortableAsyncResult(remote.id).abort()
disk.destroy()
raise Exception("Save as aborted by use.")
return disk
......@@ -403,7 +403,7 @@ class SaveAsTemplateOperation(InstanceOperation):
return "%s v%d" % (name, v)
def on_abort(self, activity, error):
if getattr(self, 'disks'):
if hasattr(self, 'disks'):
for disk in self.disks:
disk.destroy()
......@@ -445,7 +445,7 @@ class SaveAsTemplateOperation(InstanceOperation):
def __try_save_disk(disk):
try:
return disk.save_as()
return disk.save_as(task)
except Disk.WrongDiskTypeError:
return disk
......
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