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 | 2 +-
src/kimchi/model/templates.py | 32 +++++++++++++++++++++++++++++++-
3 files changed, 33 insertions(+), 2 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..68525cb 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:
diff --git a/src/kimchi/model/templates.py b/src/kimchi/model/templates.py
index 5d09813..8089beb 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()
def clone(self, name):
# set default name
@@ -171,6 +172,35 @@ class LibvirtVMTemplate(VMTemplate):
if not network.isActive():
raise InvalidParameter("KCHTMPL0007E", {'network':
name,
'template': self.name})
+ def invalid_integrity(self):
+ invalid = {}
+ # invalid networks integrity
+ conn = self.conn.get()
+ networks = [net.name() for net in conn.listAllNetworks()]
+ invalid_networks = list(set(self.info['networks']) - set(networks))
+ 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 os.path.exists(volume):
+ volumes.append(volume)
+ if volumes:
+ invalid['disks'] = volumes
+
+ self.info['invalid'] = invalid
+
+ return self.info
def _get_storage_path(self):
pool = self._storage_validate()
--
1.8.4.2