Change in vdsm[master]: cleanup: ifcfg configurator static methods and list handling

asegurap at redhat.com asegurap at redhat.com
Thu Oct 24 19:03:47 UTC 2013


Antoni Segura Puimedon has uploaded a new change for review.

Change subject: cleanup: ifcfg configurator static methods and list handling
......................................................................

cleanup: ifcfg configurator static methods and list handling

Change-Id: I83051a07d3b907ba31a01f75e64f01f3f2e7a165
Signed-off-by: Antoni S. Puimedon <asegurap at redhat.com>
---
M vdsm/netconf/ifcfg.py
1 file changed, 26 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/36/20536/1

diff --git a/vdsm/netconf/ifcfg.py b/vdsm/netconf/ifcfg.py
index cf198ef..c0a4144 100644
--- a/vdsm/netconf/ifcfg.py
+++ b/vdsm/netconf/ifcfg.py
@@ -193,7 +193,8 @@
             self._setNewMtu(nic, _netinfo.getVlanDevsForIface(nic.name))
         ifup(nic.name)
 
-    def _getFilePath(self, fileType, device):
+    @staticmethod
+    def _getFilePath(fileType, device):
         return os.path.join(netinfo.NET_CONF_DIR, '%s-%s' % (fileType, device))
 
     def _removeSourceRouteFile(self, fileType, device):
@@ -361,7 +362,8 @@
                     confFile.write(content)
             logging.info('Restored %s', confFilePath)
 
-    def _devType(self, content):
+    @staticmethod
+    def _devType(content):
         if re.search('^TYPE=Bridge$', content, re.MULTILINE):
             return "Bridge"
         elif re.search('^VLAN=yes$', content, re.MULTILINE):
@@ -371,7 +373,8 @@
         else:
             return "Other"
 
-    def _sortDeviceIfcfgs(self, deviceIfcfgs):
+    @classmethod
+    def _sortDeviceIfcfgs(cls, deviceIfcfgs):
         devdict = {'Bridge': [],
                    'Vlan': [],
                    'Slave': [],
@@ -380,7 +383,8 @@
             if not confFile.startswith(netinfo.NET_CONF_PREF):
                 continue
             try:
-                content = file(confFile).read()
+                with open(confFile) as confFileObj:
+                    content = confFileObj.read()
             except IOError as e:
                 if e.errno == os.errno.ENOENT:
                     continue
@@ -388,15 +392,17 @@
                     raise
             dev = confFile[len(netinfo.NET_CONF_PREF):]
 
-            devdict[self._devType(content)].append(dev)
+            devdict[cls._devType(content)].append(dev)
 
         return devdict['Other'] + devdict['Vlan'] + devdict['Bridge']
 
-    def _stopDevices(self, deviceIfcfgs):
+    @staticmethod
+    def _stopDevices(deviceIfcfgs):
         for dev in reversed(deviceIfcfgs):
             ifdown(dev)
 
-    def _startDevices(self, deviceIfcfgs):
+    @staticmethod
+    def _startDevices(deviceIfcfgs):
         for dev in deviceIfcfgs:
             try:
                 ifup(dev)
@@ -504,8 +510,8 @@
         return ports
 
     def writeConfFile(self, fileName, configuration):
-        '''Backs up the previous contents of the file referenced by fileName
-        writes the new configuration and sets the specified access mode.'''
+        """Backs up the previous contents of the file referenced by fileName
+        writes the new configuration and sets the specified access mode."""
         self._backup(fileName)
         logging.debug('Writing to file %s configuration:\n%s' % (fileName,
                       configuration))
@@ -533,20 +539,20 @@
                                                pipes.quote(onboot))
         cfg += conf
         if ipconfig.ipaddr:
-            cfg = cfg + 'IPADDR=%s\n' % pipes.quote(ipconfig.ipaddr)
-            cfg = cfg + 'NETMASK=%s\n' % pipes.quote(ipconfig.netmask)
+            cfg += 'IPADDR=%s\n' % pipes.quote(ipconfig.ipaddr)
+            cfg += 'NETMASK=%s\n' % pipes.quote(ipconfig.netmask)
             if ipconfig.gateway:
-                cfg = cfg + 'GATEWAY=%s\n' % pipes.quote(ipconfig.gateway)
+                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'
+            cfg += 'BOOTPROTO=none\n'
         elif ipconfig.bootproto:
-            cfg = cfg + 'BOOTPROTO=%s\n' % pipes.quote(ipconfig.bootproto)
+            cfg += 'BOOTPROTO=%s\n' % pipes.quote(ipconfig.bootproto)
 
         if mtu:
-            cfg = cfg + 'MTU=%d\n' % mtu
+            cfg += 'MTU=%d\n' % mtu
         if ipconfig.defaultRoute:
-            cfg = cfg + 'DEFROUTE=%s\n' % ipconfig.defaultRoute
+            cfg += 'DEFROUTE=%s\n' % ipconfig.defaultRoute
         cfg += 'NM_CONTROLLED=no\n'
         if ipconfig.ipv6addr or ipconfig.ipv6autoconf or ipconfig.dhcpv6:
             cfg += 'IPV6INIT=yes\n'
@@ -675,7 +681,8 @@
         self._backup(netinfo.NET_CONF_PREF + bridge)
         self._removeFile(netinfo.NET_CONF_PREF + bridge)
 
-    def _getConfigValue(self, conffile, entry):
+    @staticmethod
+    def _getConfigValue(conffile, entry):
         """
         Get value from network configuration file
 
@@ -729,13 +736,13 @@
 
 
 def ifdown(iface):
-    "Bring down an interface"
+    """Bring down an interface"""
     rc, out, err = utils.execCmd([constants.EXT_IFDOWN, iface], raw=True)
     return rc
 
 
 def ifup(iface, async=False):
-    "Bring up an interface"
+    """Bring up an interface"""
     def _ifup(netIf):
         rc, out, err = utils.execCmd([constants.EXT_IFUP, netIf], raw=False)
 


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I83051a07d3b907ba31a01f75e64f01f3f2e7a165
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Antoni Segura Puimedon <asegurap at redhat.com>


More information about the vdsm-patches mailing list