[PATCH 1/3] ksnet_to_dracut(): handle --mtu, cleanups

Will Woods wwoods at redhat.com
Thu Aug 23 00:54:19 UTC 2012


Make parse-kickstart handle 'network --mtu=...' properly (now that
dracut supports it). Also generally clean up the handling of the "ip="
arg and correctly handle missing data for static ipv4.
---
 dracut/parse-kickstart | 46 +++++++++++++++++++++++-----------------------
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/dracut/parse-kickstart b/dracut/parse-kickstart
index 55bc43a..851cecb 100755
--- a/dracut/parse-kickstart
+++ b/dracut/parse-kickstart
@@ -208,54 +208,54 @@ def find_devname(mac):
 def ksnet_to_dracut(args, lineno, net, bootdev=False):
     '''Translate the kickstart network data into dracut network data.'''
     line = []
-    ip=""
 
     if is_mac(net.device): # this is a MAC - find the interface name
         mac = net.device
         net.device = find_devname(mac)
-        if net.device is None:  # iface not active - pick a name for it
+        if not net.device:  # iface not active - pick a name for it
             net.device = "ksdev0" # we only get called once, so this is OK
             line.append("ifname=%s:%s" % (net.device, mac.lower()))
 
     # NOTE: dracut currently only does ipv4 *or* ipv6, so only one ip=arg..
+    ip = ""
+    if not net.device:
+        net.device = ""
+    net.autoconf = "dhcp" # dracut's default
     if net.bootProto in (BOOTPROTO_DHCP, BOOTPROTO_BOOTP):
-        ip="dhcp"
+        net.autoconf = "dhcp"
     elif net.bootProto == BOOTPROTO_IBFT:
-        ip="ibft"
+        net.autoconf = "ibft"
     elif net.bootProto == BOOTPROTO_QUERY:
         log.error("'%s': --bootproto=query is deprecated", " ".join(args))
     elif net.bootProto == BOOTPROTO_STATIC:
+        net.autoconf = "none"
+        ip = net.ip
         req = ("gateway", "netmask", "nameserver", "ip")
-        missing = ", ".join("--%s" % i for i in req if not hasattr(net, i))
+        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"
+        net.autoconf = "auto6"
     elif net.ipv6 == "dhcp":
-        ip="dhcp6"
+        net.autoconf = "dhcp6"
     elif net.ipv6:
-        ip="[{0.ipv6}]::{0.gateway}:{0.netmask}:" \
-           "{0.hostname}:{0.device}:none".format(net)
-
-    if net.device and not ip.endswith(":none"):
-        line.append("ip=%s:%s" % (net.device, ip))
+        net.autoconf = "none"
+        ip = "[%s]" % net.ipv6
+
+    # These argument forms are documented in dracut.kernel(7)
+    if net.autoconf == "none" or (net.mtu and not net.device):
+        ipstr = "ip={ip}::{net.gateway}:{net.netmask}:{net.hostname}:{net.device}:{net.autoconf}:{net.mtu}".format(ip=ip, net=net)
+    elif net.device:
+        ipstr = "ip={net.device}:{net.autoconf}:{net.mtu}".format(net=net)
     else:
-        line.append("ip=%s" % ip)
+        ipstr = "ip={net.autoconf}".format(net=net)
+
+    line.append(ipstr)
 
     for ns in net.nameserver.split(","):
         if ns:
             line.append("nameserver=%s" % ns)
 
-    if net.mtu:
-        # XXX FIXME: dracut doesn't support mtu= (yet)
-        if net.device:
-            line.append("mtu=%s:%s" % (net.device, net.mtu))
-        else:
-            line.append("mtu=%s" % 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
-- 
1.7.11.4



More information about the anaconda-patches mailing list