Commit 5bf0da3b by Czémán Arnold

vm: add ToggleBootMenuOperation and VmToggleBootMenuUpdate morph to VmOperationView

parent 01f0294e
Pipeline #137 passed with stage
in 0 seconds
...@@ -328,26 +328,6 @@ class VmRawDataUpdate(SuperuserRequiredMixin, UpdateView): ...@@ -328,26 +328,6 @@ class VmRawDataUpdate(SuperuserRequiredMixin, UpdateView):
return self.get_object().get_absolute_url() + "#resources" return self.get_object().get_absolute_url() + "#resources"
class VmToggleBootMenuUpdate(LoginRequiredMixin, UpdateView):
form_class = ToggleBootMenuForm
model = Instance
def get(self, *args, **kwargs):
raise Http404()
def form_valid(self, form):
user = self.request.user
is_owner = form.instance.has_level(user, "owner")
if not (is_owner and user.has_perm("vm.toggle_boot_menu")):
raise PermissionDenied()
return super(VmToggleBootMenuUpdate, self).form_valid(form)
def get_success_url(self):
return self.get_object().get_absolute_url() + "#resources"
class VmOperationView(AjaxOperationMixin, OperationView): class VmOperationView(AjaxOperationMixin, OperationView):
model = Instance model = Instance
...@@ -612,6 +592,38 @@ class VmResourcesChangeView(VmOperationView): ...@@ -612,6 +592,38 @@ class VmResourcesChangeView(VmOperationView):
*args, **kwargs) *args, **kwargs)
class VmToggleBootMenuUpdate(VmOperationView):
op = 'toggle_bootmenu'
icon = "save"
Please register or sign in to reply
show_in_toolbar = False
wait_for_result = 0.5
def post(self, request, extra=None, *args, **kwargs):
if extra is None:
Please register or sign in to reply
extra = {}
instance = get_object_or_404(Instance, pk=kwargs['pk'])
form = ToggleBootMenuForm(request.POST, instance=instance)
if not form.is_valid():
for f in form.errors:
messages.error(request, "<strong>%s</strong>: %s" % (
f, form.errors[f].as_text()
))
if request.is_ajax(): # this is not too nice
store = messages.get_messages(request)
store.used = True
return JsonResponse({'success': False,
'messages': [unicode(m) for m in store]})
else:
return HttpResponseRedirect(instance.get_absolute_url() +
"#resources")
else:
extra = form.cleaned_data
return super(VmToggleBootMenuUpdate, self).post(request, extra,
*args, **kwargs)
class TokenOperationView(OperationView): class TokenOperationView(OperationView):
"""Abstract operation view with token support. """Abstract operation view with token support.
......
...@@ -1403,6 +1403,27 @@ class ResourcesOperation(InstanceOperation): ...@@ -1403,6 +1403,27 @@ class ResourcesOperation(InstanceOperation):
@register_operation @register_operation
class ToggleBootMenuOperation(InstanceOperation):
id = 'toggle_bootmenu'
name = _("toggle boot menu")
description = _("Turn on/off boot menu.")
acl_level = "owner"
required_perms = ('vm.change_resources', )
accept_states = ('STOPPED', 'PENDING', 'RUNNING')
def _operation(self, user, activity, boot_menu):
self.instance.boot_menu = boot_menu
self.instance.full_clean()
self.instance.save()
return create_readable(ugettext_noop(
"Boot menu toggled: %(boot_menu)s"),
boot_menu="ON" if boot_menu else "OFF"
)
@register_operation
class PasswordResetOperation(RemoteAgentOperation): class PasswordResetOperation(RemoteAgentOperation):
id = 'password_reset' id = 'password_reset'
name = _("password reset") name = _("password reset")
......
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