On 02/19/2014 11:23 AM, shaohef(a)linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
update controller, mockmodel and model
Signed-off-by: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
---
src/kimchi/control/templates.py | 1 +
src/kimchi/mockmodel.py | 5 ++++-
src/kimchi/model/templates.py | 8 ++++++--
src/kimchi/vmtemplate.py | 32 ++++++++++++++++++++++++++++++++
4 files changed, 43 insertions(+), 3 deletions(-)
diff --git a/src/kimchi/control/templates.py b/src/kimchi/control/templates.py
index 8135e32..3f1dc7a 100644
--- a/src/kimchi/control/templates.py
+++ b/src/kimchi/control/templates.py
@@ -46,6 +46,7 @@ class Template(Resource):
def data(self):
return {'name': self.ident,
'icon': self.info['icon'],
+ 'invalid': self.info['invalid'],
'os_distro': self.info['os_distro'],
'os_version': self.info['os_version'],
'cpus': self.info['cpus'],
diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
index a0e5120..69574d0 100644
--- a/src/kimchi/mockmodel.py
+++ b/src/kimchi/mockmodel.py
@@ -207,7 +207,7 @@ class MockModel(object):
def template_lookup(self, name):
t = self._get_template(name)
- return t.info
+ return t.invalid_integrity()
def template_delete(self, name):
try:
@@ -809,6 +809,9 @@ class MockVMTemplate(VMTemplate):
VMTemplate.__init__(self, args)
self.model = mockmodel_inst
+ def _get_all_networks_name(self):
+ return self.model.networks_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 5d09813..ad19543 100644
--- a/src/kimchi/model/templates.py
+++ b/src/kimchi/model/templates.py
@@ -21,6 +21,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import copy
+import os
import libvirt
@@ -83,7 +84,7 @@ class TemplateModel(object):
def lookup(self, name):
t = self.get_template(name, self.objstore, self.conn)
- return t.info
+ return t.invalid_integrity()
I think t.validate_integrity() is more meaningful
def clone(self, name):
# set default name
@@ -158,6 +159,10 @@ class LibvirtVMTemplate(VMTemplate):
return pool
+ def _get_all_networks_name(self):
+ conn = self.conn.get()
+ return [net.name() for net in conn.listAllNetworks()]
+
def _network_validate(self):
names = self.info['networks']
for name in names:
@@ -171,7 +176,6 @@ class LibvirtVMTemplate(VMTemplate):
if not network.isActive():
raise InvalidParameter("KCHTMPL0007E", {'network':
name,
'template':
self.name})
-
def _get_storage_path(self):
pool = self._storage_validate()
xml = pool.XMLDesc(0)
diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py
index a11ddd0..be71e10 100644
--- a/src/kimchi/vmtemplate.py
+++ b/src/kimchi/vmtemplate.py
@@ -344,3 +344,35 @@ class VMTemplate(object):
def _get_storage_type(self):
return ''
+
+ def _get_all_networks_name(self):
+ return []
+
+ def invalid_integrity(self):
+ invalid = {}
+ # invalid networks integrity
+ invalid_networks = list(set(self.info['networks']) -
+ set(self._get_all_networks_name()))
+ if invalid_networks:
+ invalid['networks'] = invalid_networks
+
+ # invalid iso integrity
+ # FIXME when we support multiples cdrom devices
+ iso = self.info['cdrom']
+ try:
+ self.get_iso_info(iso)
+ except Exception:
+ invalid['cdrom'] = [iso]
+
+ # invalid disks integrity
+ volumes = []
+ for disk in self.info['disks']:
+ volume = disk.get("volume")
+ if volume is not None and not os.path.exists(volume):
+ volumes.append(volume)
+ if volumes:
+ invalid['disks'] = volumes
+
+ self.info['invalid'] = invalid
+
+ return self.info