Change in vdsm[ovirt-3.3]: Management network is now kept in main routing table

amuller at redhat.com amuller at redhat.com
Thu Aug 8 14:18:17 UTC 2013


Assaf Muller has uploaded a new change for review.

Change subject: Management network is now kept in main routing table
......................................................................

Management network is now kept in main routing table

Only the management network should add its default route
to the main routing table. Each NetDevice holds an IpConfig
instance who now holds defaultRoute='yes', 'no' or None.
Only the top level device will have a defaultRoute value.
When writing ifcfg files we check if we got a defaultRoute
value, if so we write it.

Patch Set 7 changed the implementation so that only the top
level device has DEFROUTE=yes/no in its ifcfg file.

Change-Id: I55c50269dd3d52fd058951200282c925a7014aca
Signed-off-by: Assaf Muller <amuller at redhat.com>
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=984028
---
M lib/vdsm/constants.py.in
M vdsm/configNetwork.py
M vdsm/netconf/__init__.py
M vdsm/netconf/ifcfg.py
M vdsm/netmodels.py
M vdsm/sourceRoute.py
6 files changed, 65 insertions(+), 33 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/44/17844/1

diff --git a/lib/vdsm/constants.py.in b/lib/vdsm/constants.py.in
index bbbb625..cfea347 100644
--- a/lib/vdsm/constants.py.in
+++ b/lib/vdsm/constants.py.in
@@ -22,6 +22,9 @@
 
 import os
 
+# VDSM management device
+MANAGEMENT_NETWORK = '@VDSMBRIDGE@'
+
 # SMBIOS manufacturer
 SMBIOS_MANUFACTURER = '@SMBIOS_MANUFACTURER@'
 SMBIOS_OSNAME = '@SMBIOS_OSNAME@'
diff --git a/vdsm/configNetwork.py b/vdsm/configNetwork.py
index fdb0b8f..155d22a 100755
--- a/vdsm/configNetwork.py
+++ b/vdsm/configNetwork.py
@@ -46,7 +46,7 @@
                        bondingOptions=None, nics=None, mtu=None, ipaddr=None,
                        netmask=None, gateway=None, bootproto=None,
                        _netinfo=None, configurator=None, blockingdhcp=None,
-                       implicitBonding=None, **opts):
+                       implicitBonding=None, defaultRoute=None, **opts):
     """
     Constructs an object hierarchy that describes the network configuration
     that is passed in the parameters.
@@ -66,6 +66,8 @@
     :param blockingdhcp: whether to acquire dhcp IP config in a synced manner.
     :param implicitBonding: whether the bond's existance is tied to it's
                             master's.
+    :param defaultRoute: Should this network's gateway be set in the main
+                         routing table?
 
     :returns: the top object of the hierarchy.
     """
@@ -101,7 +103,7 @@
     if topNetDev is None:
         raise ConfigNetworkError(ne.ERR_BAD_PARAMS, 'Network defined without'
                                  'devices.')
