[Kimchi-devel] [PATCH][Kimchi 1/2] Do not remove storagepools linked to guests
Ramon Medeiros
ramonn at linux.vnet.ibm.com
Wed Aug 24 17:58:30 UTC 2016
The initial propose was to extend this task to network pools, but, they
already check if guests or templates are linked before deleting.
Signed-off-by: Ramon Medeiros <ramonn at linux.vnet.ibm.com>
---
i18n.py | 1 +
model/storagepools.py | 22 ++++++++++++++++++++++
2 files changed, 23 insertions(+)
diff --git a/i18n.py b/i18n.py
index e8d9c05..ea2c4ab 100644
--- a/i18n.py
+++ b/i18n.py
@@ -227,6 +227,7 @@ messages = {
"KCHPOOL0036E": _("A volume group named '%(name)s' already exists. Please, choose another name to create the logical pool."),
"KCHPOOL0037E": _("Unable to update database with deep scan information due error: %(err)s"),
"KCHPOOL0038E": _("No volume group '%(name)s' found. Please, specify an existing volume group to create the logical pool from."),
+ "KCHPOOL0039E": _("Unable to delete pool %(name)s as it is associated with guests: %(vms)s"),
"KCHVOL0001E": _("Storage volume %(name)s already exists"),
"KCHVOL0002E": _("Storage volume %(name)s does not exist in storage pool %(pool)s"),
diff --git a/model/storagepools.py b/model/storagepools.py
index a2dbaec..31c636c 100644
--- a/model/storagepools.py
+++ b/model/storagepools.py
@@ -474,12 +474,34 @@ class StoragePoolModel(object):
pool = self.get_storagepool(name, self.conn)
if pool.isActive():
raise InvalidOperation("KCHPOOL0005E", {'name': name})
+
+ vms = self._get_vms_attach_to_storagepool(name)
+ if len(vms) > 0:
+ raise InvalidOperation('KCHPOOL0039E', {'name': name,
+ 'vms': ",".join(vms)})
try:
pool.undefine()
except libvirt.libvirtError as e:
raise OperationFailed("KCHPOOL0011E",
{'name': name, 'err': e.get_error_message()})
+ def _get_vms_attach_to_storagepool(self, storagepool):
+ conn = self.conn.get()
+
+ # get storage pool path
+ pool = self.get_storagepool(storagepool, self.conn)
+ path = "".join(xpath_get_text(pool.XMLDesc(), "/pool/target/path"))
+
+ # activate and deactive quickly to get volumes
+ vms = []
+ for dom in conn.listAllDomains(0):
+ xml = dom.XMLDesc(0)
+ files = "/domain/devices/disk[@device='disk']/source/@file"
+ for file in xpath_get_text(xml, files):
+ if file not in vms and file.startswith(path):
+ vms.append(dom.name())
+ return vms
+
class IsoPoolModel(object):
def __init__(self, **kargs):
--
2.5.5
More information about the Kimchi-devel
mailing list