Commit 7e755c8f by Bach Dániel

vm: add RecoverOperation

parent 553a35a4
......@@ -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):
register_operation(ScreenshotOperation)
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
disk.restore()
disk.save()
self.instance.destroyed_at = None
self.instance.save()
register_operation(RecoverOperation)
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