[PATCH 4/5] ksnet_to_dracut: cleanups (autoconf vs. static, formatting)

Will Woods wwoods at redhat.com
Wed Aug 29 18:07:16 UTC 2012


Since dracut allows simpler forms of the "ip=.." arg for autoconf, it
makes sense to handle autoconf and static IP config differently. But
it's kind of tricky to figure out which form the emitted argument is
using, since we build it piece by piece.

So, let's make things clearer: handle autoconf separate from static IP,
and put all the string formatting in one place.
---
 dracut/parse-kickstart | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/dracut/parse-kickstart b/dracut/parse-kickstart
index 15efacd..0690e8e 100755
--- a/dracut/parse-kickstart
+++ b/dracut/parse-kickstart
@@ -190,6 +190,7 @@ def ksnet_to_dracut(args, lineno, net, bootdev=False):
     '''Translate the kickstart network data into dracut network data.'''
     line = []
     ip=""
+    autoconf="dhcp" # dracut default
 
     if is_mac(net.device): # this is a MAC - find the interface name
         mac = net.device
@@ -200,34 +201,39 @@ def ksnet_to_dracut(args, lineno, net, bootdev=False):
 
     # NOTE: dracut currently only does ipv4 *or* ipv6, so only one ip=arg..
     if net.bootProto in (BOOTPROTO_DHCP, BOOTPROTO_BOOTP):
-        ip="dhcp"
+        autoconf = "dhcp"
     elif net.bootProto == BOOTPROTO_IBFT:
-        ip="ibft"
+        autoconf = "ibft"
     elif net.bootProto == BOOTPROTO_QUERY:
         log.error("'%s': --bootproto=query is deprecated", " ".join(args))
     elif net.bootProto == BOOTPROTO_STATIC:
+        autoconf = "none"
+        ip = net.ip
+        # Static IPv4: check for missing items
         req = ("gateway", "netmask", "nameserver", "ip")
         missing = ", ".join("--%s" % i for i in req if not getattr(net, i, ""))
         if missing:
             log.warn("line %u: network missing %s", lineno, missing)
-        else:
-            ip="{0.ip}::{0.gateway}:{0.netmask}:" \
-               "{0.hostname}:{0.device}:none".format(net)
     elif net.ipv6 == "auto":
-        ip="auto6"
+        autoconf = "auto6"
     elif net.ipv6 == "dhcp":
-        ip="dhcp6"
+        autoconf = "dhcp6"
     elif net.ipv6:
-        ip="[{0.ipv6}]::{0.gateway}:{0.netmask}:" \
-           "{0.hostname}:{0.device}:none".format(net)
+        autoconf = "none"
+        ip = "[%s]" % net.ipv6
 
     if net.device is None:
         net.device = ""
 
-    if net.device and not ip.endswith(":none"):
-        line.append("ip=%s:%s" % (net.device, ip))
+    # These argument forms are documented in dracut.kernel(7)
+    if autoconf == "none":
+        ipstr = "ip={ip}::{net.gateway}:{net.netmask}:{net.hostname}:{net.device}:{autoconf}".format(ip=ip, autoconf=autoconf, net=net)
+    elif net.device:
+        ipstr = "ip={net.device}:{autoconf}".format(net=net, autoconf=autoconf)
     else:
-        line.append("ip=%s" % ip)
+        ipstr = "ip={autoconf}".format(autoconf=autoconf)
+
+    line.append(ipstr)
 
     for ns in net.nameserver.split(","):
         if ns:
-- 
1.7.11.4



More information about the anaconda-patches mailing list