[Kimchi-devel] [PATCH V2 2/6] Fix VM stop error messages handling (backend/UI)

Rodrigo Trujillo rodrigo.trujillo at linux.vnet.ibm.com
Wed Feb 26 19:05:14 UTC 2014


The UI was not able to catch the error messages sent from backend when a
user tried to stop a VM. This patch fixes the processes and also change
the 'stop' backend function, then exceptions from "get_vm" are send to
frontend.

Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
---
 src/kimchi/i18n.py             | 1 +
 src/kimchi/model/vms.py        | 7 +++++--
 ui/js/src/kimchi.guest_main.js | 4 ++--
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index ca72a80..f262c06 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -77,6 +77,7 @@ messages = {
     "KCHVM0017E": _("Volume list (LUNs names) not given."),
     "KCHVM0018E": _("Virtual machine volumes must be a list of strings with distinct LUNs names."),
     "KCHVM0019E": _("Unable to start virtual machine %(name)s. Details: %(err)s"),
+    "KCHVM0020E": _("Unable to stop virtual machine %(name)s. Details: %(err)s"),
 
     "KCHVMIF0001E": _("Interface %(iface)s does not exist in virtual machine %(name)s"),
     "KCHVMIF0002E": _("Network %(network)s specified for virtual machine %(name)s does not exist"),
diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py
index b6a42e6..7f29f1a 100644
--- a/src/kimchi/model/vms.py
+++ b/src/kimchi/model/vms.py
@@ -383,9 +383,12 @@ class VMModel(object):
                                   {'name': name, 'err': e.get_error_message()})
 
     def stop(self, name):
-        if self._vm_exists(name):
-            dom = self.get_vm(name, self.conn)
+        dom = self.get_vm(name, self.conn)
+        try:
             dom.destroy()
+        except libvirt.libvirtError as e:
+            raise OperationFailed("KCHVM0020E",
+                                  {'name': name, 'err': e.get_error_message()})
 
     def _vm_get_graphics(self, name):
         dom = self.get_vm(name, self.conn)
diff --git a/ui/js/src/kimchi.guest_main.js b/ui/js/src/kimchi.guest_main.js
index ab09976..0aadc9b 100644
--- a/ui/js/src/kimchi.guest_main.js
+++ b/ui/js/src/kimchi.guest_main.js
@@ -50,8 +50,8 @@ kimchi.vmstop = function(event) {
         kimchi.stopVM(vm_id, function(result) {
             button.removeClass('loading');
             kimchi.listVmsAuto();
-        }, function() {
-            kimchi.message.error(i18n['msg.fail.stop']);
+        }, function(err) {
+            kimchi.message.error(err.responseJSON.reason);
         });
     } else {
         event.preventDefault();
-- 
1.8.5.3




More information about the Kimchi-devel mailing list