[Kimchi-devel] [PATCH V3 3/4] Implement integrity verification: verify template integrity in backend
Shu Ming
shuming at linux.vnet.ibm.com
Fri Feb 21 09:33:03 UTC 2014
Reviewed-by: Shu Ming <shuming at linux.vnet.ibm.com>
2014/2/21 14:59, shaohef at linux.vnet.ibm.com:
> From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
>
> update controller, mockmodel and model
>
> Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
> ---
> src/kimchi/control/templates.py | 1 +
> src/kimchi/mockmodel.py | 5 ++++-
> src/kimchi/model/templates.py | 7 ++++++-
> src/kimchi/vmtemplate.py | 32 ++++++++++++++++++++++++++++++++
> 4 files changed, 43 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 8ef4431..04cdb11 100644
> --- a/src/kimchi/mockmodel.py
> +++ b/src/kimchi/mockmodel.py
> @@ -208,7 +208,7 @@ class MockModel(object):
>
> def template_lookup(self, name):
> t = self._get_template(name)
> - return t.info
> + return t.validate_integrity()
>
> def template_delete(self, name):
> try:
> @@ -851,6 +851,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..eac1a2a 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.validate_integrity()
>
> 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 sorted(conn.listNetworks() + conn.listDefinedNetworks())
> +
> 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 a11ddd0..af07ee3 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 validate_integrity(self):
> + invalid = {}
> + # validate networks integrity
> + invalid_networks = list(set(self.info['networks']) -
> + set(self._get_all_networks_name()))
> + if invalid_networks:
> + invalid['networks'] = invalid_networks
> +
> + # validate iso integrity
> + # FIXME when we support multiples cdrom devices
> + iso = self.info['cdrom']
> + try:
> + self.get_iso_info(iso)
> + except Exception:
> + invalid['cdrom'] = [iso]
> +
> + # validate 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
More information about the Kimchi-devel
mailing list