Petr Šebek has uploaded a new change for review.

Change subject: Change of ConfigWriter._createConfFile parameters
......................................................................

Change of ConfigWriter._createConfFile parameters

ifcfg.ConfigWriter._createConfFile now accepts IpConfig object instead
of number of arguments. It helps to reduce number of arguments passed
and make interface more flexible.

Change-Id: Iae5ec15048ed52170371dda1d0fa9b90d51838e3
Signed-off-by: Petr Sebek <pse...@redhat.com>
---
M vdsm/netconf/ifcfg.py
1 file changed, 30 insertions(+), 44 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/31/18331/1

diff --git a/vdsm/netconf/ifcfg.py b/vdsm/netconf/ifcfg.py
index 8fafbd0..7ba6361 100644
--- a/vdsm/netconf/ifcfg.py
+++ b/vdsm/netconf/ifcfg.py
@@ -445,30 +445,29 @@
             return None
         return 'yes' if defaultRoute else 'no'
 
-    def _createConfFile(self, conf, name, ipaddr=None, netmask=None,
-                        gateway=None, bootproto=None, mtu=None,
-                        defaultRoute=None, onboot='yes', **kwargs):
+    def _createConfFile(self, conf, name, ipconfig=None, mtu=None,
+                        onboot='yes', **kwargs):
         """ Create ifcfg-* file with proper fields per device """
         cfg = self.CONFFILE_HEADER + '\n'
 
         cfg += """DEVICE=%s\nONBOOT=%s\n""" % (pipes.quote(name),
                                                pipes.quote(onboot))
         cfg += conf
-        if ipaddr:
-            cfg = cfg + 'IPADDR=%s\nNETMASK=%s\n' % (pipes.quote(ipaddr),
-                                                     pipes.quote(netmask))
-            if gateway:
-                cfg = cfg + 'GATEWAY=%s\n' % pipes.quote(gateway)
-            # According to manual the BOOTPROTO=none should be set
-            # for static IP
-            cfg = cfg + 'BOOTPROTO=none\n'
-        else:
-            if bootproto:
-                cfg = cfg + 'BOOTPROTO=%s\n' % pipes.quote(bootproto)
+        if ipconfig is not None:
+            if ipconfig.ipaddr:
+                cfg = cfg + 'IPADDR=%s\n' % pipes.quote(ipconfig.ipaddr)
+                cfg = cfg + 'NETMASK=%s\n' % pipes.quote(ipconfig.netmask)
+                if ipconfig.gateway:
+                    cfg = cfg + 'GATEWAY=%s\n' % pipes.quote(ipconfig.gateway)
+                # According to manual the BOOTPROTO=none should be set
+                # for static IP
+                cfg = cfg + 'BOOTPROTO=none\n'
+            elif ipconfig.bootproto:
+                cfg = cfg + 'BOOTPROTO=%s\n' % pipes.quote(ipconfig.bootproto)
+            if ipconfig.defaultRoute:
+                cfg = cfg + 'DEFROUTE=%s\n' % ipconfig.defaultRoute
         if mtu:
             cfg = cfg + 'MTU=%d\n' % mtu
