Assaf Muller has uploaded a new change for review.

Change subject: Extend setupNetworks API to accept defaultRoute
......................................................................

Extend setupNetworks API to accept defaultRoute

Previously defaultRoute was True for the management network,
now it is received from the client.

Change-Id: I9b2ff711155eb0bd79ab84e979eb82c846362374
Bug-Url: https://bugzilla.redhat.com/1015009
Signed-off-by: Assaf Muller <[email protected]>
---
M lib/vdsm/tool/unified_persistence.py
M vdsm/configNetwork.py
M vdsm_api/vdsmapi-schema.json
3 files changed, 31 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/20/22720/1

diff --git a/lib/vdsm/tool/unified_persistence.py 
b/lib/vdsm/tool/unified_persistence.py
index d1b3d0a..b412915 100644
--- a/lib/vdsm/tool/unified_persistence.py
+++ b/lib/vdsm/tool/unified_persistence.py
@@ -37,14 +37,26 @@
     _persist(networks, bondings)
 
 
-def _toIfcfgFormat(value):
-    filter = {'on': 'yes', 'off': 'no'}
-    # If value is in the dict and hashable - Get its filtered value.
-    # Otherwise: Return the original value
+def _ifcfgFilter(filter, value):
+    """
+    If value is in the dict and hashable - Get its filtered value.
+    Otherwise: Return the original value
+    :param filter: Dictionary of 'from' -> 'to'
+    :param value: The value to filter
+    :return: Filtered value
+    """
     try:
         return filter.get(value, value)
     except TypeError:
         return value
+
+
+def _toIfcfgFormat(value):
+    return _ifcfgFilter({'on': 'yes', 'off': 'no'}, value)
+
+
+def _fromIfcfgFormat(value):
+    return _ifcfgFilter({'yes': True, 'no': False}, value)
 
 
 def _getNetInfo():
@@ -72,7 +84,8 @@
                 netParams['bridged'] else physicalDevice
 
             # Copy ip addressing information
-            bootproto = str(getIfaceCfg(topLevelDevice).get('BOOTPROTO'))
+            ifcfg = getIfaceCfg(topLevelDevice)
+            bootproto = str(ifcfg.get('BOOTPROTO'))
             if bootproto == 'dhcp':
                 networks[network]['bootproto'] = bootproto
             else:
@@ -83,6 +96,9 @@
                 if netParams['gateway'] != '':
                     networks[network]['gateway'] = netParams['gateway']
 
+            networks[network]['defaultRoute'] = _fromIfcfgFormat(
+                ifcfg.get('DEFROUTE', False))
+
             # What if the 'physical device' is actually a VLAN?
             if physicalDevice in netinfo.vlans:
                 vlanDevice = physicalDevice
diff --git a/vdsm/configNetwork.py b/vdsm/configNetwork.py
index 5db2a41..e928740 100755
--- a/vdsm/configNetwork.py
+++ b/vdsm/configNetwork.py
@@ -210,7 +210,8 @@
                netmask=None, prefix=None, mtu=None, gateway=None,
                ipv6addr=None, ipv6gateway=None, force=False,
                configurator=None, bondingOptions=None, bridged=True,
-               _netinfo=None, qosInbound=None, qosOutbound=None, **options):
+               _netinfo=None, qosInbound=None, qosOutbound=None,
+               defaultRoute=False, **options):
     nics = nics or ()
     if _netinfo is None:
         _netinfo = netinfo.NetInfo()
@@ -245,16 +246,14 @@
                                                    bridged)
 
     logging.info("Adding network %s with vlan=%s, bonding=%s, nics=%s,"
-                 " bondingOptions=%s, mtu=%s, bridged=%s, options=%s",
-                 network, vlan, bonding, nics, bondingOptions,
-                 mtu, bridged, options)
+                 " bondingOptions=%s, mtu=%s, bridged=%s, defaultRoute=%s,"
+                 "options=%s", network, vlan, bonding, nics, bondingOptions,
+                 mtu, bridged, defaultRoute, options)
 
     if configurator is None:
         configurator = Ifcfg()
 
     bootproto = options.pop('bootproto', None)
-
-    defaultRoute = network == constants.MANAGEMENT_NETWORK
 
     netEnt = objectivizeNetwork(network if bridged else None, vlan, bonding,
                                 bondingOptions, nics, mtu, ipaddr, netmask,
@@ -527,6 +526,7 @@
                         ipv6gateway="<ipv6>"
                         ipv6autoconf="0|1"
                         dhcpv6="0|1"
+                        defaultRoute=True|False
                         (other options will be passed to the config file AS-IS)
                         -- OR --
                         remove=True (other attributes can't be specified)
diff --git a/vdsm_api/vdsmapi-schema.json b/vdsm_api/vdsmapi-schema.json
index ce9204f..64e5613 100644
--- a/vdsm_api/vdsmapi-schema.json
+++ b/vdsm_api/vdsmapi-schema.json
@@ -164,6 +164,9 @@
 #
 # @qosOutbound:   #optional BandwidthParams for outgoing traffic.
 #
+# @defaultRoute:  #optional boolean - Is this network's gateway the host's
+#                 default gateway?
+#
 # Since: 4.10.0
 ##
 {'type': 'SetupNetworkNetAttributes',
@@ -171,7 +174,7 @@
           '*netmask': 'str', '*gateway': 'str', '*bootproto': 'str',
           '*remove': 'bool',
           '*qosInbound': 'BandwidthParams',
-          '*qosOutbound': 'BandwidthParams'}}
+          '*qosOutbound': 'BandwidthParams', '*defaultRoute': 'bool'}}
 ##
 # @SetupNetworkBondAttributes:
 #


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

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

Reply via email to