Commit 2ff6b951 by Őry Máté

vm: move renew to a new operation

fixes #184
parent 44430db0
......@@ -439,10 +439,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
for cps in customized_params]
def clean(self, *args, **kwargs):
if self.time_of_suspend is None:
if self.time_of_delete is None:
self.time_of_suspend, self.time_of_delete = self.get_renew_times()
super(Instance, self).clean(*args, **kwargs)
def manual_state_change(self, new_state="NOSTATE", reason=None, user=None):
......@@ -715,36 +712,14 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
return False
def get_renew_times(self):
def get_renew_times(self, lease=None):
"""Returns new suspend and delete times if renew would be called.
if lease is None:
lease =
return ( +, +
def _do_renew(self, which='both'):
"""Set expiration times to renewed values.
time_of_suspend, time_of_delete = self.get_renew_times()
if which in ('suspend', 'both'):
self.time_of_suspend = time_of_suspend
if which in ('delete', 'both'):
self.time_of_delete = time_of_delete
def renew(self, which='both', base_activity=None, user=None):
"""Renew virtual machine instance leases.
if base_activity is None:
act_ctx = instance_activity(code_suffix='renew', instance=self,
act_ctx = base_activity.sub_activity('renew')
with act_ctx:
if which not in ('suspend', 'delete', 'both'):
raise ValueError('No such expiration type.')
self._do_renew(which) + lease.suspend_interval, + lease.delete_interval)
def change_password(self, user=None):
"""Generate new password for the vm
......@@ -619,6 +619,22 @@ class WakeUpOperation(InstanceOperation):
class RenewOperation(InstanceOperation):
activity_code_suffix = 'renew'
id = 'renew'
name = _("renew")
description = _("Renew expiration times")
acl_level = "operator"
def _operation(self, lease=None):
self.instance.time_of_delete) = self.instance.get_renew_times(lease)
class NodeOperation(Operation):
async_operation = abortable_async_node_operation
host_cls = Node
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