[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[PATCH f17-branch 2/2] dracut/parse-kickstart: handle network --device=link (or none)



If you have a kickstart where your first network line has no device (or
--device=link), we won't have a valid net.device ("" or "link",
respectively.) Still a valid kickstart though, so we need to generate
correct dracut args for that case.

Also we need to set rd.neednet so the device always goes online in
dracut (matching loader's behavior).

This means we don't need to write ifcfg if net.device is empty:
1) empty 'net.device' is only valid for the first device,
2) first device always comes online,
3) online devices get ifcfg written by dracut.

(It also means we don't need to touch /tmp/net.ifaces, since that happens
in step 3.)
---
 dracut/parse-kickstart |   34 ++++++++++++++++++++--------------
 1 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/dracut/parse-kickstart b/dracut/parse-kickstart
index d33394e..214d123 100755
--- a/dracut/parse-kickstart
+++ b/dracut/parse-kickstart
@@ -70,19 +70,17 @@ class Network(commands.network.F16_Network):
     def dracut_args(self, args, lineno, net):
         if len(self.network) == 1: # first network line gets special treatment
             net.activate = True      # activate by default
-            if not net.device:       # --device is optional, defaults to..
-                net.device = self.handler.ksdevice # kickstart device, if any
-        if not net.device:
+            # --device is optional, defaults to ksdevice
+            if net.device == "link" or not net.device:
+                net.device = self.handler.ksdevice # might be empty (ks=file:)
+        elif not net.device:
+            # every other network line needs a --device (and not "link")
             log.error("'%s': missing --device", " ".join(args))
         # write ifcfg for all listed devices
         ksnet_to_ifcfg(net)
-        # make sure /tmp/net.ifaces exists so dracut will copy them over
-        if not os.path.exists("/tmp/net.ifaces"):
-            open("/tmp/net.ifaces", "w")
         # anaconda tradition: bring up the first device listed, and no others
         if len(self.network) == 1:
-            netline = ksnet_to_dracut(args, lineno, net)
-            netline += " bootdev=%s" % net.device
+            netline = ksnet_to_dracut(args, lineno, net, bootdev=True)
             return netline
 
 # TODO: keymap, lang... device? upgrade? selinux?
@@ -137,13 +135,14 @@ def init_logger():
         pass
     return logger
 
-def ksnet_to_dracut(args, lineno, net):
+def ksnet_to_dracut(args, lineno, net, bootdev=False):
     '''Translate the kickstart network data into dracut network data.'''
     line = []
+    dev = net.device
     if net.bootProto in (BOOTPROTO_DHCP, BOOTPROTO_BOOTP):
-        line.append("ip=%s:dhcp" % net.device)
+        line.append("ip=%s:dhcp" % dev if dev else "ip=dhcp")
     elif net.bootProto == BOOTPROTO_IBFT:
-        line.append("ip=%s:ibft" % net.device)
+        line.append("ip=%s:ibft" % dev if dev else "ip=ibft")
     elif net.bootProto == BOOTPROTO_QUERY:
         log.error("'%s': --bootproto=query is deprecated", " ".join(args))
     elif net.bootProto == BOOTPROTO_STATIC:
@@ -158,20 +157,25 @@ def ksnet_to_dracut(args, lineno, net):
             line.append("nameserver=%s" % ns)
 
     if net.ipv6 == "auto":
-        line.append("ip=%s:auto6" % net.device)
+        line.append("ip=%s:auto6" % dev if dev else "ip=auto6")
     elif net.ipv6 == "dhcp":
-        line.append("ip=%s:dhcp6" % net.device)
+        line.append("ip=%s:dhcp6" % dev if dev else "ip=dhcp6")
     elif net.ipv6:
         line.append("ip=[{0.ipv6}]::{0.gateway}:{0.netmask}:" \
                     "{0.hostname}:{0.device}".format(net))
 
     if net.mtu:
         # XXX FIXME: dracut doesn't support mtu= (yet)
-        line.append("mtu=%s:%u" % (net.device, net.mtu))
+        line.append("mtu=%s:%u" % (dev, net.mtu) if dev else "mtu=%u" % net.mtu)
     # TODO: nodefroute, noipv[46], nodns: pass along to 'ifcfg' module somehow
     # TODO FIXME dhcpclass: dracut only uses one dhclient.conf for all ifaces
     # so we can't (yet) have per-interface dhcpclass
 
+    if bootdev:
+        if dev:
+            line.append("bootdev=%s" % dev)
+        line.append("rd.neednet=1")
+
     if net.essid or net.wepkey or net.wpakey:
         # TODO: make dracut support wireless? (do we care?)
         log.error("'%s': dracut doesn't support wireless networks",
@@ -187,6 +191,8 @@ def readfile(f):
 
 def ksnet_to_ifcfg(net, filename=None):
     '''Write an ifcfg file for the given kickstart network config'''
+    if not net.device:
+        return
     ifcfg = dict()
     if filename is None:
         filename = "/tmp/ifcfg/ifcfg-%s" % net.device
-- 
1.7.7.6


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]