When trying to start a running vm, shutoff or poweroff a shutdown vm,
the retrieved error was 500 (Internal Server Error). A better error
would be 400 (Invalid Request).
Signed-off-by: Ramon Medeiros <ramonn(a)linux.vnet.ibm.com>
---
src/kimchi/model/vms.py | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py
index 106e9bc..d3020b6 100644
--- a/src/kimchi/model/vms.py
+++ b/src/kimchi/model/vms.py
@@ -1105,7 +1105,12 @@ class VMModel(object):
try:
dom.create()
except libvirt.libvirtError as e:
- raise OperationFailed("KCHVM0019E",
+ # vm already running: return error 403
+ if DOM_STATE_MAP[dom.info()[0]] == "running":
+ raise InvalidOperation("KCHVM0019E",
+ {'name': name, 'err':
e.get_error_message()})
+ else:
+ raise OperationFailed("KCHVM0019E",
{'name': name, 'err':
e.get_error_message()})
def poweroff(self, name):
@@ -1113,7 +1118,12 @@ class VMModel(object):
try:
dom.destroy()
except libvirt.libvirtError as e:
- raise OperationFailed("KCHVM0020E",
+ # vm already powered off: return error 403
+ if DOM_STATE_MAP[dom.info()[0]] == "shutoff":
+ raise InvalidOperation("KCHVM0020E",
+ {'name': name, 'err':
e.get_error_message()})
+ else:
+ raise OperationFailed("KCHVM0020E",
{'name': name, 'err':
e.get_error_message()})
def shutdown(self, name):
@@ -1121,7 +1131,12 @@ class VMModel(object):
try:
dom.shutdown()
except libvirt.libvirtError as e:
- raise OperationFailed("KCHVM0029E",
+ # vm already powered off: return error 403
+ if DOM_STATE_MAP[dom.info()[0]] == "shutoff":
+ raise InvalidOperation("KCHVM0029E",
+ {'name': name, 'err':
e.get_error_message()})
+ else:
+ raise OperationFailed("KCHVM0029E",
{'name': name, 'err':
e.get_error_message()})
def reset(self, name):
--
2.1.0