From: Royce Lv <lvroyce(a)linux.vnet.ibm.com>
For pools which not allowed create and delete volume,
if create vm fails, its storage volume should not be destoryed.
Put the constant in single file to prevent circular import.
For storage volume deletion, fix deleting vol clear part for readonly pool.
Signed-off-by: Royce Lv <lvroyce(a)linux.vnet.ibm.com>
---
src/kimchi/config.py.in | 3 +++
src/kimchi/model/vms.py | 16 +++++++++++-----
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/src/kimchi/config.py.in b/src/kimchi/config.py.in
index 2747164..d1affea 100644
--- a/src/kimchi/config.py.in
+++ b/src/kimchi/config.py.in
@@ -31,6 +31,9 @@ from kimchi.xmlutils import xpath_get_text
DEFAULT_LOG_LEVEL = "debug"
+# Storage pool constant for read-only pool types
+READONLY_POOL_TYPE = ['iscsi', 'scsi', 'mpath']
+
def get_object_store():
return os.path.join(paths.state_dir, 'objectstore')
diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py
index a3b6c31..6267d03 100644
--- a/src/kimchi/model/vms.py
+++ b/src/kimchi/model/vms.py
@@ -27,6 +27,7 @@ from cherrypy.process.plugins import BackgroundTask
from kimchi import vnc
from kimchi import xmlutils
+from kimchi.config import READONLY_POOL_TYPE
from kimchi.exception import InvalidOperation, InvalidParameter
from kimchi.exception import MissingParameter, NotFoundError, OperationFailed
from kimchi.model.config import CapabilitiesModel
@@ -183,7 +184,7 @@ class VMsModel(object):
# If storagepool is SCSI, volumes will be LUNs and must be passed by
# the user from UI or manually.
vol_list = []
- if t._get_storage_type() == 'scsi':
+ if t._get_storage_type() in READONLY_POOL_TYPE:
if not params.get('volumes'):
raise MissingParameter('KCHVM0017E')
else:
@@ -215,9 +216,10 @@ class VMsModel(object):
try:
conn.defineXML(xml.encode('utf-8'))
except libvirt.libvirtError as e:
- for v in vol_list:
- vol = conn.storageVolLookupByPath(v['path'])
- vol.delete(0)
+ if t._get_storage_type() not in READONLY_POOL_TYPE:
+ for v in vol_list:
+ vol = conn.storageVolLookupByPath(v['path'])
+ vol.delete(0)
raise OperationFailed("KCHVM0007E", {'name': name,
'err': e.get_error_message()})
@@ -356,7 +358,11 @@ class VMModel(object):
for path in paths:
vol = conn.storageVolLookupByPath(path)
- vol.delete(0)
+ pool = vol.storagePoolLookupByVolume()
+ xml = pool.XMLDesc(0)
+ pool_type = xmlutils.xpath_get_text(xml, "/pool/@type")[0]
+ if pool_type not in READONLY_POOL_TYPE:
+ vol.delete(0)
with self.objstore as session:
session.delete('vm', dom.UUIDString(), ignore_missing=True)
--
1.8.1.2