Change in vdsm[master]: net: remove last dependency on ifcfg persistence

asegurap at redhat.com asegurap at redhat.com
Mon Jun 9 19:42:33 UTC 2014


Antoni Segura Puimedon has uploaded a new change for review.

Change subject: net: remove last dependency on ifcfg persistence
......................................................................

net: remove last dependency on ifcfg persistence

Up until now, some of the most corner case behavior (removal of
partially broken networks) was only working for ifcfg persistence
or ifcfg configurator + unified persistence.

This patch cleans the api from ifcfgisms.

Change-Id: Ia5d682eaf93b488fac0391bf4b84394d73d7f485
Signed-off-by: Antoni S. Puimedon <asegurap at redhat.com>
---
M lib/vdsm/netconfpersistence.py
M vdsm/network/api.py
M vdsm/network/configurators/ifcfg.py
3 files changed, 49 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/30/28530/1

diff --git a/lib/vdsm/netconfpersistence.py b/lib/vdsm/netconfpersistence.py
index 4114577..b92e10c 100644
--- a/lib/vdsm/netconfpersistence.py
+++ b/lib/vdsm/netconfpersistence.py
@@ -199,3 +199,15 @@
     def restore(self):
         restore()
         return RunningConfig()
+
+
+def configuredPorts(network):
+    nic = network.get('nic')
+    bond = network.get('bonding')
+    vlan = network.get('vlan', '')
+    if bond:
+        return [bond + vlan]
+    elif nic:
+        return [nic + vlan]
+    else:  # isolated bridged network
+        return []
diff --git a/vdsm/network/api.py b/vdsm/network/api.py
index bf210b4..01ace74 100755
--- a/vdsm/network/api.py
+++ b/vdsm/network/api.py
@@ -30,7 +30,6 @@
 from vdsm import netinfo
 from vdsm import utils
 
-from .configurators.ifcfg import ConfigWriter
 from .configurators import libvirt
 from .errors import ConfigNetworkError
 from . import errors as ne
@@ -52,7 +51,19 @@
         from .configurators.ifcfg import Ifcfg
         return Ifcfg
 
+
+def _getPersistenceModule():
+    persistence = config.get('vars', 'net_persistence')
+    if persistence == 'unified':
+        from vdsm import netconfpersistence
+        return netconfpersistence
+    else:
+        from .configurators import ifcfg
+        return ifcfg
+
+
 ConfiguratorClass = _getConfiguratorClass()
+persistence = _getPersistenceModule()
 
 
 def objectivizeNetwork(bridge=None, vlan=None, bonding=None,
@@ -364,13 +375,23 @@
     print "Bondings:", _netinfo.bondings.keys()
 
 
+def _configuredPorts(bridge, configurator):
+    """Returns the configured ports for a bridge"""
+    if config.get('vars', 'net_persistence') == 'unified':
+        return persistence.configuredPorts(
+            configurator.runningConfig.networks[bridge])
+    else:
+        return persistence.configuredPorts(bridge)
+
+
 def _delBrokenNetwork(network, netAttr, configurator):
     '''Adapts the network information of broken networks so that they can be
     deleted via delNetwork.'''
     _netinfo = netinfo.NetInfo()
     _netinfo.networks[network] = netAttr
     if _netinfo.networks[network]['bridged']:
-        _netinfo.networks[network]['ports'] = ConfigWriter.ifcfgPorts(network)
+        _netinfo.networks[network]['ports'] = _configuredPorts(network,
+                                                               configurator)
     elif not os.path.exists('/sys/class/net/' + netAttr['iface']):
         # Bridgeless broken network without underlying device
         libvirt.removeNetwork(network)
diff --git a/vdsm/network/configurators/ifcfg.py b/vdsm/network/configurators/ifcfg.py
index 8dc5743..48e303b 100644
--- a/vdsm/network/configurators/ifcfg.py
+++ b/vdsm/network/configurators/ifcfg.py
@@ -516,20 +516,6 @@
             else:
                 os.remove(fpath)
 
-    @classmethod
-    def ifcfgPorts(cls, network):
-        ports = []
-        for filePath in glob.iglob(netinfo.NET_CONF_PREF + '*'):
-            with open(filePath, 'r') as confFile:
-                for line in confFile:
-                    if line.startswith('BRIDGE=' + network):
-                        port = filePath[filePath.rindex('-') + 1:]
-                        logging.debug('port %s found in ifcfg for %s', port,
-                                      network)
-                        ports.append(port)
-                        break
-        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.'''
@@ -801,3 +787,17 @@
     else:
         rc, out, err = _ifup(iface)
         return rc
+
+
+def configuredPorts(bridge):
+    ports = []
+    for filePath in glob.iglob(netinfo.NET_CONF_PREF + '*'):
+        with open(filePath) as confFile:
+            for line in confFile:
+                if line.startswith('BRIDGE=' + bridge):
+                    port = filePath[filePath.rindex('-') + 1:]
+                    logging.debug('port %s found in ifcfg for %s', port,
+                                  bridge)
+                    ports.append(port)
+                    break
+    return ports


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia5d682eaf93b488fac0391bf4b84394d73d7f485
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