[PATCH V3] [Kimchi] Only on s390x add default networks to template if template.conf has default network configuration uncommented.

From: Archana Singh <archus@linux.vnet.ibm.com> Below are the changes done for s390x architecture to only add default networks to template if template.conf has network configuration uncommented otherwise do not add any network by default. 1) Only on s390x, osinfo._get_tmpl_defaults() does not add default network in case template.conf has commented out network configuration. 2) NetworksModel._check_default_networks() does not throw key error if networks not found in tmpl_defaults. 3) VMTemplate.validate_integrity() does not throw key error if networks not found in the template. 4) LibvirtVMTemplate._network_validate() does not throw key error if networks not found in tmpl_default, as on s390x networks is optional. 5) VMTemplate._get_network_xml() does return empty string and does not throw key error if networks not found in template object. 6) control/templates.py gets empty networks list if not found in self.info. Signed-off-by: Archana Singh <archus@linux.vnet.ibm.com> --- control/templates.py | 2 +- model/networks.py | 3 ++- model/templates.py | 2 +- osinfo.py | 14 +++++++++++++- vmtemplate.py | 11 ++++++++--- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/control/templates.py b/control/templates.py index bb2e068..2dd8601 100644 --- a/control/templates.py +++ b/control/templates.py @@ -67,7 +67,7 @@ class Template(Resource): 'memory': self.info['memory'], 'cdrom': self.info.get('cdrom', None), 'disks': self.info['disks'], - 'networks': self.info['networks'], + 'networks': self.info.get('networks', []), 'folder': self.info.get('folder', []), 'graphics': self.info['graphics'], 'cpu_info': self.info.get('cpu_info') diff --git a/model/networks.py b/model/networks.py index 35431d4..b9d363a 100644 --- a/model/networks.py +++ b/model/networks.py @@ -55,7 +55,8 @@ class NetworksModel(object): self.caps = CapabilitiesModel(**kargs) def _check_default_networks(self): - networks = list(set(tmpl_defaults['networks'])) + networks = list(set(tmpl_defaults.get('networks', []))) + conn = self.conn.get() for net_name in networks: diff --git a/model/templates.py b/model/templates.py index a299c85..8df8c3b 100644 --- a/model/templates.py +++ b/model/templates.py @@ -358,7 +358,7 @@ class LibvirtVMTemplate(VMTemplate): return sorted(map(lambda x: x.decode('utf-8'), names)) def _network_validate(self): - names = self.info['networks'] + names = self.info.get('networks', []) for name in names: try: conn = self.conn.get() diff --git a/osinfo.py b/osinfo.py index 2c59312..528cf14 100644 --- a/osinfo.py +++ b/osinfo.py @@ -138,10 +138,22 @@ def _get_tmpl_defaults(): 'pool': '/plugins/kimchi/storagepools/default'}}, 'processor': {'vcpus': '1', 'maxvcpus': 1}, 'graphics': {'type': 'spice', 'listen': '127.0.0.1'}} + + The default values on s390x architecture: + + {'memory': {'current': 1024, 'maxmemory': 1024}, + 'storage': { 'disk.0': {'format': 'qcow2', 'size': '10', + 'pool': '/plugins/kimchi/storagepools/default'}}, + 'processor': {'vcpus': '1', 'maxvcpus': 1}, + 'graphics': {'type': 'spice', 'listen': '127.0.0.1'}} """ # Create dict with default values tmpl_defaults = defaultdict(dict) - tmpl_defaults['main']['networks'] = ['default'] + + host_arch = _get_arch() + if host_arch != 's390x': + tmpl_defaults['main']['networks'] = ['default'] + tmpl_defaults['memory'] = {'current': _get_default_template_mem(), 'maxmemory': _get_default_template_mem()} tmpl_defaults['storage']['disk.0'] = {'size': 10, 'format': 'qcow2', diff --git a/vmtemplate.py b/vmtemplate.py index 7ac0541..babf050 100644 --- a/vmtemplate.py +++ b/vmtemplate.py @@ -288,7 +288,10 @@ class VMTemplate(object): networks = "" params = {'type': 'network', 'model': self.info['nic_model']} - for nw in self.info['networks']: + + info_networks = self.info.get('networks', []) + + for nw in info_networks: params['network'] = nw networks += get_iface_xml(params, self.info['arch'], self.info['os_distro'], @@ -353,7 +356,7 @@ class VMTemplate(object): graphics.update(kwargs.get('graphics', {})) # Graphics is not supported on s390x, this check will # not add graphics tag in domain xml. - if params['arch'] not in ['s390x']: + if params.get('arch') != 's390x': params['graphics'] = get_graphics_xml(graphics) libvirt_stream_protocols = kwargs.get('libvirt_stream_protocols', []) @@ -487,7 +490,9 @@ class VMTemplate(object): def validate_integrity(self): invalid = {} # validate networks integrity - invalid_networks = list(set(self.info['networks']) - + networks = self.info.get('networks', []) + + invalid_networks = list(set(networks) - set(self._get_all_networks_name())) if invalid_networks: invalid['networks'] = invalid_networks -- 2.7.4
participants (2)
-
Aline Manera
-
archus@linux.vnet.ibm.com