Change in vdsm[master]: sourceroute: remove removeSourceRoute in favour of remove_dy...

osvoboda at redhat.com osvoboda at redhat.com
Fri May 29 16:48:41 UTC 2015


Ondřej Svoboda has uploaded a new change for review.

Change subject: sourceroute: remove removeSourceRoute in favour of remove_dynamic_source_route
......................................................................

sourceroute: remove removeSourceRoute in favour of remove_dynamic_source_route

Change-Id: If36daa066879e6fd5f5d5e4e8dc14ac49a41a86b
Signed-off-by: Ondřej Svoboda <osvoboda at redhat.com>
---
M vdsm/network/configurators/__init__.py
M vdsm/network/configurators/ifcfg.py
M vdsm/network/configurators/iproute2.py
M vdsm/network/sourceroutethread.py
4 files changed, 41 insertions(+), 40 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/13/41613/1

diff --git a/vdsm/network/configurators/__init__.py b/vdsm/network/configurators/__init__.py
index 6462ad1..3eb96af 100644
--- a/vdsm/network/configurators/__init__.py
+++ b/vdsm/network/configurators/__init__.py
@@ -102,7 +102,7 @@
     def configureSourceRoute(self, source_route):
         raise NotImplementedError
 
-    def removeSourceRoute(self, source_route):
+    def remove_dynamic_source_route(self, device_name):
         raise NotImplementedError
 
     def configureLibvirtNetwork(self, network, iface):
diff --git a/vdsm/network/configurators/ifcfg.py b/vdsm/network/configurators/ifcfg.py
index ddf97a3..b896711 100644
--- a/vdsm/network/configurators/ifcfg.py
+++ b/vdsm/network/configurators/ifcfg.py
@@ -231,35 +231,16 @@
             if set_mtu is not None:
                 ipwrapper.linkSet(nic.name, ['mtu', str(set_mtu)])
 
-    def _getFilePath(self, fileType, device):
-        return os.path.join(netinfo.NET_CONF_DIR, '%s-%s' % (fileType, device))
-
-    def _removeSourceRouteFile(self, fileType, device):
-        filePath = self._getFilePath(fileType, device)
-        self.configApplier._backup(filePath)
-        self.configApplier._removeFile(filePath)
-
-    def _writeConfFile(self, contents, fileType, device):
-        filePath = self._getFilePath(fileType, device)
-
-        configuration = ''
-        for entry in contents:
-            configuration += str(entry) + '\n'
-
-        self.configApplier.writeConfFile(filePath, configuration)
-
     def configureSourceRoute(self, source_route):
-        self._writeConfFile(source_route.routes, 'route', source_route.device)
-        self._writeConfFile(source_route.rules, 'rule', source_route.device)
-
-    def removeSourceRoute(self, device):
-        logging.info('Removing source route for %s', device)
-        self._removeSourceRouteFile('rule', device)
-        self._removeSourceRouteFile('route', device)
+        self.configApplier.write_source_route_file(
+            source_route.routes, 'route', source_route.device)
+        self.configApplier.write_source_route_file(
+            source_route.rules, 'rule', source_route.device)
 
     def _remove_static_source_route(self, device):
         if device.ipv4.bootproto != 'dhcp' and device.master is None:
-            self.removeSourceRoute(device.name)
+            logging.info('Removing static source route for %s', device_name)
+            self.configApplier.remove_source_route(device.name)
 
     def flush(self):
         super(Ifcfg, self).flush()
@@ -764,6 +745,24 @@
         for slave in slaves:
             self.setIfaceMtu(slave, newmtu)
 
+    def write_source_route_file(self, contents, file_type, device_name):
+        file_path = self._get_file_path(file_type, device_name)
+        configuration = ''.join(str(entry) + '\n' for entry in contents)
+        self.writeConfFile(file_path, configuration)
+
+    def _get_file_path(self, file_type, device):
+        return os.path.join(netinfo.NET_CONF_DIR, '%s-%s' % (file_type,
+                                                             device_name))
+
+    def remove_source_route(self, device_name):
+        self._remove_source_route_file('rule', device_name)
+        self._remove_source_route_file('route', device_name)
+
+    def _remove_source_route_file(self, file_type, device_name):
+        file_path = self._get_file_path(file_type, device_name)
+        self._backup(file_path)
+        self._removeFile(file_path)
+
 
 def ifdown(iface):
     "Bring down an interface"
diff --git a/vdsm/network/configurators/iproute2.py b/vdsm/network/configurators/iproute2.py
index eb4d242..5f58369 100644
--- a/vdsm/network/configurators/iproute2.py
+++ b/vdsm/network/configurators/iproute2.py
@@ -209,20 +209,14 @@
             logging.error('Source route configuration failed: %s', e.message)
 
     @staticmethod
-    def removeSourceRoute(source_route):
-        logging.info('Removing source route for %s', source_route.device)
-        # Routes are removed automatically when the link goes down.
-        try:
-            for rule in source_route.rules:
-                ruleDel(rule)
-        except IPRoute2Error as e:
-            logging.error('Source route removal failed: %s' % e.message)
+    def remove_dynamic_source_route(device_name):
+        source_route = DynamicSourceRoute(device_name)
+        if source_route.prepare_removal():
+            ConfigApplier.remove_source_route(device_name, source_route.rules)
 
     def _remove_dynamic_source_route(self, device):
         if device.ipv4.bootproto != 'dhcp' and device.master is None:
-            source_route = DynamicSourceRoute(device.name)
-            if source_route.prepare_removal():
-                self.removeSourceRoute(source_route)
+            self.remove_dynamic_source_route(device.name)
 
 
 class ConfigApplier(object):
@@ -343,3 +337,13 @@
 
     def removeLibvirtNetwork(self, network):
         libvirt.removeNetwork(network)
+
+    @staticmethod
+    def remove_source_route(device_name, rules):
+        logging.info('Removing source route for %s', device_name)
+        # Routes are removed automatically when the link goes down.
+        try:
+            for rule in rules:
+                ruleDel(rule)
+        except IPRoute2Error as e:
+            logging.error('Source route removal failed: %s', e.message)
diff --git a/vdsm/network/sourceroutethread.py b/vdsm/network/sourceroutethread.py
index 08538a5..b672d2c 100644
--- a/vdsm/network/sourceroutethread.py
+++ b/vdsm/network/sourceroutethread.py
@@ -56,9 +56,7 @@
                         source_route.prepare_configuration()
                         configurator.configureSourceRoute(source_route)
                 else:
-                    source_route = DynamicSourceRoute(device)
-                    if source_route.prepare_removal():
-                        configurator.removeSourceRoute(source_route)
+                    configurator.remove_dynamic_source_route(device)
             else:
                 logging.info("interface %s is not a libvirt interface", device)
 


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If36daa066879e6fd5f5d5e4e8dc14ac49a41a86b
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Ondřej Svoboda <osvoboda at redhat.com>


More information about the vdsm-patches mailing list