From: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
update mockmodel and model
Signed-off-by: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
---
src/kimchi/mockmodel.py | 3 +++
src/kimchi/model/templates.py | 5 +++++
src/kimchi/vmtemplate.py | 10 ++++++++++
3 files changed, 18 insertions(+)
diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
index b23a024..762f839 100644
--- a/src/kimchi/mockmodel.py
+++ b/src/kimchi/mockmodel.py
@@ -859,6 +859,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 eac1a2a..9177e46 100644
--- a/src/kimchi/model/templates.py
+++ b/src/kimchi/model/templates.py
@@ -163,6 +163,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 af07ee3..b8689d0 100644
--- a/src/kimchi/vmtemplate.py
+++ b/src/kimchi/vmtemplate.py
@@ -31,6 +31,7 @@ from kimchi import isoinfo
from kimchi import osinfo
from kimchi.exception import InvalidParameter, IsoFormatError
from kimchi.isoinfo import IsoImage
+from kimchi.utils import pool_name_from_uri
QEMU_NAMESPACE =
"xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'"
@@ -348,6 +349,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
@@ -356,6 +360,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