[PATCH 1/3 master/newui] Write default ifcfg files in dracut not in anaconda.

Radek Vykydal rvykydal at redhat.com
Wed Jul 11 12:51:40 UTC 2012


Default ifcfg files used to be written in loader.
We need to write them before systemd runs NM so that we control which
devices are brought up. NM activates default connections for devices
with missing ifcfg files.
This should also fix newui traceback caused by missing ifcfg files
because Network class is not instantiated in some cases.
---
 dracut/anaconda-write-default-ifcfg.sh |   20 ++++++++++++++++++++
 dracut/module-setup.sh                 |    1 +
 pyanaconda/network.py                  |   27 +++------------------------
 3 files changed, 24 insertions(+), 24 deletions(-)
 create mode 100755 dracut/anaconda-write-default-ifcfg.sh

diff --git a/dracut/anaconda-write-default-ifcfg.sh b/dracut/anaconda-write-default-ifcfg.sh
new file mode 100755
index 0000000..e51de25
--- /dev/null
+++ b/dracut/anaconda-write-default-ifcfg.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
+# ex: ts=8 sw=4 sts=4 et filetype=sh
+
+for interface in /sys/class/net/*; do
+
+    ifname=${interface##*/}
+
+    if [ ! -e /run/initramfs/state/etc/sysconfig/network-scripts/ifcfg-$ifname ]; then
+        {
+            echo "# Generated by anconda dracut initrd module"
+            echo "DEVICE=$ifname"
+            echo "BOOTPROTO=dhcp"
+            echo "ONBOOT=no"
+            echo "HWADDR=$(cat /sys/class/net/$ifname/address)"
+            echo "UUID=$(cat /proc/sys/kernel/random/uuid)"
+        } > /run/initramfs/state/etc/sysconfig/network-scripts/ifcfg-$ifname
+    fi
+
+done
diff --git a/dracut/module-setup.sh b/dracut/module-setup.sh
index 39ecc58..227b3de 100755
--- a/dracut/module-setup.sh
+++ b/dracut/module-setup.sh
@@ -28,6 +28,7 @@ install() {
     inst_hook pre-trigger 40 "$moddir/anaconda-udevprop.sh"
     inst_hook initqueue/online 80 "$moddir/anaconda-netroot.sh"
     inst "$moddir/anaconda-diskroot" "/sbin/anaconda-diskroot"
+    inst_hook pre-pivot 90 "$moddir/anaconda-write-default-ifcfg.sh"
     inst_hook pre-pivot 99 "$moddir/anaconda-copy-ks.sh"
     # kickstart parsing, WOOOO
     inst_hook initqueue/online 10 "$moddir/fetch-kickstart-net.sh"
diff --git a/pyanaconda/network.py b/pyanaconda/network.py
index 103816e..984663b 100644
--- a/pyanaconda/network.py
+++ b/pyanaconda/network.py
@@ -242,29 +242,6 @@ class NetworkDevice(IfcfgFile):
 
         return s
 
-    # anaconda doesn't actually need this configuration, but if we don't write
-    # it to the installed system then 'ifup' doesn't work after install.
-    # FIXME: make 'ifup' use its own defaults!
-    def setDefaultConfig(self):
-        ifcfglog.debug("NetworkDevice %s: setDefaultConfig()" % self.iface)
-        self.set(("DEVICE", self.iface),
-                 ("BOOTPROTO", "dhcp"),
-                 ("ONBOOT", "no")) # for "security", or something
-
-        try:
-            mac = open("/sys/class/net/%s/address" % self.iface).read().strip()
-            self.set(("HWADDR", mac.upper()))
-        except IOError as e:
-            ifcfglog.warning("HWADDR: %s" % str(e))
-
-        try:
-            uuid = open("/proc/sys/kernel/random/uuid").read().strip()
-            self.set(("UUID", uuid))
-        except IOError as e:
-            ifcfglog.warning("UUID: %s" % str(e))
-
-        self.writeIfcfgFile()
-
     def loadIfcfgFile(self):
         ifcfglog.debug("%s:\n%s" % (self.path, self.fileContent()))
         ifcfglog.debug("NetworkDevice %s:\n%s" % (self.iface, self.__str__()))
@@ -440,7 +417,9 @@ class Network:
                 if os.access(device.path, os.R_OK):
                     device.loadIfcfgFile()
                 else:
-                    device.setDefaultConfig()
+                    log.info("Network.update(): %s file not found" %
+                             device.path)
+                    continue
 
             # TODORV - the last iface in loop wins, might be ok,
             #          not worthy of special juggling
-- 
1.7.4



More information about the anaconda-patches mailing list