[Kimchi-devel] [PATCH V2 4/6] Fix VM delete error message handling (UI/Backend)

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


This patch fixes delete confirmation window, changes backend in order to
raise proper exception and fixes the ui to catch the right message from
backend.

Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
---
 src/kimchi/i18n.py             |  1 +
 src/kimchi/model/vms.py        | 31 +++++++++++++++++--------------
 ui/js/src/kimchi.guest_main.js | 12 ++++++------
 ui/pages/i18n.html.tmpl        |  1 +
 4 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index f262c06..e955d3b 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -78,6 +78,7 @@ messages = {
     "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"),
+    "KCHVM0021E": _("Unable to delete 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 7f29f1a..f999ed0 100644
--- a/src/kimchi/model/vms.py
+++ b/src/kimchi/model/vms.py
@@ -345,26 +345,29 @@ class VMModel(object):
                 raise
 
     def delete(self, name):
-        if self._vm_exists(name):
-            conn = self.conn.get()
-            dom = self.get_vm(name, self.conn)
-            self._vmscreenshot_delete(dom.UUIDString())
-            paths = self._vm_get_disk_paths(dom)
-            info = self.lookup(name)
+        conn = self.conn.get()
+        dom = self.get_vm(name, self.conn)
+        self._vmscreenshot_delete(dom.UUIDString())
+        paths = self._vm_get_disk_paths(dom)
+        info = self.lookup(name)
 
-            if info['state'] == 'running':
-                self.stop(name)
+        if info['state'] == 'running':
+            self.stop(name)
 
+        try:
             dom.undefine()
+        except libvirt.libvirtError as e:
+            raise OperationFailed("KCHVM0021E",
+                                  {'name': name, 'err': e.get_error_message()})
 
-            for path in paths:
-                vol = conn.storageVolLookupByPath(path)
-                vol.delete(0)
+        for path in paths:
+            vol = conn.storageVolLookupByPath(path)
+            vol.delete(0)
 
-            with self.objstore as session:
-                session.delete('vm', dom.UUIDString(), ignore_missing=True)
+        with self.objstore as session:
+            session.delete('vm', dom.UUIDString(), ignore_missing=True)
 
-            vnc.remove_proxy_token(name)
+        vnc.remove_proxy_token(name)
 
     def start(self, name):
         # make sure the ISO file has read permission
diff --git a/ui/js/src/kimchi.guest_main.js b/ui/js/src/kimchi.guest_main.js
index 41bf18d..ead5f3b 100644
--- a/ui/js/src/kimchi.guest_main.js
+++ b/ui/js/src/kimchi.guest_main.js
@@ -74,16 +74,16 @@ kimchi.vmdelete = function(event) {
     var vm = $(this).closest('li[name=guest]');
     var vm_id=vm.attr("id");
     var settings = {
-        title : i18n['msg.confirm.delete.title'],
-        content : i18n['msg.vm.confirm.delete'],
-        confirm : i18n['msg.confirm.delete.confirm'],
-        cancel : i18n['msg.confirm.delete.cancel']
+        title : i18n['KCHVM6002M'],
+        content : i18n['KCHVM6001M'],
+        confirm : i18n['KCHAPI6002M'],
+        cancel : i18n['KCHAPI6003M']
     };
     kimchi.confirm(settings, function() {
         kimchi.deleteVM(vm_id, function(result) {
             kimchi.listVmsAuto();
-        }, function() {
-            kimchi.message.error(i18n['msg.fail.delete']);
+        }, function(err) {
+            kimchi.message.error(err.responseJSON.reason);
         });
     }, function() {
     });
diff --git a/ui/pages/i18n.html.tmpl b/ui/pages/i18n.html.tmpl
index f8af68e..b3eeab8 100644
--- a/ui/pages/i18n.html.tmpl
+++ b/ui/pages/i18n.html.tmpl
@@ -95,6 +95,7 @@ var i18n = {
     'KCHDR6011M': "$_("Report name should contain only letters, digits and/or hyphen ('-').")",
 
     'KCHVM6001M': "$_("This will delete the virtual machine and its virtual disks. This operation cannot be undone. Would you like to continue?")",
+    'KCHVM6002M': "$_("Delete Confirmation")",
 
     'KCHNET6001E': "$_("The VLAN id must be between 1 and 4094.")",
 
-- 
1.8.5.3




More information about the Kimchi-devel mailing list