Commit 8c20ce75 by Őry Máté

vm: allow saving lease

fixes #252
parent c06380e5
...@@ -703,6 +703,8 @@ class VmRenewForm(forms.Form): ...@@ -703,6 +703,8 @@ class VmRenewForm(forms.Form):
force = forms.BooleanField(required=False, label=_( force = forms.BooleanField(required=False, label=_(
"Set expiration times even if they are shorter than " "Set expiration times even if they are shorter than "
"the current value.")) "the current value."))
save = forms.BooleanField(required=False, label=_(
"Save selected lease."))
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
choices = kwargs.pop('choices') choices = kwargs.pop('choices')
...@@ -714,6 +716,7 @@ class VmRenewForm(forms.Form): ...@@ -714,6 +716,7 @@ class VmRenewForm(forms.Form):
empty_label=None, label=_('Length'))) empty_label=None, label=_('Length')))
if len(choices) < 2: if len(choices) < 2:
self.fields['lease'].widget = HiddenInput() self.fields['lease'].widget = HiddenInput()
self.fields['save'].widget = HiddenInput()
@property @property
def helper(self): def helper(self):
......
...@@ -754,7 +754,7 @@ class RenewOperation(InstanceOperation): ...@@ -754,7 +754,7 @@ class RenewOperation(InstanceOperation):
required_perms = () required_perms = ()
concurrency_check = False concurrency_check = False
def _operation(self, activity, lease=None, force=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 if (not force and suspend and self.instance.time_of_suspend and
suspend < self.instance.time_of_suspend): suspend < self.instance.time_of_suspend):
...@@ -768,6 +768,8 @@ class RenewOperation(InstanceOperation): ...@@ -768,6 +768,8 @@ class RenewOperation(InstanceOperation):
"in its delete time get earlier than before.")) "in its delete time get earlier than before."))
self.instance.time_of_suspend = suspend self.instance.time_of_suspend = suspend
self.instance.time_of_delete = delete self.instance.time_of_delete = delete
if save:
self.instance.lease = lease
self.instance.save() self.instance.save()
activity.result = create_readable(ugettext_noop( activity.result = 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."),
......
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