[Kimchi-devel] [PATCH V2 2/3] template integrity verification: verify storagepool in backend

shaohef at linux.vnet.ibm.com shaohef at linux.vnet.ibm.com
Tue Mar 4 14:55:05 UTC 2014


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

update mockmodel and model

Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
---
 src/kimchi/mockmodel.py       |  3 +++
 src/kimchi/model/templates.py |  5 +++++
 src/kimchi/vmtemplate.py      | 11 ++++++++++-
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
index f99b4cd..4ad6a30 100644
--- a/src/kimchi/mockmodel.py
+++ b/src/kimchi/mockmodel.py
@@ -862,6 +862,9 @@ class MockVMTemplate(VMTemplate):
     def _get_all_networks_name(self):
         return self.model.networks_get_list()
 
+    def _get_all_storagepools_name(self):
+        return self.model.storagepools_get_list()
+
     def _storage_validate(self):
         pool_uri = self.info['storagepool']
         pool_name = pool_name_from_uri(pool_uri)
diff --git a/src/kimchi/model/templates.py b/src/kimchi/model/templates.py
index 3062bd7..52e7eab 100644
--- a/src/kimchi/model/templates.py
+++ b/src/kimchi/model/templates.py
@@ -167,6 +167,11 @@ class LibvirtVMTemplate(VMTemplate):
         conn = self.conn.get()
         return sorted(conn.listNetworks() + conn.listDefinedNetworks())
 
+    def _get_all_storagepools_name(self):
+        conn = self.conn.get()
+        names = conn.listStoragePools() + conn.listDefinedStoragePools()
+        return sorted(map(lambda x: x.decode('utf-8'), names))
+
     def _network_validate(self):
         names = self.info['networks']
         for name in names:
diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py
index e2d78a4..f092cf7 100644
--- a/src/kimchi/vmtemplate.py
+++ b/src/kimchi/vmtemplate.py
@@ -26,7 +26,7 @@ import urlparse
 from kimchi import osinfo
 from kimchi.exception import InvalidParameter, IsoFormatError
 from kimchi.isoinfo import IsoImage
-from kimchi.utils import check_url_path
+from kimchi.utils import check_url_path, pool_name_from_uri
 
 
 QEMU_NAMESPACE = "xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'"
@@ -344,6 +344,9 @@ class VMTemplate(object):
     def _get_all_networks_name(self):
         return []
 
+    def _get_all_storagepools_name(self):
+        return []
+
     def validate_integrity(self):
         invalid = {}
         # validate networks integrity
@@ -352,6 +355,12 @@ class VMTemplate(object):
         if invalid_networks:
             invalid['networks'] = invalid_networks
 
+        # validate storagepools integrity
+        pool_uri = self.info['storagepool']
+        pool_name = pool_name_from_uri(pool_uri)
+        if pool_name not in self._get_all_storagepools_name():
+            invalid['storagepools'] = [pool_name]
+
         # validate iso integrity
         # FIXME when we support multiples cdrom devices
         iso = self.info['cdrom']
-- 
1.8.4.2




More information about the Kimchi-devel mailing list