Commit 3ab3e26a by Őry Máté

vm: allow forcibly interrupting activities

fixes #256
parent 1e2a59ed
...@@ -714,6 +714,27 @@ class VmRenewForm(forms.Form): ...@@ -714,6 +714,27 @@ class VmRenewForm(forms.Form):
return helper return helper
class VmStateChangeForm(forms.Form):
interrupt = forms.BooleanField(required=False, label=_(
"Forcibly interrupt all running activities."),
help_text=_("Set all activities to finished state, "
"but don't interrupt any tasks."))
def __init__(self, *args, **kwargs):
show_interrupt = kwargs.pop('show_interrupt')
super(VmStateChangeForm, self).__init__(*args, **kwargs)
if not show_interrupt:
self.fields['interrupt'].widget = HiddenInput()
@property
def helper(self):
helper = FormHelper(self)
helper.form_tag = False
return helper
class VmCreateDiskForm(forms.Form): class VmCreateDiskForm(forms.Form):
name = forms.CharField(max_length=100, label=_("Name")) name = forms.CharField(max_length=100, label=_("Name"))
size = forms.CharField( size = forms.CharField(
......
...@@ -67,7 +67,7 @@ from .forms import ( ...@@ -67,7 +67,7 @@ from .forms import (
CircleAuthenticationForm, HostForm, LeaseForm, MyProfileForm, CircleAuthenticationForm, HostForm, LeaseForm, MyProfileForm,
NodeForm, TemplateForm, TraitForm, VmCustomizeForm, GroupCreateForm, NodeForm, TemplateForm, TraitForm, VmCustomizeForm, GroupCreateForm,
UserCreationForm, GroupProfileUpdateForm, UnsubscribeForm, UserCreationForm, GroupProfileUpdateForm, UnsubscribeForm,
VmSaveForm, UserKeyForm, VmRenewForm, VmSaveForm, UserKeyForm, VmRenewForm, VmStateChangeForm,
CirclePasswordChangeForm, VmCreateDiskForm, VmDownloadDiskForm, CirclePasswordChangeForm, VmCreateDiskForm, VmDownloadDiskForm,
TraitsForm, RawDataForm, GroupPermissionForm, AclUserAddForm, TraitsForm, RawDataForm, GroupPermissionForm, AclUserAddForm,
VmResourcesForm, VmAddInterfaceForm, VmListSearchForm VmResourcesForm, VmAddInterfaceForm, VmListSearchForm
...@@ -936,6 +936,22 @@ class VmRenewView(FormOperationMixin, TokenOperationView, VmOperationView): ...@@ -936,6 +936,22 @@ class VmRenewView(FormOperationMixin, TokenOperationView, VmOperationView):
return extra return extra
class VmStateChangeView(FormOperationMixin, VmOperationView):
op = 'emergency_change_state'
icon = 'legal'
effect = 'danger'
show_in_toolbar = True
form_class = VmStateChangeForm
wait_for_result = 0.5
def get_form_kwargs(self):
inst = self.get_op().instance
show_interrupt = active_activities.exists()
val = super(VmStateChangeView, self).get_form_kwargs()
val.update({'show_interrupt': show_interrupt})
return val
vm_ops = OrderedDict([ vm_ops = OrderedDict([
('deploy', VmOperationView.factory( ('deploy', VmOperationView.factory(
op='deploy', icon='play', effect='success')), op='deploy', icon='play', effect='success')),
...@@ -956,8 +972,7 @@ vm_ops = OrderedDict([ ...@@ -956,8 +972,7 @@ vm_ops = OrderedDict([
op='shut_off', icon='ban', effect='warning')), op='shut_off', icon='ban', effect='warning')),
('recover', VmOperationView.factory( ('recover', VmOperationView.factory(
op='recover', icon='medkit', effect='warning')), op='recover', icon='medkit', effect='warning')),
('nostate', VmOperationView.factory( ('nostate', VmStateChangeView),
op='emergency_change_state', icon='legal', effect='danger')),
('destroy', VmOperationView.factory( ('destroy', VmOperationView.factory(
extra_bases=[TokenOperationView], extra_bases=[TokenOperationView],
op='destroy', icon='times', effect='danger')), op='destroy', icon='times', effect='danger')),
......
...@@ -788,9 +788,17 @@ class ChangeStateOperation(InstanceOperation): ...@@ -788,9 +788,17 @@ class ChangeStateOperation(InstanceOperation):
"resources.") "resources.")
acl_level = "owner" acl_level = "owner"
required_perms = ('vm.emergency_change_state', ) required_perms = ('vm.emergency_change_state', )
concurrency_check = False
def _operation(self, user, activity, new_state="NOSTATE"): def _operation(self, user, activity, new_state="NOSTATE", interrupt=False):
activity.resultant_state = new_state activity.resultant_state = new_state
if interrupt:
msg_txt = ugettext_noop("Activity is forcibly interrupted.")
message = create_readable(msg_txt, msg_txt)
for i in InstanceActivity.objects.filter(
finished__isnull=True, instance=self.instance):
i.finish(False, result=message)
logger.error('Forced finishing activity %s', i)
register_operation(ChangeStateOperation) register_operation(ChangeStateOperation)
......
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