From 0cf2b4c6d7759fbe193cfe1091e8fa94f990eb32 Mon Sep 17 00:00:00 2001 From: Őry Máté Date: Thu, 6 Mar 2014 18:58:03 +0100 Subject: [PATCH] vm: add activity to Instance.renew --- circle/vm/models/instance.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/circle/vm/models/instance.py b/circle/vm/models/instance.py index e5fdfc9..8494b08 100644 --- a/circle/vm/models/instance.py +++ b/circle/vm/models/instance.py @@ -632,17 +632,23 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel): timezone.now() + self.lease.suspend_interval, timezone.now() + self.lease.delete_interval) - def renew(self, which='both'): + def renew(self, which='both', base_activity=None, user=None): """Renew virtual machine instance leases. """ - if which not in ('suspend', 'delete', 'both'): - raise ValueError('No such expiration type.') - 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 - self.save() + if base_activity is None: + act = instance_activity(code_suffix='renew', instance=self, + user=user) + else: + act = base_activity.sub_activity('renew') + with act: + if which not in ('suspend', 'delete', 'both'): + raise ValueError('No such expiration type.') + 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 + self.save() def change_password(self, user=None): """Generate new password for the vm -- libgit2 0.26.0