Commit e5b9cb0f by Bach Dániel

Merge branch 'fix-renew' into 'master'

Fix renew 

closes #375

See merge request !334
parents 3122ce02 707287be
...@@ -973,26 +973,48 @@ class RenewOperation(InstanceOperation): ...@@ -973,26 +973,48 @@ class RenewOperation(InstanceOperation):
required_perms = () required_perms = ()
concurrency_check = False concurrency_check = False
def set_time_of_suspend(self, activity, suspend, force):
with activity.sub_activity(
'renew_suspend', concurrency_check=False,
readable_name=ugettext_noop('set time of suspend')):
if (not force and suspend and self.instance.time_of_suspend and
suspend < self.instance.time_of_suspend):
raise HumanReadableException.create(ugettext_noop(
"Renewing the machine with the selected lease would "
"result in its suspension time get earlier than before."))
self.instance.time_of_suspend = suspend
def set_time_of_delete(self, activity, delete, force):
with activity.sub_activity(
'renew_delete', concurrency_check=False,
readable_name=ugettext_noop('set time of delete')):
if (not force and delete and self.instance.time_of_delete and
delete < self.instance.time_of_delete):
raise HumanReadableException.create(ugettext_noop(
"Renewing the machine with the selected lease would "
"result in its delete time get earlier than before."))
self.instance.time_of_delete = delete
def _operation(self, activity, lease=None, force=False, save=False): def _operation(self, activity, lease=None, force=False, save=False):
suspend, delete = self.instance.get_renew_times(lease) suspend, delete = self.instance.get_renew_times(lease)
if (not force and suspend and self.instance.time_of_suspend and try:
suspend < self.instance.time_of_suspend): self.set_time_of_suspend(activity, suspend, force)
raise HumanReadableException.create(ugettext_noop( except HumanReadableException:
"Renewing the machine with the selected lease would result " pass
"in its suspension time get earlier than before.")) try:
if (not force and delete and self.instance.time_of_delete and self.set_time_of_delete(activity, delete, force)
delete < self.instance.time_of_delete): except HumanReadableException:
raise HumanReadableException.create(ugettext_noop( pass
"Renewing the machine with the selected lease would result "
"in its delete time get earlier than before."))
self.instance.time_of_suspend = suspend
self.instance.time_of_delete = delete
if save: if save:
self.instance.lease = lease self.instance.lease = lease
self.instance.save() self.instance.save()
return create_readable(ugettext_noop( return create_readable(ugettext_noop(
"Renewed to suspend at %(suspend)s and destroy at %(delete)s."), "Renewed to suspend at %(suspend)s and destroy at %(delete)s."),
suspend=suspend, delete=delete) suspend=self.instance.time_of_suspend,
delete=self.instance.time_of_suspend)
@register_operation @register_operation
......
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