Assaf Muller has uploaded a new change for review.

Change subject: Multiple Gateways: Use SourceRoute when adding/removing networks
......................................................................

Multiple Gateways: Use SourceRoute when adding/removing networks

- Created DHCP hook 'sourceRoute.sh'
  to be placed in /etc/dhcp/dhclient.d/sourceRoute.sh
- Modified spec file and Makefile to include the new hook file
  This doesn't work at this time. Will continue work later.
- Changed configNetwork to use SourceRoute, which then uses
  its configurator

Change-Id: Id4415c6ec91ac49c56703d59b99d3a21b328015b
Signed-off-by: Assaf Muller <amul...@redhat.com>
---
M vdsm.spec.in
M vdsm/Makefile.am
M vdsm/configNetwork.py
M vdsm/netconf/ifcfg.py
M vdsm/netconf/iproute2.py
A vdsm/sourceRoute.sh
6 files changed, 63 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/28/15528/1

diff --git a/vdsm.spec.in b/vdsm.spec.in
index ffa116e..4134968 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -918,6 +918,7 @@
 %{_datadir}/%{vdsm_name}/respawn
 %{_datadir}/%{vdsm_name}/sampling.py*
 %{_datadir}/%{vdsm_name}/set-conf-item
+%{_datadir}/%{vdsm_name}/sourceRouteDHCP.sh
 %if 0%{?with_gluster}
 %dir %{_datadir}/%{vdsm_name}/gluster
 %{_datadir}/%{vdsm_name}/gluster/__init__.py*
diff --git a/vdsm/Makefile.am b/vdsm/Makefile.am
index c528b41..dc61ce9 100644
--- a/vdsm/Makefile.am
+++ b/vdsm/Makefile.am
@@ -145,6 +145,7 @@
        chmod 775 $(DESTDIR)$(localstatedir)/lib/libvirt/qemu/channels
 
 install-data-local: \
+        install-data-dhclient-hooks
                install-data-libvirtpass \
                install-data-logger \
                install-data-logrotate \
@@ -166,6 +167,7 @@
        $(MKDIR_P) $(DESTDIR)$(localstatedir)/lib/libvirt/qemu/channels
 
 uninstall-local: \
+        uninstall-data-dhclient-hooks
                uninstall-data-libvirtpass \
                uninstall-data-logger \
                uninstall-data-logrotate \
@@ -238,5 +240,14 @@
        $(MKDIR_P) $(DESTDIR)$(sysconfdir)/sysctl.d
        $(INSTALL_DATA) $(srcdir)/vdsm-sysctl.conf \
                $(DESTDIR)$(sysconfdir)/sysctl.d/vdsm
+
 uninstall-data-sysctl:
        $(RM) $(DESTDIR)$(sysconfdir)/sysctl.d/vdsm
+
+install-data-dhclient-hooks:
+       $(MKDIR_P) $(DESTDIR)$(sysconfdir)/dhcp/dhclient.d
+       $(INSTALL_DATA) sourceRouteDHCP.sh \
+               $(DESTDIR)$(sysconfdir)/dhcp/dhclient.d/sourceRouteDHCP.sh
+
+uninstall-data-dhclient-hooks:
+       $(RM) $(DESTDIR)$(sysconfdir)/dhcp/dhclient.d/sourceRouteDHCP.sh
diff --git a/vdsm/configNetwork.py b/vdsm/configNetwork.py
index 0fef2a2..978826f 100755
--- a/vdsm/configNetwork.py
+++ b/vdsm/configNetwork.py
@@ -38,6 +38,7 @@
 from netmodels import IpConfig
 from netmodels import Nic
 from netmodels import Vlan
+from sourceRoute import SourceRoute
 
 CONNECTIVITY_TIMEOUT_DEFAULT = 4
 
@@ -196,6 +197,14 @@
                                 bondingOptions, nics, mtu, ipaddr, netmask,
                                 gateway, bootproto, _netinfo, configurator,
                                 **options)
