Commit cf097f2f by Bach Dániel

vm: raise ImproperlyConfigured if required_perms is not set

parent 93ba646f
...@@ -20,7 +20,7 @@ from logging import getLogger ...@@ -20,7 +20,7 @@ from logging import getLogger
from .models import activity_context, has_suffix from .models import activity_context, has_suffix
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied, ImproperlyConfigured
logger = getLogger(__name__) logger = getLogger(__name__)
...@@ -30,7 +30,7 @@ class Operation(object): ...@@ -30,7 +30,7 @@ class Operation(object):
"""Base class for VM operations. """Base class for VM operations.
""" """
async_queue = 'localhost.man' async_queue = 'localhost.man'
required_perms = () required_perms = None
do_not_call_in_templates = True do_not_call_in_templates = True
abortable = False abortable = False
has_percentage = False has_percentage = False
...@@ -141,6 +141,9 @@ class Operation(object): ...@@ -141,6 +141,9 @@ class Operation(object):
pass pass
def check_auth(self, user): def check_auth(self, user):
if self.required_perms is None:
raise ImproperlyConfigured(
"Set required_perms to () if none needed.")
if not user.has_perms(self.required_perms): if not user.has_perms(self.required_perms):
raise PermissionDenied("%s doesn't have the required permissions." raise PermissionDenied("%s doesn't have the required permissions."
% user) % user)
......
...@@ -83,6 +83,7 @@ class AddInterfaceOperation(InstanceOperation): ...@@ -83,6 +83,7 @@ class AddInterfaceOperation(InstanceOperation):
name = _("add interface") name = _("add interface")
description = _("Add a new network interface for the specified VLAN to " description = _("Add a new network interface for the specified VLAN to "
"the VM.") "the VM.")
required_perms = ()
def _operation(self, activity, user, system, vlan, managed=None): def _operation(self, activity, user, system, vlan, managed=None):
if managed is None: if managed is None:
...@@ -158,6 +159,7 @@ class DeployOperation(InstanceOperation): ...@@ -158,6 +159,7 @@ class DeployOperation(InstanceOperation):
id = 'deploy' id = 'deploy'
name = _("deploy") name = _("deploy")
description = _("Deploy new virtual machine with network.") description = _("Deploy new virtual machine with network.")
required_perms = ()
def check_precond(self): def check_precond(self):
super(DeployOperation, self).check_precond() super(DeployOperation, self).check_precond()
...@@ -199,6 +201,7 @@ class DestroyOperation(InstanceOperation): ...@@ -199,6 +201,7 @@ class DestroyOperation(InstanceOperation):
id = 'destroy' id = 'destroy'
name = _("destroy") name = _("destroy")
description = _("Destroy virtual machine and its networks.") description = _("Destroy virtual machine and its networks.")
required_perms = ()
def on_commit(self, activity): def on_commit(self, activity):
activity.resultant_state = 'DESTROYED' activity.resultant_state = 'DESTROYED'
...@@ -240,6 +243,7 @@ class MigrateOperation(InstanceOperation): ...@@ -240,6 +243,7 @@ class MigrateOperation(InstanceOperation):
id = 'migrate' id = 'migrate'
name = _("migrate") name = _("migrate")
description = _("Live migrate running VM to another node.") description = _("Live migrate running VM to another node.")
required_perms = ()
def rollback(self, activity): def rollback(self, activity):
with activity.sub_activity('rollback_net'): with activity.sub_activity('rollback_net'):
...@@ -290,6 +294,7 @@ class RebootOperation(InstanceOperation): ...@@ -290,6 +294,7 @@ class RebootOperation(InstanceOperation):
id = 'reboot' id = 'reboot'
name = _("reboot") name = _("reboot")
description = _("Reboot virtual machine with Ctrl+Alt+Del signal.") description = _("Reboot virtual machine with Ctrl+Alt+Del signal.")
required_perms = ()
def check_precond(self): def check_precond(self):
super(RebootOperation, self).check_precond() super(RebootOperation, self).check_precond()
...@@ -308,6 +313,7 @@ class RemoveInterfaceOperation(InstanceOperation): ...@@ -308,6 +313,7 @@ class RemoveInterfaceOperation(InstanceOperation):
id = 'remove_interface' id = 'remove_interface'
name = _("remove interface") name = _("remove interface")
description = _("Remove the specified network interface from the VM.") description = _("Remove the specified network interface from the VM.")
required_perms = ()
def _operation(self, activity, user, system, interface): def _operation(self, activity, user, system, interface):
if self.instance.is_running: if self.instance.is_running:
...@@ -325,6 +331,7 @@ class RemoveDiskOperation(InstanceOperation): ...@@ -325,6 +331,7 @@ class RemoveDiskOperation(InstanceOperation):
id = 'remove_disk' id = 'remove_disk'
name = _("remove disk") name = _("remove disk")
description = _("Remove the specified disk from the VM.") description = _("Remove the specified disk from the VM.")
required_perms = ()
def check_precond(self): def check_precond(self):
super(RemoveDiskOperation, self).check_precond() super(RemoveDiskOperation, self).check_precond()
...@@ -345,6 +352,7 @@ class ResetOperation(InstanceOperation): ...@@ -345,6 +352,7 @@ class ResetOperation(InstanceOperation):
id = 'reset' id = 'reset'
name = _("reset") name = _("reset")
description = _("Reset virtual machine (reset button).") description = _("Reset virtual machine (reset button).")
required_perms = ()
def check_precond(self): def check_precond(self):
super(ResetOperation, self).check_precond() super(ResetOperation, self).check_precond()
...@@ -459,6 +467,7 @@ class ShutdownOperation(InstanceOperation): ...@@ -459,6 +467,7 @@ class ShutdownOperation(InstanceOperation):
name = _("shutdown") name = _("shutdown")
description = _("Shutdown virtual machine with ACPI signal.") description = _("Shutdown virtual machine with ACPI signal.")
abortable = True abortable = True
required_perms = ()
def check_precond(self): def check_precond(self):
super(ShutdownOperation, self).check_precond() super(ShutdownOperation, self).check_precond()
...@@ -482,6 +491,7 @@ class ShutOffOperation(InstanceOperation): ...@@ -482,6 +491,7 @@ class ShutOffOperation(InstanceOperation):
id = 'shut_off' id = 'shut_off'
name = _("shut off") name = _("shut off")
description = _("Shut off VM (plug-out).") description = _("Shut off VM (plug-out).")
required_perms = ()
def check_precond(self): def check_precond(self):
super(ShutOffOperation, self).check_precond() super(ShutOffOperation, self).check_precond()
...@@ -513,6 +523,7 @@ class SleepOperation(InstanceOperation): ...@@ -513,6 +523,7 @@ class SleepOperation(InstanceOperation):
id = 'sleep' id = 'sleep'
name = _("sleep") name = _("sleep")
description = _("Suspend virtual machine with memory dump.") description = _("Suspend virtual machine with memory dump.")
required_perms = ()
def check_precond(self): def check_precond(self):
super(SleepOperation, self).check_precond() super(SleepOperation, self).check_precond()
...@@ -552,6 +563,7 @@ class WakeUpOperation(InstanceOperation): ...@@ -552,6 +563,7 @@ class WakeUpOperation(InstanceOperation):
Power on Virtual Machine and load its memory from dump. Power on Virtual Machine and load its memory from dump.
""") """)
required_perms = ()
def check_precond(self): def check_precond(self):
super(WakeUpOperation, self).check_precond() super(WakeUpOperation, self).check_precond()
...@@ -614,6 +626,7 @@ class FlushOperation(NodeOperation): ...@@ -614,6 +626,7 @@ class FlushOperation(NodeOperation):
id = 'flush' id = 'flush'
name = _("flush") name = _("flush")
description = _("Disable node and move all instances to other ones.") description = _("Disable node and move all instances to other ones.")
required_perms = ()
def _operation(self, activity, user): def _operation(self, activity, user):
self.node.disable(user, activity) self.node.disable(user, activity)
...@@ -631,6 +644,7 @@ class ScreenshotOperation(InstanceOperation): ...@@ -631,6 +644,7 @@ class ScreenshotOperation(InstanceOperation):
name = _("screenshot") name = _("screenshot")
description = _("Get screenshot") description = _("Get screenshot")
acl_level = "owner" acl_level = "owner"
required_perms = ()
def check_precond(self): def check_precond(self):
super(ScreenshotOperation, self).check_precond() super(ScreenshotOperation, self).check_precond()
......
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