Change in vdsm[master]: netconf: Add config option for network configurator

wudxw at linux.vnet.ibm.com wudxw at linux.vnet.ibm.com
Fri Aug 16 09:58:21 UTC 2013


Mark Wu has uploaded a new change for review.

Change subject: netconf: Add config option for network configurator
......................................................................

netconf: Add config option for network configurator

Change-Id: I426a38f229131ce6d32568387be7a809b09ae0c1
Signed-off-by: Mark Wu <wudxw at linux.vnet.ibm.com>
---
M lib/vdsm/config.py.in
M vdsm/configNetwork.py
2 files changed, 28 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/10/18210/1

diff --git a/lib/vdsm/config.py.in b/lib/vdsm/config.py.in
index bdbd91a..446c20f 100644
--- a/lib/vdsm/config.py.in
+++ b/lib/vdsm/config.py.in
@@ -42,6 +42,9 @@
             'Comma-separated list of fnmatch-patterns for dummy hosts nics to '
             'be shown to vdsm.'),
 
+        ('configurator', 'ifcfg',
+            'Whether to use "ifcfg" or "iproute2" to configure networks.'),
+
         ('nic_model', 'rtl8139,pv',
             'NIC model is rtl8139, ne2k_pci pv or any other valid device '
             'recognized by kvm/qemu if a coma separated list given then a '
diff --git a/vdsm/configNetwork.py b/vdsm/configNetwork.py
index 155d22a..b87d8d7 100755
--- a/vdsm/configNetwork.py
+++ b/vdsm/configNetwork.py
@@ -23,6 +23,7 @@
 import time
 import logging
 
+from vdsm.config import config
 from vdsm import constants
 from vdsm import utils
 from storage.misc import execCmd
@@ -31,7 +32,6 @@
 from vdsm import define
 from vdsm import netinfo
 from netconf.ifcfg import ConfigWriter
-from netconf.ifcfg import Ifcfg
 from netmodels import Bond
 from netmodels import Bridge
 from netmodels import IPv4
@@ -40,6 +40,25 @@
 from netmodels import Vlan
 
 CONNECTIVITY_TIMEOUT_DEFAULT = 4
+
+
+def _getConfigurator():
+
+    @utils.memoized
+    def getConfiguratorClass():
+        configurator = config.get('vars', 'configurator')
+        if configurator == 'iproute2':
+            from netconf.iproute2 import Iproute2
+            return Iproute2
+        else:
+            if configurator != 'ifcfg':
+                logging.warn('Invalid config for network configruator: %s. '
+                             'Use ifcfg instead.', configurator)
+            from netconf.ifcfg import Ifcfg
+            return Ifcfg
+
+    configuratorClass = getConfiguratorClass()
+    return configuratorClass()
 
 
 def objectivizeNetwork(bridge=None, vlan=None, bonding=None,
@@ -72,7 +91,7 @@
     :returns: the top object of the hierarchy.
     """
     if configurator is None:
-        configurator = Ifcfg()
+        configurator = _getConfigurator()
     if _netinfo is None:
         _netinfo = netinfo.NetInfo()
     if bondingOptions and not bonding:
@@ -191,7 +210,7 @@
                  mtu, bridged, options)
 
     if configurator is None:
-        configurator = Ifcfg()
+        configurator = _getConfigurator()
 
     bootproto = options.pop('bootproto', None)
 
@@ -297,7 +316,7 @@
         _netinfo = netinfo.NetInfo()
 
     if configurator is None:
-        configurator = Ifcfg()
+        configurator = _getConfigurator()
 
     if network not in _netinfo.networks:
         logging.info("Network %r: doesn't exist in libvirt database", network)
@@ -347,7 +366,7 @@
 
 def editNetwork(oldBridge, newBridge, vlan=None, bonding=None, nics=None,
                 **options):
-    configurator = Ifcfg()
+    configurator = _getConfigurator()
     try:
         delNetwork(oldBridge, configurator=configurator, **options)
         addNetwork(newBridge, vlan=vlan, bonding=bonding, nics=nics,
@@ -480,7 +499,7 @@
     """
     logger = logging.getLogger("setupNetworks")
     _netinfo = netinfo.NetInfo()
-    configurator = Ifcfg()
+    configurator = _getConfigurator()
     networksAdded = set()
 
     logger.debug("Setting up network according to configuration: "


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I426a38f229131ce6d32568387be7a809b09ae0c1
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Mark Wu <wudxw at linux.vnet.ibm.com>


More information about the vdsm-patches mailing list