-    topNetDev.ip = IpConfig(inet=IPv4(ipaddr, netmask, gateway),
+    topNetDev.ip = IpConfig(inet=IPv4(ipaddr, netmask, gateway, defaultRoute),
                             bootproto=bootproto,
                             blocking=utils.tobool(blockingdhcp))
     return topNetDev
@@ -182,6 +184,7 @@
             for nic in nics:
                 _validateInterNetworkCompatibility(_netinfo, vlan, nic,
                                                    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,
@@ -192,10 +195,13 @@
 
     bootproto = options.pop('bootproto', None)
 
+    defaultRoute = network == constants.MANAGEMENT_NETWORK
+
     netEnt = objectivizeNetwork(network if bridged else None, vlan, bonding,
                                 bondingOptions, nics, mtu, ipaddr, netmask,
                                 gateway, bootproto, _netinfo, configurator,
-                                **options)
+                                defaultRoute=defaultRoute, **options)
+
     netEnt.configure(**options)
     configurator.configureLibvirtNetwork(network, netEnt,
                                          qosInbound=qosInbound,
diff --git a/vdsm/netconf/__init__.py b/vdsm/netconf/__init__.py
index c5227c2..d618522 100644
--- a/vdsm/netconf/__init__.py
+++ b/vdsm/netconf/__init__.py
@@ -81,7 +81,7 @@
         DynamicSourceRoute.addInterfaceTracking(netEnt)
 
     def _removeSourceRoute(self, netEnt):
-        _, _, _, bootproto, _ = netEnt.getIpConfig()
+        _, _, _, bootproto, _, _ = netEnt.getIpConfig()
         if bootproto != 'dhcp' and netEnt.master is None:
             logging.debug("Removing source route for device %s" % netEnt.name)
             StaticSourceRoute(netEnt.name, self).remove()
diff --git a/vdsm/netconf/ifcfg.py b/vdsm/netconf/ifcfg.py
index 140b538..a8872f9 100644
--- a/vdsm/netconf/ifcfg.py
+++ b/vdsm/netconf/ifcfg.py
@@ -61,7 +61,7 @@
             self._libvirtAdded = set()
 
     def configureBridge(self, bridge, **opts):
-        ipaddr, netmask, gateway, bootproto, async = bridge.getIpConfig()
+        ipaddr, netmask, gateway, bootproto, async, _ = bridge.getIpConfig()
         self.configApplier.addBridge(bridge, **opts)
         ifdown(bridge.name)
         if bridge.port:
@@ -70,14 +70,14 @@
         ifup(bridge.name, async)
 
     def configureVlan(self, vlan, **opts):
-        ipaddr, netmask, gateway, bootproto, async = vlan.getIpConfig()
+        ipaddr, netmask, gateway, bootproto, async, _ = vlan.getIpConfig()
         self.configApplier.addVlan(vlan, **opts)
         vlan.device.configure(**opts)
         self._addSourceRoute(vlan, ipaddr, netmask, gateway, bootproto)
         ifup(vlan.name, async)
 
     def configureBond(self, bond, **opts):
-        ipaddr, netmask, gateway, bootproto, async = bond.getIpConfig()
+        ipaddr, netmask, gateway, bootproto, async, _ = bond.getIpConfig()
         self.configApplier.addBonding(bond, **opts)
         if not netinfo.isVlanned(bond.name):
             for slave in bond.slaves:
@@ -97,7 +97,7 @@
         self.configureBond(bond)
 
     def configureNic(self, nic, **opts):
-        ipaddr, netmask, gateway, bootproto, async = nic.getIpConfig()
+        ipaddr, netmask, gateway, bootproto, async, _ = nic.getIpConfig()
         self.configApplier.addNic(nic, **opts)
         self._addSourceRoute(nic, ipaddr, netmask, gateway, bootproto)
         if nic.bond is None:
@@ -445,9 +445,15 @@
             logging.debug('ignoring restorecon error in case '
                           'SElinux is disabled', exc_info=True)
 
+    @staticmethod
+    def _toIfcfgFormat(defaultRoute):
+        if defaultRoute is None:
+            return None
+        return 'yes' if defaultRoute else 'no'
+
     def _createConfFile(self, conf, name, ipaddr=None, netmask=None,
-                        gateway=None, bootproto=None, mtu=None, onboot='yes',
-                        **kwargs):
+                        gateway=None, bootproto=None, mtu=None,
+                        defaultRoute=None, onboot='yes', **kwargs):
         """ Create ifcfg-* file with proper fields per device """
         cfg = self.CONFFILE_HEADER + '\n'
 
@@ -467,6 +473,8 @@
                 cfg = cfg + 'BOOTPROTO=%s\n' % pipes.quote(bootproto)
         if mtu:
             cfg = cfg + 'MTU=%d\n' % mtu
+        if defaultRoute:
+            cfg = cfg + 'DEFROUTE=%s\n' % defaultRoute
         cfg += 'NM_CONTROLLED=no\n'
         BLACKLIST = ['TYPE', 'NAME', 'DEVICE', 'bondingOptions',
                      'force', 'blockingdhcp',
@@ -482,20 +490,24 @@
 
     def addBridge(self, bridge, **opts):
         """ Create ifcfg-* file with proper fields for bridge """
-        ipaddr, netmask, gateway, bootproto, _ = bridge.getIpConfig()
+        ipaddr, netmask, gateway, bootproto, _, defaultRoute =\
+            bridge.getIpConfig()
         conf = 'TYPE=Bridge\nDELAY=%s\n' % bridge.forwardDelay
         self._createConfFile(conf, bridge.name, ipaddr, netmask, gateway,
-                             bootproto, bridge.mtu, **opts)
+                             bootproto, bridge.mtu,
+                             self._toIfcfgFormat(defaultRoute), **opts)
 
     def addVlan(self, vlan, **opts):
         """ Create ifcfg-* file with proper fields for VLAN """
-        ipaddr, netmask, gateway, bootproto, _ = vlan.getIpConfig()
+        ipaddr, netmask, gateway, bootproto, _, defaultRoute =\
+            vlan.getIpConfig()
         conf = 'VLAN=yes\n'
         if vlan.bridge:
             conf += 'BRIDGE=%s\n' % pipes.quote(vlan.bridge.name)
 
         self._createConfFile(conf, vlan.name, ipaddr, netmask, gateway,
-                             bootproto, vlan.mtu, **opts)
+                             bootproto, vlan.mtu,
+                             self._toIfcfgFormat(defaultRoute), **opts)
 
     def addBonding(self, bond, **opts):
         """ Create ifcfg-* file with proper fields for bond """
@@ -503,10 +515,10 @@
         if bond.bridge:
             conf += 'BRIDGE=%s\n' % pipes.quote(bond.bridge.name)
 
-        ipaddr, netmask, gateway, bootproto, mtu = \
+        ipaddr, netmask, gateway, bootproto, mtu, defaultRoute = \
             self._getIfaceConfValues(bond, netinfo.NetInfo())
         self._createConfFile(conf, bond.name, ipaddr, netmask, gateway,
-                             bootproto, mtu, **opts)
+                             bootproto, mtu, defaultRoute, **opts)
 
         # create the bonding device to avoid initscripts noise
         if bond.name not in open(netinfo.BONDING_MASTERS).read().split():
