Change in vdsm[master]: net: removing the bonding modes constant duplication.

ibarkan at redhat.com ibarkan at redhat.com
Wed Nov 25 13:09:58 UTC 2015


Ido Barkan has uploaded a new change for review.

Change subject: net: removing the bonding modes constant duplication.
......................................................................

net: removing the bonding modes constant duplication.

Now, after everybody can use netinfo, this duplicated constant can be
merged.

Change-Id: Ia6682c7294f5afb8d50a30c6bd0431d85bbd159d
Signed-off-by: Ido Barkan <ibarkan at redhat.com>
---
M lib/vdsm/kernelconfig.py
M lib/vdsm/netinfo.py
M vdsm/network/configurators/ifcfg.py
M vdsm/network/models.py
4 files changed, 17 insertions(+), 32 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/70/49170/1

diff --git a/lib/vdsm/kernelconfig.py b/lib/vdsm/kernelconfig.py
index a212c5c..b3a10ee 100644
--- a/lib/vdsm/kernelconfig.py
+++ b/lib/vdsm/kernelconfig.py
@@ -26,13 +26,6 @@
 from . import utils
 from .netconfpersistence import BaseConfig
 
-_BONDING_MODES = {
-    # TODO: this dictionary and the reverse mapping are duplicated in code
-    '0': 'balance-rr', '1': 'active-backup', '2': 'balance-xor',
-    '3': 'broadcast', '4': '802.3ad', '5': 'balance-tlb', '6': 'balance-alb'
-}
-_BONDING_MODES_REVERSED = dict((v, k) for k, v in _BONDING_MODES.iteritems())
-
 
 class KernelConfig(BaseConfig):
     # TODO: after the netinfo API is refactored, we should decide if we need
@@ -284,10 +277,10 @@
     # force a numeric bonding mode
     mode = opts.get('mode',
                     netinfo.getAllDefaultBondingOptions()['0']['mode'][-1])
-    if mode in _BONDING_MODES:
+    if mode in netinfo.BONDING_MODES_NUMBER_TO_NAME:
         numeric_mode = mode
     else:
-        numeric_mode = _BONDING_MODES_REVERSED[mode]
+        numeric_mode = netinfo.BONDING_MODES_NAME_TO_NUMBER[mode]
         opts['mode'] = numeric_mode
 
     defaults = netinfo.getDefaultBondingOptions(numeric_mode)
diff --git a/lib/vdsm/netinfo.py b/lib/vdsm/netinfo.py
index 8a36a40..ffb205a 100644
--- a/lib/vdsm/netinfo.py
+++ b/lib/vdsm/netinfo.py
@@ -89,6 +89,18 @@
 OPERSTATE_DOWN = 'down'
 DUMMY_BRIDGE  # Appease flake8 since dummy bridge should be exported from here
 
+BONDING_MODES_NAME_TO_NUMBER = {
+    'balance-rr': '0',
+    'active-backup': '1',
+    'balance-xor': '2',
+    'broadcast': '3',
+    '802.3ad': '4',
+    'balance-tlb': '5',
+    'balance-alb': '6',
+}
+BONDING_MODES_NUMBER_TO_NAME = dict(
+    (v, k) for k, v in BONDING_MODES_NAME_TO_NUMBER.iteritems())
+
 
 def get_host_nameservers():
     """Returns a list of nameservers listed in /etc/resolv.conf"""
diff --git a/vdsm/network/configurators/ifcfg.py b/vdsm/network/configurators/ifcfg.py
index 99b16a9..f0a7c33 100644
--- a/vdsm/network/configurators/ifcfg.py
+++ b/vdsm/network/configurators/ifcfg.py
@@ -847,18 +847,8 @@
     if 'mode' not in desired_options:
         return None
 
-    MODE_NAME_TO_NUMBER = {
-        'balance-rr': '0',
-        'active-backup': '1',
-        'balance-xor': '2',
-        'broadcast': '3',
-        '802.3ad': '4',
-        'balance-tlb': '5',
-        'balance-alb': '6',
-    }
-
     desired_mode = desired_options['mode']
-    for k, v in MODE_NAME_TO_NUMBER.iteritems():
+    for k, v in netinfo.BONDING_MODES_NAME_TO_NUMBER.iteritems():
         if desired_mode in (k, v):
             return [k, v]
     raise Exception('Error translating bond mode.')
diff --git a/vdsm/network/models.py b/vdsm/network/models.py
index a0012d2..7c6993c 100644
--- a/vdsm/network/models.py
+++ b/vdsm/network/models.py
@@ -320,18 +320,8 @@
             raise ConfigNetworkError(ne.ERR_BAD_BONDING, 'Error parsing '
                                      'bonding options: %r' % bondingOptions)
 
-        MODE_NAME_TO_NUMBER = {
-            'balance-rr': '0',
-            'active-backup': '1',
-            'balance-xor': '2',
-            'broadcast': '3',
-            '802.3ad': '4',
-            'balance-tlb': '5',
-            'balance-alb': '6',
-        }
-
-        if mode in MODE_NAME_TO_NUMBER:
-            mode = MODE_NAME_TO_NUMBER[mode]
+        if mode in netinfo.BONDING_MODES_NAME_TO_NUMBER:
+            mode = netinfo.BONDING_MODES_NAME_TO_NUMBER[mode]
         defaults = netinfo.getDefaultBondingOptions(mode)
 
         for option in bondingOptions.split():


-- 
To view, visit https://gerrit.ovirt.org/49170
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia6682c7294f5afb8d50a30c6bd0431d85bbd159d
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Ido Barkan <ibarkan at redhat.com>


More information about the vdsm-patches mailing list