Igor Lvovsky has uploaded a new change for review.

Change subject: Optimize _getConfigValue to return multiple values
......................................................................

Optimize _getConfigValue to return multiple values

Change-Id: I15ff5542095d51f33f5f1970b81a4a0cbfb30632
Signed-off-by: Igor Lvovsky <[email protected]>
---
M vdsm/configNetwork.py
1 file changed, 19 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/06/7306/1

diff --git a/vdsm/configNetwork.py b/vdsm/configNetwork.py
index 7e3379e..fb283ff 100755
--- a/vdsm/configNetwork.py
+++ b/vdsm/configNetwork.py
@@ -373,9 +373,11 @@
         cfg += conf
         # Check whether we need to preserve prev ip/mask/gateway
         if not ipaddr and os.path.exists(cf):
-            ipaddr = self._getConfigValue(cf, 'IPADDR')
-            netmask = self._getConfigValue(cf, 'NETMASK')
-            gateway = self._getConfigValue(cf, 'GATEWAY')
+            confParams = self._getConfigValue(cf, ['IPADDR', 'NETMASK',
+                                                   'GATEWAY'])
+            ipaddr = confParams['IPADDR']
+            netmask = confParams['NETMASK']
+            gateway = confParams['GATEWAY']
 
         if ipaddr:
             cfg = cfg + 'IPADDR=%s\nNETMASK=%s\n' % (pipes.quote(ipaddr),
@@ -485,12 +487,12 @@
         self._backup(self.NET_CONF_PREF + bridge)
         self._removeFile(self.NET_CONF_PREF + bridge)
 
-    def _getConfigValue(self, conffile, entry):
+    def _getConfigValue(self, conffile, entries):
         """
-        Get value from network configuration file
+        Get values from network configuration file
 
-        :param entry: entry to look for (entry=value)
-        :type entry: string
+        :param entry: entries to look for (entry=value)
+        :type entry: list
 
         :returns: value for entry (or None)
         :rtype: string
@@ -498,13 +500,14 @@
         Search for entry in conffile and return
         its value or None if not found
         """
+        confParams = dict(zip(entries, len(entries)*[None]))
         with open(conffile) as f:
-            entries = [ line for line in f.readlines()
-                        if line.startswith(entry + '=') ]
-        if len(entries) != 0:
-            value = entries[0].split('=', 1)[1]
-            return value.strip()
-        return None
+            for line in f.readlines():
+                key, val = line.split('=', 1)
+                if key.strip() in confParams:
+                    confParams[key.strip()] = val.strip()
+
+        return confParams
 
     def _updateConfigValue(self, conffile, entry, value, delete=False):
         """
@@ -551,7 +554,7 @@
         """
         for nic in nics:
             cf = self.NET_CONF_PREF + nic
-            mtuval = self._getConfigValue(cf, 'MTU')
+            mtuval = self._getConfigValue(cf, ['MTU'])['MTU']
             if not mtuval is None:
                 if int(mtuval) > mtu:
                     mtu = mtuval
@@ -570,7 +573,7 @@
         """
         _netinfo = netinfo.NetInfo()
         cf = self.NET_CONF_PREF + bridge
-        currmtu = self._getConfigValue(cf, 'MTU')
+        currmtu = self._getConfigValue(cf, ['MTU'])['MTU']
         if currmtu is None:
             return
 
@@ -591,7 +594,7 @@
             if vlan == delvlan:
                 continue
             cf = self.NET_CONF_PREF + vlan
-            mtu = self._getConfigValue(cf, 'MTU')
+            mtu = self._getConfigValue(cf, ['MTU'])['MTU']
             newmtu = max(newmtu, mtu)
 
         if newmtu != currmtu:


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I15ff5542095d51f33f5f1970b81a4a0cbfb30632
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Igor Lvovsky <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to