[Kimchi-devel] [PATCH] Issue #100: do not delete the VM when storage volume not found

shaohef at linux.vnet.ibm.com shaohef at linux.vnet.ibm.com
Fri May 9 10:33:42 UTC 2014


From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>

The VM may not be in a certain pool for some reasons.
Or the pool may not be active for some reasons.

We do not allow to delete this VM in this case.
And report the detail message to user.

Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
---
 src/kimchi/model/vms.py | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py
index 17bda04..3201fdd 100644
--- a/src/kimchi/model/vms.py
+++ b/src/kimchi/model/vms.py
@@ -426,14 +426,25 @@ class VMModel(object):
         if info['state'] == 'running':
             self.poweroff(name)
 
+        vols = []
+        for path in paths:
+            try:
+                vols.append(conn.storageVolLookupByPath(path))
+            except libvirt.libvirtError as e:
+                if e.get_error_code() == libvirt.VIR_ERR_NO_STORAGE_VOL:
+                    raise OperationFailed(
+                        "KCHVM0021E",
+                        {'name': name, 'err': e.get_error_message()})
+                else:
+                    raise
+
         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)
+        for vol in vols:
             pool = vol.storagePoolLookupByVolume()
             xml = pool.XMLDesc(0)
             pool_type = xmlutils.xpath_get_text(xml, "/pool/@type")[0]
-- 
1.9.0




More information about the Kimchi-devel mailing list