diff options
| author | Will Woods <wwoods@redhat.com> | 2012-03-15 19:53:14 -0400 |
|---|---|---|
| committer | Will Woods <wwoods@redhat.com> | 2012-03-16 12:36:59 -0400 |
| commit | c35c0a9d842c1846dce1770c4c320331af6f61ab (patch) | |
| tree | 97ee3cc5123ad6cf36ebfc8470b6305a0dcb949b /dracut/parse-kickstart | |
| parent | 9b03004817dca5ffc8d7955315f61ea39dee06be (diff) | |
| download | anaconda-c35c0a9d842c1846dce1770c4c320331af6f61ab.tar.gz anaconda-c35c0a9d842c1846dce1770c4c320331af6f61ab.tar.xz anaconda-c35c0a9d842c1846dce1770c4c320331af6f61ab.zip | |
parse-kickstart: write ifcfg files for all net devs
(note that the one for the ksdevice will get overwritten by dracut,
but that's OK)
update comments to reflect current limitations etc.
oh, and AFAICT loader just uses DHCP for BOOTP, so handle BOOTP like
DHCP if we see that. (which we won't.)
Diffstat (limited to 'dracut/parse-kickstart')
| -rwxr-xr-x | dracut/parse-kickstart | 77 |
1 files changed, 69 insertions, 8 deletions
diff --git a/dracut/parse-kickstart b/dracut/parse-kickstart index 8e1706238..9933a7a7a 100755 --- a/dracut/parse-kickstart +++ b/dracut/parse-kickstart @@ -74,11 +74,12 @@ class Network(commands.network.F16_Network): net.device = self.handler.ksdevice # kickstart device, if any if not net.device: log.error("'%s': missing --device", " ".join(args)) - elif net.activate: # we only care about activated devices + # write ifcfg for all listed devices + ksnet_to_ifcfg(net) + # anaconda tradition: bring up the first device listed, and no others + if len(self.network) == 1: netline = ksnet_to_dracut(args, lineno, net) - # The first device in the kickstart is our new bootdev - if len(self.network) == 1: - netline += " bootdev=%s" % net.device + netline += " bootdev=%s" % net.device return netline # TODO: keymap, lang... device? upgrade? selinux? @@ -136,12 +137,10 @@ def init_logger(): def ksnet_to_dracut(args, lineno, net): '''Translate the kickstart network data into dracut network data.''' line = [] - if net.bootProto == BOOTPROTO_DHCP: + if net.bootProto in (BOOTPROTO_DHCP, BOOTPROTO_BOOTP): line.append("ip=%s:dhcp" % net.device) elif net.bootProto == BOOTPROTO_IBFT: line.append("ip=%s:ibft" % net.device) - elif net.bootProto == BOOTPROTO_BOOTP: # NOTE: no dracut support yet... - line.append("ip=%s:bootp" % net.device) elif net.bootProto == BOOTPROTO_QUERY: log.error("'%s': --bootproto=query is deprecated", " ".join(args)) elif net.bootProto == BOOTPROTO_STATIC: @@ -166,7 +165,9 @@ def ksnet_to_dracut(args, lineno, net): if net.mtu: # XXX FIXME: dracut doesn't support mtu= (yet) line.append("mtu=%s:%u" % (net.device, net.mtu)) - # TODO FIXME ALSO: nodns, nodefroute, noipv4, noipv6, dhcpclass + # 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 net.essid or net.wepkey or net.wpakey: # TODO: make dracut support wireless? (do we care?) @@ -174,6 +175,66 @@ def ksnet_to_dracut(args, lineno, net): " ".join(args)) return " ".join(line) +def readfile(f): + try: + val = open(f).readline().strip() + except IOError: + val = None + return val + +def ksnet_to_ifcfg(net, filename=None): + '''Write an ifcfg file for the given kickstart network config''' + ifcfg = dict() + if filename is None: + filename = "/tmp/ifcfg/ifcfg-%s" % net.device + if not os.path.isdir("/tmp/ifcfg"): + os.makedirs("/tmp/ifcfg") + ifcfg['DEVICE'] = net.device + ifcfg['HWADDR'] = readfile("/sys/class/net/%s/address" % net.device) + ifcfg['UUID'] = readfile("/proc/sys/kernel/random/uuid") + ifcfg['ONBOOT'] = "yes" if net.onboot else "no" + + # dhcp etc. + ifcfg['BOOTPROTO'] = net.bootProto + if net.bootProto == 'static': + ifcfg['IPADDR'] = net.ip + ifcfg['NETMASK'] = net.netmask + ifcfg['GATEWAY'] = net.gateway + if net.bootProto == 'dhcp': + if net.hostname: + ifcfg['DHCP_HOSTNAME'] = net.hostname + + # ipv6 settings + if net.noipv6: + ifcfg['IPV6INIT'] = "no" + if net.ipv6 == 'dhcp': + ifcfg['DHCPV6C'] = "yes" + ifcfg['IPV6_AUTOCONF'] = "no" + elif ':' in net.ipv6: + ifcfg['IPV6ADDR'] = net.ipv6 + + # misc stuff + if net.mtu: + ifcfg['MTU'] = net.mtu + if net.nameserver: + ifcfg['DNS1'] = net.nameserver + if net.nodefroute: + ifcfg['DEFROUTE'] = "no" + + # TODO: dhcpclass, ethtool, etc. (see comments in ksnet_to_dracut()) + # TODO: handle essid/wepkey/wpakey (maybe inside anaconda) + + try: + outf = open(filename, "w") + outf.write('# Generated by parse-kickstart\n') + for k,v in ifcfg.items(): + outf.write("%s=%s\n" % (k,v)) + outf.close() + except IOError as e: + log.error("can't write %s: %s" % (filename, str(e))) + else: + return filename + def process_kickstart(ksfile): handler = DracutHandler() handler.ksdevice = os.environ.get('ksdevice') |
