Commit f7488817 by Bach Dániel

Merge branch 'feature-recover' into 'master'

Feature: Recover destroyed vm
parents e0fb01fd cab4ad49
......@@ -716,6 +716,8 @@ vm_ops = OrderedDict([
op='shutdown', icon='off', effect='warning')),
('shut_off', VmOperationView.factory(
op='shut_off', icon='ban-circle', effect='warning')),
('recover', VmOperationView.factory(
op='recover', icon='medkit', effect='warning')),
('destroy', VmOperationView.factory(
op='destroy', icon='remove', effect='danger')),
('create_disk', VmCreateDiskView),
......@@ -380,11 +380,16 @@ class Disk(AclBase, TimeStampedModel):
return True
def restore(self, user=None, task_uuid=None):
def restore(self, user=None, task_uuid=None, timeout=15):
"""Recover destroyed disk from trash if possible.
queue_name = self.datastore.get_remote_queue_name(
'storage', priority='slow')"Image: %s at Datastore: %s recovered from trash." %
(self.filename, self.datastore.path))
args=[self.datastore.path, self.filename],
def save_as(self, user=None, task_uuid=None, timeout=300):
"""Save VM as template.
......@@ -72,6 +72,9 @@ def make_free_space(datastore, percent):
def move_to_trash(datastore, disk_path):
def recover_from_trash(datastore, disk_path):
def get_storage_stat(path):
......@@ -264,6 +264,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
('change_resources', _('Can change resources of a running VM.')),
('set_resources', _('Can change resources of a new VM.')),
('config_ports', _('Can configure port forwards.')),
('recover', _('Can recover a destroyed VM.')),
verbose_name = _('instance')
verbose_name_plural = _('instances')
......@@ -628,3 +628,30 @@ class ScreenshotOperation(InstanceOperation):
class RecoverOperation(InstanceOperation):
activity_code_suffix = 'recover'
id = 'recover'
name = _("recover")
description = _("Recover virtual machine from destroyed state.")
acl_level = "owner"
required_perms = ('vm.recover', )
def check_precond(self):
if not self.instance.destroyed_at:
raise self.instance.WrongStateError(self.instance)
def on_commit(self, activity):
activity.resultant_state = 'PENDING'
def _operation(self):
for disk in self.instance.disks.all():
disk.destroyed = None
self.instance.destroyed_at = None
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