@@ -524,27 +536,31 @@
         if nic.bond:
             conf += 'MASTER=%s\nSLAVE=yes\n' % pipes.quote(nic.bond.name)
 
-        ipaddr, netmask, gateway, bootproto, mtu = \
+        ipaddr, netmask, gateway, bootproto, mtu, defaultRoute = \
             self._getIfaceConfValues(nic, _netinfo)
         self._createConfFile(conf, nic.name, ipaddr, netmask, gateway,
-                             bootproto, mtu, **opts)
+                             bootproto, mtu, defaultRoute, **opts)
 
     @staticmethod
     def _getIfaceConfValues(iface, _netinfo):
-        ipaddr, netmask, gateway, bootproto, _ = iface.getIpConfig()
+        ipaddr, netmask, gateway, bootproto, _, defaultRoute =\
+            iface.getIpConfig()
+        defaultRoute = ConfigWriter._toIfcfgFormat(defaultRoute)
         mtu = iface.mtu
         if _netinfo.ifaceUsers(iface.name):
             confParams = netinfo.getIfaceCfg(iface.name)
-            if not ipaddr and bootproto != 'dhcp':
-                ipaddr = confParams.get('IPADDR', None)
-                netmask = confParams.get('NETMASK', None)
-                gateway = confParams.get('GATEWAY', None)
-                bootproto = confParams.get('BOOTPROTO', None)
+            if not ipaddr:
+                if bootproto != 'dhcp':
+                    ipaddr = confParams.get('IPADDR', None)
+                    netmask = confParams.get('NETMASK', None)
+                    gateway = confParams.get('GATEWAY', None)
+                    bootproto = confParams.get('BOOTPROTO', None)
+                defaultRoute = confParams.get('DEFROUTE', None)
             if not iface.mtu:
                 mtu = confParams.get('MTU', None)
                 if mtu:
                     mtu = int(mtu)
-        return ipaddr, netmask, gateway, bootproto, mtu
+        return ipaddr, netmask, gateway, bootproto, mtu, defaultRoute
 
     def removeNic(self, nic):
         cf = netinfo.NET_CONF_PREF + nic
diff --git a/vdsm/netmodels.py b/vdsm/netmodels.py
index 6368e36..0d228d0 100644
--- a/vdsm/netmodels.py
+++ b/vdsm/netmodels.py
@@ -44,10 +44,12 @@
 
     def getIpConfig(self):
         try:
-            ipaddr, netmask, gateway, bootproto, async = self.ip.getConfig()
+            ipaddr, netmask, gateway, bootproto, async, defaultRoute =\
+                self.ip.getConfig()
         except AttributeError:
-            ipaddr = netmask = gateway = bootproto = async = None
-        return ipaddr, netmask, gateway, bootproto, async
+            ipaddr = netmask = gateway = bootproto = async = defaultRoute =\
+                None
+        return ipaddr, netmask, gateway, bootproto, async, defaultRoute
 
     @property
     def bridge(self):
@@ -260,7 +262,8 @@
 
 
 class IPv4(object):
-    def __init__(self, address=None, netmask=None, gateway=None):
+    def __init__(self, address=None, netmask=None, gateway=None,
+                 defaultRoute=None):
         if address:
             if not netmask:
                 raise ConfigNetworkError(ne.ERR_BAD_ADDR, 'Must specify '
@@ -277,9 +280,11 @@
         self.address = address
         self.netmask = netmask
         self.gateway = gateway
+        self.defaultRoute = defaultRoute
 
     def __repr__(self):
-        return 'IPv4(%s, %s, %s)' % (self.address, self.netmask, self.gateway)
+        return 'IPv4(%s, %s, %s, %s)' % (self.address, self.netmask,
+                                         self.gateway, self.defaultRoute)
 
     @classmethod
     def validateAddress(cls, address):
@@ -328,6 +333,8 @@
             ipaddr = self.inet.address
             netmask = self.inet.netmask
             gateway = self.inet.gateway
+            defaultRoute = self.inet.defaultRoute
         except AttributeError:
-            ipaddr = netmask = gateway = None
-        return ipaddr, netmask, gateway, self.bootproto, self.async
+            ipaddr = netmask = gateway = defaultRoute = None
+        return ipaddr, netmask, gateway, self.bootproto, self.async,\
+            defaultRoute
diff --git a/vdsm/sourceRoute.py b/vdsm/sourceRoute.py
index bed5cd0..c05d066 100644
--- a/vdsm/sourceRoute.py
+++ b/vdsm/sourceRoute.py
@@ -101,7 +101,7 @@
 
     @staticmethod
     def addInterfaceTracking(device):
-        _, _, _, bootproto, _ = device.getIpConfig()
+        _, _, _, bootproto, _, _ = device.getIpConfig()
         if bootproto == 'dhcp':
             open(DynamicSourceRoute.getTrackingFilePath(device.name), 'a').\
                 close()


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I55c50269dd3d52fd058951200282c925a7014aca
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.3
Gerrit-Owner: Assaf Muller <amuller at redhat.com>


More information about the vdsm-patches mailing list