Commit 66b0952f by Guba Sándor Committed by Bach Dániel

storage: make save_as abortable task

parent 0bb9d185
...@@ -134,6 +134,7 @@ class Disk(AclBase, TimeStampedModel): ...@@ -134,6 +134,7 @@ class Disk(AclBase, TimeStampedModel):
self.disk = disk self.disk = disk
class DiskIsNotReady(Exception): class DiskIsNotReady(Exception):
""" Exception for operations that need a deployed disk. """ Exception for operations that need a deployed disk.
""" """
...@@ -394,7 +395,7 @@ class Disk(AclBase, TimeStampedModel): ...@@ -394,7 +395,7 @@ class Disk(AclBase, TimeStampedModel):
args=[self.datastore.path, self.filename], args=[self.datastore.path, self.filename],
queue=queue_name).get(timeout=timeout) queue=queue_name).get(timeout=timeout)
def save_as(self, user=None, task_uuid=None, timeout=300): def save_as(self, task, user=None, task_uuid=None, timeout=300):
"""Save VM as template. """Save VM as template.
Based on disk type: Based on disk type:
...@@ -429,10 +430,18 @@ class Disk(AclBase, TimeStampedModel): ...@@ -429,10 +430,18 @@ class Disk(AclBase, TimeStampedModel):
type=new_type) type=new_type)
queue_name = self.get_remote_queue_name("storage", priority="slow") queue_name = self.get_remote_queue_name("storage", priority="slow")
storage_tasks.merge.apply_async(args=[self.get_disk_desc(), remote = storage_tasks.merge.apply_async(kwargs={
disk.get_disk_desc()], "old_json": self.get_disk_desc(),
"new_json": disk.get_disk_desc()},
queue=queue_name queue=queue_name
).get() # Timeout ) # Timeout
disk.is_ready = True while True:
disk.save() 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 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