Change in vdsm[master]: Source Routing upgrade script

amuller at redhat.com amuller at redhat.com
Tue Aug 6 20:14:17 UTC 2013


Assaf Muller has uploaded a new change for review.

Change subject: Source Routing upgrade script
......................................................................

Source Routing upgrade script

This upgrade script configures:
1) Management network gateway as the host's default gateway
2) Source routing on every VDSM controlled device
3) defroute=yes in the management network ifcfg file,
   defroute=no in every other VDSM controlled ifcfg file

Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=990854
Change-Id: I051b0f168b6357e60184409845ea410c5891b082
Signed-off-by: Assaf Muller <amuller at redhat.com>
---
M vdsm.spec.in
M vdsm/upgrade/Makefile.am
A vdsm/upgrade/multipleGateways.py
M vdsm/vdsmd.init.in
4 files changed, 99 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/27/17727/1

diff --git a/vdsm.spec.in b/vdsm.spec.in
index 4389575..d8ac9c3 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -966,6 +966,7 @@
 %{_datadir}/%{vdsm_name}/set-conf-item
 %dir %{_datadir}/%{vdsm_name}/upgrade
 %{_datadir}/%{vdsm_name}/upgrade/upgrade.py*
+%{_datadir}/%{vdsm_name}/upgrade/multipleGateways.py*
 %if 0%{?with_gluster}
 %dir %{_datadir}/%{vdsm_name}/gluster
 %{_datadir}/%{vdsm_name}/gluster/__init__.py*
diff --git a/vdsm/upgrade/Makefile.am b/vdsm/upgrade/Makefile.am
index 014864a..2957318 100644
--- a/vdsm/upgrade/Makefile.am
+++ b/vdsm/upgrade/Makefile.am
@@ -23,4 +23,6 @@
 upgradedir = $(vdsmdir)/upgrade
 
 dist_upgrade_PYTHON = \
-	upgrade.py
+	upgrade.py \
+	multipleGateways.py
+
diff --git a/vdsm/upgrade/multipleGateways.py b/vdsm/upgrade/multipleGateways.py
new file mode 100755
index 0000000..a089546
--- /dev/null
+++ b/vdsm/upgrade/multipleGateways.py
@@ -0,0 +1,93 @@
+#! /usr/bin/python
+# Copyright 2013 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+import sys
+sys.path.append("/usr/share/vdsm")
+
+from upgrade import Upgrade
+from vdsm.constants import MANAGEMENT_NETWORK
+from vdsm import netinfo
+from vdsm import ipwrapper
+from netconf.ifcfg import Ifcfg
+from netconf.iproute2 import Iproute2
+from sourceRoute import StaticSourceRoute
+from sourceRoute import DynamicSourceRoute
+
+
+class SourceRoute(Upgrade):
+    def run(self):
+        '''
+        1) Ensure that the ovirtmgmt gateway is the host default gateway
+        For every VDMS controlled device:
+            2) Configure source routing
+            3) Append DEFROUTE=yes for ifcfg-ovirtmgmt, DEFROUTE=no for the rest
+               of the devices
+        '''
+        _netinfo = netinfo.NetInfo()
+
+        #1
+        managementGateway = netinfo.getGateway(MANAGEMENT_NETWORK)
+        if managementGateway != '0.0.0.0':
+            ipwrapper.routeDel(["default"])
+            defaultRoute = ipwrapper.Route(network='0.0.0.0/0',
+                                           ipaddr=managementGateway,
+                                           device=MANAGEMENT_NETWORK)
+            ipwrapper.routeAdd(defaultRoute)
+
+        vdsmNetworks = _netinfo.networks
+        for network, attributes in vdsmNetworks.iteritems():
+            # 2
+            device = attributes['iface']
+            bootproto = netinfo.getBootProtocol(device)
+            if bootproto == 'dhcp':
+                sourceRoute = DynamicSourceRoute(device, Iproute2())
+            else:
+                sourceRoute = StaticSourceRoute(device, Ifcfg())
+
+            sourceRoute.configure(attributes['addr'], attributes['netmask'],
+                                  netinfo.getGateway(device))
+
+            # Ifcfg configurator only writes the route and rule files,
+            # since this upgrade doesn't ifdown and then ifup the device,
+            # the files won't get used and so we need to additionally
+            # add the routes and rules via the Iproute2 configurator.
+            # The route/rule files will be used henceforth on every ifup
+            # and ifdown.
+            if bootproto == 'none':
+                try:
+                    Iproute2.configureSourceRoute(sourceRoute.routes,
+                                                  sourceRoute.rules, device)
+                except ipwrapper.IPRoute2Error as e:
+                    self.log.error('ip binary failed during source route'
+                                   'configuration: %s' % e.message)
+
+            # 3
+            ifcfgPath = netinfo.NET_CONF_DIR + 'ifcfg-' + device
+            defroute = 'yes' if network == MANAGEMENT_NETWORK else 'no'
+            with open(ifcfgPath, 'a') as ifcfgFile:
+                ifcfgFile.write("DEFROUTE=%s\n" % defroute)
+
+
+def main():
+    SourceRoute().runIfNeeded()
+
+
+if __name__ == "__main__":
+    main()
diff --git a/vdsm/vdsmd.init.in b/vdsm/vdsmd.init.in
index 56f07bd..bd0dbb0 100755
--- a/vdsm/vdsmd.init.in
+++ b/vdsm/vdsmd.init.in
@@ -246,6 +246,8 @@
         return 1
     fi
 
+    "@PYTHON@"
+
     echo $"Starting up vdsm daemon: "
     local vdsm_nice="$("${GETCONFITEM}" "${CONF_FILE}" vars vdsm_nice -5)"
 


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

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


More information about the vdsm-patches mailing list