Commit 9e60b9b7 by Guba Sándor

operations: added missing preconditions

parent cbcf6f97
...@@ -90,6 +90,11 @@ class AddInterfaceOperation(InstanceOperation): ...@@ -90,6 +90,11 @@ class AddInterfaceOperation(InstanceOperation):
"the VM.") "the VM.")
required_perms = () required_perms = ()
def check_precond(self):
super(AddInterfaceOperation, self).check_precond()
if self.instance.status not in ['STOPPED', 'PENDING', 'RUNNING']:
raise self.instance.WrongStateError(self.instance)
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:
managed = vlan.managed managed = vlan.managed
...@@ -344,6 +349,11 @@ class RemoveInterfaceOperation(InstanceOperation): ...@@ -344,6 +349,11 @@ class RemoveInterfaceOperation(InstanceOperation):
description = _("Remove the specified network interface from the VM.") description = _("Remove the specified network interface from the VM.")
required_perms = () required_perms = ()
def check_precond(self):
super(RemoveInterfaceOperation, self).check_precond()
if self.instance.status not in ['STOPPED', 'PENDING', 'RUNNING']:
raise self.instance.WrongStateError(self.instance)
def _operation(self, activity, user, system, interface): def _operation(self, activity, user, system, interface):
if self.instance.is_running: if self.instance.is_running:
self.instance.detach_network(interface) self.instance.detach_network(interface)
...@@ -365,7 +375,7 @@ class RemoveDiskOperation(InstanceOperation): ...@@ -365,7 +375,7 @@ class RemoveDiskOperation(InstanceOperation):
def check_precond(self): def check_precond(self):
super(RemoveDiskOperation, self).check_precond() super(RemoveDiskOperation, self).check_precond()
if self.instance.status not in ['STOPPED', 'RUNNING']: if self.instance.status not in ['STOPPED', 'PENDING', 'RUNNING']:
raise self.instance.WrongStateError(self.instance) raise self.instance.WrongStateError(self.instance)
def _operation(self, activity, user, system, disk): def _operation(self, activity, user, system, disk):
......
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