Commit 9b04178a by Czémán Arnold

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

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