<div class="socmaildefaultfont" dir="ltr" style="font-family:Arial;font-size:10.5pt" ><div dir="ltr" >This can be merged but in future you can do a small optimization by not initializing a list and use 'in' operator to check the match. If you are just comparing the strings then simple '==' operator is good enough unless you are doing substring matching or multiple strings matching. </div>
<div dir="ltr" ><div class="socmaildefaultfont" dir="ltr" style="font-family:Arial;font-size:10.5pt" ><div class="socmaildefaultfont" dir="ltr" style="font-family:Arial;font-size:10.5pt" ><div dir="ltr" style="margin-top: 20px;" ><div style="font-size: 12pt; font-weight: bold; font-family: sans-serif; color: #7C7C5F;" >Harshal Patil</div>
<div style="font-size: 8pt; font-family: sans-serif; margin-top: 10px;" ><div><span style="font-weight: bold; color: #336699;" >E-mail: </span><a href="mailto:harshal.patil@in.ibm.com" style="color: #555" >harshal.patil@in.ibm.com</a></div></div></div></div></div></div>
<div dir="ltr" > </div>
<div dir="ltr" > </div>
<blockquote data-history-content-modified="1" data-history-expanded="1" dir="ltr" style="border-left:solid #aaaaaa 2px; margin-left:5px; padding-left:5px; direction:ltr; margin-right:0px" >----- Original message -----<br>From: archus@linux.vnet.ibm.com<br>Sent by: kimchi-devel-bounces@ovirt.org<br>To: Kimchi Devel <kimchi-devel@ovirt.org><br>Cc:<br>Subject: [Kimchi-devel] [PATCH V1] [Kimchi] Only on s390x add default networks to template if template.conf has default network configuration uncommented.<br>Date: Wed, Aug 17, 2016 6:09 PM<br>
<div><font face="Default Monospace,Courier New,Courier,monospace" size="2" >From: Archana Singh <archus@linux.vnet.ibm.com><br><br>Below are the changes done for s390x architecture to only add default networks<br>to template if template.conf has network configuration uncommented<br>otherwise do not add any network by default.<br><br>1) Only on s390x, osinfo._get_tmpl_defaults() does not add<br>default network in case template.conf has commented out network configuration.<br>2) Only on s390x, NetworksModel._check_default_networks() does<br>not throw key error if networks not found in tmpl_defaults.<br>3) Only on s390x, VMTemplate.validate_integrity() does not throw<br>key error if networks not found in the template.<br>4) Only on s390x, LibvirtVMTemplate._network_validate() does not<br>throw key error on s390x if networks not found in tmpl_default, as on s390x networks is optional.<br>5) Only on s390x, VMTemplate._get_network_xml() does<br>return empty string and does not throw key error if networks not found in template object.<br>6) Only on s390x, control/templates.py gets networks as [] if not found<br>self.info.<br><br>Signed-off-by: Archana Singh <archus@linux.vnet.ibm.com><br>---<br> control/templates.py | 2 +-<br> model/networks.py | 7 ++++++-<br> model/templates.py | 5 ++++-<br> osinfo.py | 14 +++++++++++++-<br> vmtemplate.py | 15 +++++++++++++--<br> 5 files changed, 37 insertions(+), 6 deletions(-)<br><br>diff --git a/control/templates.py b/control/templates.py<br>index bb2e068..2dd8601 100644<br>--- a/control/templates.py<br>+++ b/control/templates.py<br>@@ -67,7 +67,7 @@ class Template(Resource):<br> 'memory': self.info['memory'],<br> 'cdrom': self.info.get('cdrom', None),<br> 'disks': self.info['disks'],<br>- 'networks': self.info['networks'],<br>+ 'networks': self.info.get('networks', []),<br> 'folder': self.info.get('folder', []),<br> 'graphics': self.info['graphics'],<br> 'cpu_info': self.info.get('cpu_info')<br>diff --git a/model/networks.py b/model/networks.py<br>index 35431d4..c9db979 100644<br>--- a/model/networks.py<br>+++ b/model/networks.py<br>@@ -21,6 +21,7 @@ import copy<br> import ipaddr<br> import libvirt<br> import time<br>+import os<br> from libvirt import VIR_INTERFACE_XML_INACTIVE<br> <br> from wok.exception import InvalidOperation, InvalidParameter<br>@@ -55,7 +56,11 @@ class NetworksModel(object):<br> self.caps = CapabilitiesModel(**kargs)<br> <br> def _check_default_networks(self):<br>- networks = list(set(tmpl_defaults['networks']))<br>+ if os.uname()[4] in ['s390x']:<br>+ networks = list(set(tmpl_defaults.get('networks', [])))<br>+ else:<br>+ networks = list(set(tmpl_defaults['networks']))<br>+<br> conn = self.conn.get()<br> <br> for net_name in networks:<br>diff --git a/model/templates.py b/model/templates.py<br>index a299c85..877bea1 100644<br>--- a/model/templates.py<br>+++ b/model/templates.py<br>@@ -358,7 +358,10 @@ class LibvirtVMTemplate(VMTemplate):<br> return sorted(map(lambda x: x.decode('utf-8'), names))<br> <br> def _network_validate(self):<br>- names = self.info['networks']<br>+ if os.uname()[4] in ['s390x']:<br>+ names = self.info.get('networks', [])<br>+ else:<br>+ names = self.info['networks']<br> for name in names:<br> try:<br> conn = self.conn.get()<br>diff --git a/osinfo.py b/osinfo.py<br>index 2c59312..af37c72 100644<br>--- a/osinfo.py<br>+++ b/osinfo.py<br>@@ -138,10 +138,22 @@ def _get_tmpl_defaults():<br> 'pool': '/plugins/kimchi/storagepools/default'}},<br> 'processor': {'vcpus': '1', 'maxvcpus': 1},<br> 'graphics': {'type': 'spice', 'listen': '127.0.0.1'}}<br>+<br>+ The default values on s390x architecture:<br>+<br>+ {'memory': {'current': 1024, 'maxmemory': 1024},<br>+ 'storage': { 'disk.0': {'format': 'qcow2', 'size': '10',<br>+ 'pool': '/plugins/kimchi/storagepools/default'}},<br>+ 'processor': {'vcpus': '1', 'maxvcpus': 1},<br>+ 'graphics': {'type': 'spice', 'listen': '127.0.0.1'}}<br> """<br> # Create dict with default values<br> tmpl_defaults = defaultdict(dict)<br>- tmpl_defaults['main']['networks'] = ['default']<br>+<br>+ host_arch = _get_arch()<br>+ if host_arch not in ['s390x']:<br>+ tmpl_defaults['main']['networks'] = ['default']<br>+<br> tmpl_defaults['memory'] = {'current': _get_default_template_mem(),<br> 'maxmemory': _get_default_template_mem()}<br> tmpl_defaults['storage']['disk.0'] = {'size': 10, 'format': 'qcow2',<br>diff --git a/vmtemplate.py b/vmtemplate.py<br>index dc81fe2..5a45123 100644<br>--- a/vmtemplate.py<br>+++ b/vmtemplate.py<br>@@ -288,7 +288,13 @@ class VMTemplate(object):<br> networks = ""<br> params = {'type': 'network',<br> 'model': self.info['nic_model']}<br>- for nw in self.info['networks']:<br>+<br>+ if os.uname()[4] in ['s390x']:<br>+ info_networks = self.info.get('networks', [])<br>+ else:<br>+ info_networks = self.info['networks']<br>+<br>+ for nw in info_networks:<br> params['network'] = nw<br> networks += get_iface_xml(params, self.info['arch'],<br> self.info['os_distro'],<br>@@ -484,7 +490,12 @@ class VMTemplate(object):<br> def validate_integrity(self):<br> invalid = {}<br> # validate networks integrity<br>- invalid_networks = list(set(self.info['networks']) -<br>+ if os.uname()[4] in ['s390x']:<br>+ networks = self.info.get('networks', [])<br>+ else:<br>+ networks = self.info['networks']<br>+<br>+ invalid_networks = list(set(networks) -<br> set(self._get_all_networks_name()))<br> if invalid_networks:<br> invalid['networks'] = invalid_networks<br>--<br>2.7.4<br><br>_______________________________________________<br>Kimchi-devel mailing list<br>Kimchi-devel@ovirt.org<br><a href="http://lists.ovirt.org/mailman/listinfo/kimchi-devel" target="_blank" >http://lists.ovirt.org/mailman/listinfo/kimchi-devel</a></font><br> </div></blockquote>
<div dir="ltr" > </div></div><BR>