[PATCH master] Dump default auto connection's ifcfg file instead of writing a new one (#870922)

Radek Vykydal rvykydal at redhat.com
Thu Nov 8 15:58:36 UTC 2012


The case:
1) Dracut does not use network so it does not write any ifcfg file
   (e.g. DVD install)
2) NM creates default auto connection (DHCP) because it can't find
   any ifcfg file for a device.
3) Anaconda writes out default ifcfg file (e.g. ifcfg-eth0)
4) When editing a connection in nm-c-e, ifcfg file of edited default
   auto connection (Wired connection 1) is created
   (ifcfg-Wired_connection_1).
5) If anaconda tweaks any ifcfg file later (setting ONBOOT, NM_CONTROLLED),
   it is the ifcfg-eth0.
6) Both ifcfg files are copied to the target system at the end of
   installation

Luckily, the ifcfg-Wired_connection_1 seems to be used after installation,
but bug #870922 suggests it might be not so in all cases.
Anyway, we shouldn't create anaconda's ifcfg-ethX default file in this case.
---
 pyanaconda/isys/__init__.py |    1 +
 pyanaconda/network.py       |   40 +++++++++++++++++++++++++++++++++++-----
 2 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/pyanaconda/isys/__init__.py b/pyanaconda/isys/__init__.py
index ca72438..f14eab6 100755
--- a/pyanaconda/isys/__init__.py
+++ b/pyanaconda/isys/__init__.py
@@ -48,6 +48,7 @@ log = logging.getLogger("anaconda")
 
 NM_SERVICE = "org.freedesktop.NetworkManager"
 NM_MANAGER_PATH = "/org/freedesktop/NetworkManager"
+NM_SETTINGS_PATH = "/org/freedesktop/NetworkManager/Settings"
 NM_MANAGER_IFACE = "org.freedesktop.NetworkManager"
 NM_ACTIVE_CONNECTION_IFACE = "org.freedesktop.NetworkManager.Connection.Active"
 NM_CONNECTION_IFACE = "org.freedesktop.NetworkManager.Settings.Connection"
diff --git a/pyanaconda/network.py b/pyanaconda/network.py
index b4f3b16..dbdf5df 100644
--- a/pyanaconda/network.py
+++ b/pyanaconda/network.py
@@ -419,12 +419,42 @@ class WirelessNetworkDevice(NetworkDevice):
     def write(self):
         pass
 
+def get_NM_object(path):
+    return dbus.SystemBus().get_object(isys.NM_SERVICE, path)
+
+# Handle default auto connections created by NM upon start
+# For server, those will be turned off in NetworkManager.conf
 def createMissingDefaultIfcfgs():
-    for iface in getDevices():
-        if not isys.isWirelessDevice(iface):
-            device = NetworkDevice(netscriptsDir, iface)
-            if not os.access(device.path, os.R_OK):
-                device.setDefaultConfig()
+    nm = get_NM_object(isys.NM_MANAGER_PATH)
+    dev_paths = nm.GetDevices()
+    settings = get_NM_object(isys.NM_SETTINGS_PATH)
+    con_paths = settings.ListConnections()
+    for devpath in dev_paths:
+        device = get_NM_object(devpath)
+        device_props_iface = dbus.Interface(device, isys.DBUS_PROPS_IFACE)
+        devicetype = device_props_iface.Get(isys.NM_DEVICE_IFACE, "DeviceType")
+        if devicetype == isys.NM_DEVICE_TYPE_WIFI:
+            continue
+        # if there is no ifcfg file for the device
+        interface = str(device_props_iface.Get(isys.NM_DEVICE_IFACE, "Interface"))
+        device_cfg = NetworkDevice(netscriptsDir, interface)
+        if os.access(device_cfg.path, os.R_OK):
+            continue
+        # check if there is a connection for the device (default autoconnection)
+        hwaddr = device_props_iface.Get(isys.NM_DEVICE_WIRED_IFACE, "HwAddress")
+        for con_path in con_paths:
+            con = get_NM_object(con_path)
+            setting = con.GetSettings()
+            con_hwaddr = ":".join("%02X" % byte for byte in
+                                  setting['802-3-ethernet']['mac-address'])
+            # if so, write its configuration with name changed to iface
+            if con_hwaddr.upper() == hwaddr.upper():
+                setting['connection']['id'] = interface
+                con.Update(setting)
+                break
+        else:
+            # if there is no connection, create default ifcfg
+            device_cfg.setDefaultConfig()
 
 def getDevices():
     # TODO: filter with existence of ifcfg file?
-- 
1.7.4



More information about the anaconda-patches mailing list