Commit 9b04178a by Czémán Arnold

vm, storage, dashboard: rework vm recover and disk restoration

parent 17a4af7f
Pipeline #146 passed with stage
in 0 seconds
......@@ -3,7 +3,9 @@
<i class="fa fa-file"></i>
{{ d.name }} (#{{ d.id }}) - {{ d.size|filesize }}
{% if d.destroyed %}
<i class="fa fa-exclamation-triangle text-danger" alt="missing" title="missing"></i>
{% endif %}
<span class="operation-wrapper pull-right">
{% if d.is_resizable %}
......
......@@ -76,9 +76,8 @@ class DataStore(Model):
def get_deletable_disks(self):
deletables = [disk for disk in self.disk_set.filter(
destroyed__isnull=False) if disk.is_deletable]
deletables = sorted(deletables, key=lambda disk: disk.destroyed)
destroyed__isnull=False).order_by(
"destroyed") if disk.is_deletable]
return [disk.filename for disk in deletables]
@method_cache(30)
......@@ -475,8 +474,6 @@ class Disk(TimeStampedModel):
"""
queue_name = self.datastore.get_remote_queue_name(
'storage', priority='slow')
logger.info("Image: %s at Datastore: %s recovered from trash." %
(self.filename, self.datastore.path))
res = storage_tasks.exists.apply_async(
args=[self.datastore.path,
self.filename],
......@@ -487,6 +484,7 @@ class Disk(TimeStampedModel):
else:
logger.info("Image: %s at Datastore: %s not recovered." %
(self.filename, self.datastore.path))
return res
def save_as(self, task=None, user=None, task_uuid=None, timeout=300):
"""Save VM as template.
......
......@@ -62,7 +62,7 @@ def destroy(disk, user):
@celery.task
def restore(disk, user):
disk.restore(task_uuid=restore.request.id, user=user)
return disk.restore(task_uuid=restore.request.id, user=user)
@celery.task(base=AbortableTask, bind=True)
......
......@@ -1347,10 +1347,13 @@ class RecoverOperation(InstanceOperation):
'recover_instance',
readable_name=ugettext_noop("recover instance")):
self.instance.destroyed_at = None
not_restored = []
for disk in self.instance.disks.all():
if disk.restore():
disk.destroyed = None
disk.restore()
disk.save()
else:
not_restored.append(unicode(disk))
self.instance.status = 'PENDING'
self.instance.save()
......@@ -1359,6 +1362,12 @@ class RecoverOperation(InstanceOperation):
except:
pass
if not_restored:
raise HumanReadableException.create(ugettext_noop(
"The following disk(s) couldn't be recovered: %(disks)s"),
disks=", ".join(not_restored)
)
if self.instance.template:
for net in self.instance.template.interface_set.all():
self.instance.add_interface(
......
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