
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@linux.vnet.ibm.com> --- i18n.py | 1 + model/storagepools.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/i18n.py b/i18n.py index 7625469..f1db243 100644 --- a/i18n.py +++ b/i18n.py @@ -225,6 +225,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..f8c1fe4 100644 --- a/model/storagepools.py +++ b/model/storagepools.py @@ -471,6 +471,11 @@ class StoragePoolModel(object): if self._pool_used_by_template(name): raise InvalidOperation('KCHPOOL0035E', {'name': name}) + vms = self._get_vms_attach_to_storagepool(name) + if len(vms) > 0: + raise InvalidOperation('KCHPOOL0039E', {'name': name, + 'vms': ",".join(vms)}) + pool = self.get_storagepool(name, self.conn) if pool.isActive(): raise InvalidOperation("KCHPOOL0005E", {'name': name}) @@ -480,6 +485,22 @@ class StoragePoolModel(object): 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 + stpool = self.get_storagepool(storagepool, self.conn) + path = "".join(xpath_get_text(stpool.XMLDesc(), "/pool/target/path")) + + vms = [] + for dom in conn.listAllDomains(0): + xml = dom.XMLDesc(0) + files = "/domain/devices/disk/source/@file" + for file in xpath_get_text(xml, files): + if file.startswith(path): + vms.append(dom.name()) + return vms + class IsoPoolModel(object): def __init__(self, **kargs): -- 2.5.5