+
+    # bootproto returns None for both static and no bootproto
+    if bootproto != 'dhcp':
+        sourceRoute = SourceRoute(netEnt.name, configurator)
+        logging.debug("Adding source route %s, %s, %s, %s" %
+                      (netEnt.name, ipaddr, netmask, gateway))
+        sourceRoute.configure(ipaddr, netmask, gateway)
+
     netEnt.configure(**options)
     configurator.configureLibvirtNetwork(network, netEnt)
 
@@ -275,6 +284,7 @@
                                     nics=nics, _netinfo=_netinfo,
                                     configurator=configurator,
                                     implicitBonding=False)
+        SourceRoute(netEnt.name, configurator).remove()
         netEnt.remove()
     else:
         raise ConfigNetworkError(ne.ERR_BAD_BRIDGE, "Cannot delete network"
@@ -321,6 +331,7 @@
                                 bonding=bonding, nics=nics, _netinfo=_netinfo,
                                 configurator=configurator,
                                 implicitBonding=implicitBonding)
+    SourceRoute(netEnt.name, configurator).remove()
     netEnt.remove()
 
 
diff --git a/vdsm/netconf/ifcfg.py b/vdsm/netconf/ifcfg.py
index 3bafcfb..378dab0 100644
--- a/vdsm/netconf/ifcfg.py
+++ b/vdsm/netconf/ifcfg.py
@@ -198,6 +198,31 @@
             if to_be_removed:
                 self.configWriter.removeNic(nic.name)
 
+    def _getFilePath(self, type, device):
+        return os.path.join(netinfo.NET_CONF_DIR, '%s-%s' % (type, device))
+
+    def _removeSourceRouteFile(self, type, device):
+        filePath = self._getFilePath(type, device)
+        self.configWriter._backup(filePath)
+        self.configWriter._removeFile(filePath)
+
+    def _writeConfFile(self, contents, type, device):
+        filePath = self._getFilePath(type, device)
+
+        configuration = ''
+        for entry in contents:
+            configuration += str(entry) + '\n'
+
+        self.configWriter.writeConfFile(filePath, configuration)
+
+    def configureSourceRoute(self, routes, rules, device):
+        self._writeConfFile(routes, 'route', device)
+        self._writeConfFile(rules, 'rule', device)
+
+    def removeSourceRoute(self, routes, rules, device):
+        self._removeSourceRouteFile('route', device)
+        self._removeSourceRouteFile('rule', device)
+
 
 class ConfigWriter(object):
     CONFFILE_HEADER = '# automatically generated by vdsm'
diff --git a/vdsm/netconf/iproute2.py b/vdsm/netconf/iproute2.py
index 7f8ad6e..a80e85a 100644
--- a/vdsm/netconf/iproute2.py
+++ b/vdsm/netconf/iproute2.py
@@ -22,16 +22,16 @@
 
 
 class Iproute2(object):
-    def configureSourceRoute(self, sourceRoute):
-        for route in sourceRoute.routes:
+    def configureSourceRoute(self, routes, rules, device):
+        for route in routes:
             ipwrapper.ipRouteAdd(route)
 
-        for rule in sourceRoute.rules:
+        for rule in rules:
             ipwrapper.ipRuleAdd(rule)
 
-    def removeSourceRoute(self, sourceRoute):
-        for route in sourceRoute.routes:
+    def removeSourceRoute(self, routes, rules, device):
+        for route in routes:
             ipwrapper.ipRouteDel(route)
 
-        for rule in sourceRoute.rules:
+        for rule in rules:
             ipwrapper.ipRuleDel(rule)
diff --git a/vdsm/sourceRoute.sh b/vdsm/sourceRoute.sh
new file mode 100755
index 0000000..db33793
--- /dev/null
+++ b/vdsm/sourceRoute.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+sourceRoute_config() {
+       python /usr/share/vdsm/sourceRoute.py "configure" "dhcp" 
$new_ip_address $new_subnet_mask $new_routers $interface
+}
+
+sourceRoute_restore() {
+       python /usr/share/vdsm/sourceRoute.py "remove" "dhcp" $interface
+}


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id4415c6ec91ac49c56703d59b99d3a21b328015b
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Assaf Muller <amul...@redhat.com>
_______________________________________________
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to