-        if defaultRoute:
-            cfg = cfg + 'DEFROUTE=%s\n' % defaultRoute
         cfg += 'NM_CONTROLLED=no\n'
         BLACKLIST = ['TYPE', 'NAME', 'DEVICE', 'bondingOptions',
                      'force', 'blockingdhcp',
@@ -484,24 +483,16 @@
 
     def addBridge(self, bridge, **opts):
         """ Create ifcfg-* file with proper fields for bridge """
-        ipaddr, netmask, gateway, bootproto, _, defaultRoute = \
-            bridge.ipConfig
         conf = 'TYPE=Bridge\nDELAY=%s\n' % bridge.forwardDelay
-        self._createConfFile(conf, bridge.name, ipaddr, netmask, gateway,
-                             bootproto, bridge.mtu,
-                             self._toIfcfgFormat(defaultRoute), **opts)
+        self._createConfFile(conf, bridge.name, bridge.ip, bridge.mtu, **opts)
 
     def addVlan(self, vlan, **opts):
         """ Create ifcfg-* file with proper fields for VLAN """
-        ipaddr, netmask, gateway, bootproto, _, defaultRoute = \
-            vlan.ipConfig
         conf = 'VLAN=yes\n'
         if vlan.bridge:
             conf += 'BRIDGE=%s\n' % pipes.quote(vlan.bridge.name)
 
-        self._createConfFile(conf, vlan.name, ipaddr, netmask, gateway,
-                             bootproto, vlan.mtu,
-                             self._toIfcfgFormat(defaultRoute), **opts)
+        self._createConfFile(conf, vlan.name, vlan.ip, vlan.mtu, **opts)
 
     def addBonding(self, bond, **opts):
         """ Create ifcfg-* file with proper fields for bond """
@@ -509,10 +500,8 @@
         if bond.bridge:
             conf += 'BRIDGE=%s\n' % pipes.quote(bond.bridge.name)
 
-        ipaddr, netmask, gateway, bootproto, mtu, defaultRoute = \
-            self._getIfaceConfValues(bond, netinfo.NetInfo())
-        self._createConfFile(conf, bond.name, ipaddr, netmask, gateway,
-                             bootproto, mtu, defaultRoute, **opts)
+        ipconfig = self._getIfaceConfValues(bond, netinfo.NetInfo())
+        self._createConfFile(conf, bond.name, ipconfig, **opts)
 
         # create the bonding device to avoid initscripts noise
         if bond.name not in open(netinfo.BONDING_MASTERS).read().split():
@@ -530,31 +519,28 @@
         if nic.bond:
             conf += 'MASTER=%s\nSLAVE=yes\n' % pipes.quote(nic.bond.name)
 
-        ipaddr, netmask, gateway, bootproto, mtu, defaultRoute = \
-            self._getIfaceConfValues(nic, _netinfo)
-        self._createConfFile(conf, nic.name, ipaddr, netmask, gateway,
-                             bootproto, mtu, defaultRoute, **opts)
+        ipconfig = self._getIfaceConfValues(nic, _netinfo)
+        self._createConfFile(conf, nic.name, ipconfig, **opts)
 
     @staticmethod
     def _getIfaceConfValues(iface, _netinfo):
-        ipaddr, netmask, gateway, bootproto, _, defaultRoute = \
-            iface.ipConfig
-        defaultRoute = ConfigWriter._toIfcfgFormat(defaultRoute)
+        ipconfig = iface.ip
+        defaultRoute = ConfigWriter._toIfcfgFormat(ipconfig.inet.defaultRoute)
         mtu = iface.mtu
         if _netinfo.ifaceUsers(iface.name):
             confParams = netinfo.getIfaceCfg(iface.name)
-            if not ipaddr and bootproto != 'dhcp':
-                ipaddr = confParams.get('IPADDR', None)
-                netmask = confParams.get('NETMASK', None)
-                gateway = confParams.get('GATEWAY', None)
-                bootproto = confParams.get('BOOTPROTO', None)
+            if not ipconfig.inet.address and ipconfig.bootproto != 'dhcp':
+                ipconfig.inet.address = confParams.get('IPADDR', None)
+                ipconfig.inet.netmask = confParams.get('NETMASK', None)
+                ipconfig.inet.gateway = confParams.get('GATEWAY', None)
+                ipconfig.bootproto = confParams.get('BOOTPROTO', None)
             if defaultRoute is None:
-                defaultRoute = confParams.get('DEFROUTE', None)
+                ipconfig.inet.defaultRoute = confParams.get('DEFROUTE', None)
             if not iface.mtu:
                 mtu = confParams.get('MTU', None)
                 if mtu:
                     mtu = int(mtu)
-        return ipaddr, netmask, gateway, bootproto, mtu, defaultRoute
+        return iface.ip
 
     def removeNic(self, nic):
         cf = netinfo.NET_CONF_PREF + nic


-- 
To view, visit http://gerrit.ovirt.org/18331
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iae5ec15048ed52170371dda1d0fa9b90d51838e3
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Petr Šebek <pse...@redhat.com>
_______________________________________________
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to