Commit bb695789 by Őry Máté

Merge branch 'feature-renew-conditionally' into 'master'

Feature Renew Conditionally
parents 9ea843e9 0ca705cf
...@@ -697,16 +697,18 @@ class LeaseForm(forms.ModelForm): ...@@ -697,16 +697,18 @@ class LeaseForm(forms.ModelForm):
class VmRenewForm(forms.Form): class VmRenewForm(forms.Form):
force = forms.BooleanField(required=False, label=_(
"Set expiration times even if they are shorter than "
"the current value."))
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
choices = kwargs.pop('choices') choices = kwargs.pop('choices')
default = kwargs.pop('default') default = kwargs.pop('default')
super(VmRenewForm, self).__init__(*args, **kwargs) super(VmRenewForm, self).__init__(*args, **kwargs)
self.fields['lease'] = forms.ModelChoiceField(queryset=choices, self.fields.insert(0, 'lease', forms.ModelChoiceField(
initial=default, queryset=choices, initial=default, required=False,
required=False, 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()
......
...@@ -28,7 +28,9 @@ from sizefield.utils import filesizeformat ...@@ -28,7 +28,9 @@ from sizefield.utils import filesizeformat
from celery.exceptions import TimeLimitExceeded from celery.exceptions import TimeLimitExceeded
from common.models import create_readable, humanize_exception from common.models import (
create_readable, humanize_exception, HumanReadableException
)
from common.operations import Operation, register_operation from common.operations import Operation, register_operation
from .tasks.local_tasks import ( from .tasks.local_tasks import (
abortable_async_instance_operation, abortable_async_node_operation, abortable_async_instance_operation, abortable_async_node_operation,
...@@ -279,7 +281,10 @@ class DeployOperation(InstanceOperation): ...@@ -279,7 +281,10 @@ class DeployOperation(InstanceOperation):
"boot virtual machine")): "boot virtual machine")):
self.instance.resume_vm(timeout=timeout) self.instance.resume_vm(timeout=timeout)
try:
self.instance.renew(parent_activity=activity) self.instance.renew(parent_activity=activity)
except:
pass
register_operation(DeployOperation) register_operation(DeployOperation)
...@@ -700,8 +705,10 @@ class WakeUpOperation(InstanceOperation): ...@@ -700,8 +705,10 @@ class WakeUpOperation(InstanceOperation):
"deploy network")): "deploy network")):
self.instance.deploy_net() self.instance.deploy_net()
# Renew vm try:
self.instance.renew(parent_activity=activity) self.instance.renew(parent_activity=activity)
except:
pass
register_operation(WakeUpOperation) register_operation(WakeUpOperation)
...@@ -716,10 +723,24 @@ class RenewOperation(InstanceOperation): ...@@ -716,10 +723,24 @@ class RenewOperation(InstanceOperation):
required_perms = () required_perms = ()
concurrency_check = False concurrency_check = False
def _operation(self, lease=None): def _operation(self, activity, lease=None, force=False):
(self.instance.time_of_suspend, suspend, delete = self.instance.get_renew_times(lease)
self.instance.time_of_delete) = self.instance.get_renew_times(lease) 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."))
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_suspend = suspend
self.instance.time_of_delete = delete
self.instance.save() self.instance.save()
activity.result = create_readable(ugettext_noop(
"Renewed to suspend at %(suspend)s and destroy at %(delete)s."),
suspend=suspend, delete=delete)
register_operation(RenewOperation) register_operation(RenewOperation)
......
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