Edward Haas has uploaded a new change for review.

Change subject: net: Consume ifcfg files that have a non vdsm standard name
......................................................................

net: Consume ifcfg files that have a non vdsm standard name

VDSM assumes that the ifcfg files which represent network devices are
named in the following format: ifcfg-<dev name>

If the host is set initially by Network Manager, the names of the files
do no correspond to the expected format.

This patch adjusts the ifcfg file name to the mentioned format and
erases any other ifcfg files that correspond to the same device.

Change-Id: I0bf70ba936d5de1f17a90742644719216018f674
TODO: Add functional tests.
Signed-off-by: Edward Haas <edwa...@redhat.com>
---
M lib/vdsm/network/configurators/ifcfg.py
1 file changed, 46 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/90/63990/1

diff --git a/lib/vdsm/network/configurators/ifcfg.py 
b/lib/vdsm/network/configurators/ifcfg.py
index 8eb681e..feefc53 100644
--- a/lib/vdsm/network/configurators/ifcfg.py
+++ b/lib/vdsm/network/configurators/ifcfg.py
@@ -108,6 +108,8 @@
             self.runningConfig = None
 
     def configureBridge(self, bridge, **opts):
+        if not self.owned_device(bridge.name):
+            self.normalize_device_filename(bridge.name)
         self.configApplier.addBridge(bridge, **opts)
         ifdown(bridge.name)
         if bridge.port:
@@ -116,12 +118,16 @@
         _ifup(bridge)
 
     def configureVlan(self, vlan, **opts):
+        if not self.owned_device(vlan.name):
+            self.normalize_device_filename(vlan.name)
         self.configApplier.addVlan(vlan, **opts)
         vlan.device.configure(**opts)
         self._addSourceRoute(vlan)
         _ifup(vlan)
 
     def configureBond(self, bond, **opts):
+        if not self.owned_device(bond.name):
+            self.normalize_device_filename(bond.name)
         self.configApplier.addBonding(bond, **opts)
         if not vlans.is_vlanned(bond.name):
             for slave in bond.slaves:
@@ -145,6 +151,9 @@
         nicsToSet = frozenset(nic.name for nic in bond.slaves)
         currentNics = frozenset(_netinfo.getNicsForBonding(bond.name))
         nicsToAdd = nicsToSet - currentNics
+
+        if not self.owned_device(bond.name):
+            self.normalize_device_filename(bond.name)
 
         # Create bond configuration in case it was a non ifcfg controlled bond.
         # Needed to be before slave configuration for initscripts to add slave
@@ -183,6 +192,8 @@
                             'switch': 'legacy'})
 
     def configureNic(self, nic, **opts):
+        if not self.owned_device(nic.name):
+            self.normalize_device_filename(nic.name)
         self.configApplier.addNic(nic, **opts)
         self._addSourceRoute(nic)
         if nic.bond is None:
@@ -191,6 +202,8 @@
             _ifup(nic)
 
     def removeBridge(self, bridge):
+        if not self.owned_device(bridge.name):
+            self.normalize_device_filename(bridge.name)
         DynamicSourceRoute.addInterfaceTracking(bridge)
         ifdown(bridge.name)
         self._removeSourceRoute(bridge, StaticSourceRoute)
@@ -200,6 +213,8 @@
             bridge.port.remove()
 
     def removeVlan(self, vlan):
+        if not self.owned_device(vlan.name):
+            self.normalize_device_filename(vlan.name)
         DynamicSourceRoute.addInterfaceTracking(vlan)
         ifdown(vlan.name)
         self._removeSourceRoute(vlan, StaticSourceRoute)
@@ -221,6 +236,8 @@
         DynamicSourceRoute.addInterfaceTracking(netEnt)
 
     def removeBond(self, bonding):
+        if not self.owned_device(bonding.name):
+            self.normalize_device_filename(bonding.name)
         to_be_removed = self._ifaceDownAndCleanup(bonding)
         if to_be_removed:
             self.configApplier.removeBonding(bonding.name)
@@ -245,6 +262,8 @@
                 ipwrapper.linkSet(bonding.name, ['mtu', str(set_mtu)])
 
     def removeNic(self, nic, remove_even_if_used=False):
+        if not self.owned_device(nic.name):
+            self.normalize_device_filename(nic.name)
         to_be_removed = self._ifaceDownAndCleanup(nic, remove_even_if_used)
         if to_be_removed:
             self.configApplier.removeNic(nic.name)
@@ -297,6 +316,33 @@
         else:
             return content.startswith(CONFFILE_HEADER_SIGNATURE)
 
+    @staticmethod
+    def normalize_device_filename(device):
+        """
+        Attempts to detect a device ifcfg file and rename it to a vdsm
+        supported format.
+        In case of multiple ifcfg files that treat the same device, all except
+        the first are deleted.
+        """
+        device_files = []
+        paths = glob.iglob(NET_CONF_PREF + '*')
+        for ifcfg_file in paths:
+            with open(ifcfg_file) as f:
+                for line in f:
+                    if line.startswith('#'):
+                        continue
+                    key, value = line.rstrip().split('=', 1)
+                    if value and value[0] == '\"' and value[-1] == '\"':
+                        value = value[1:-1]
+                    if key.upper() == 'DEVICE':
+                        if value == device:
+                            device_files.append(ifcfg_file)
+                        break
+        if device_files:
+            os.rename(device_files[0], NET_CONF_PREF + device)
+            for filepath in device_files[1:]:
+                utils.rmFile(filepath)
+
 
 class ConfigWriter(object):
     CONFFILE_HEADER = (CONFFILE_HEADER_SIGNATURE + ' ' +


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0bf70ba936d5de1f17a90742644719216018f674
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Edward Haas <edwa...@redhat.com>
_______________________________________________
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org

Reply via email to