diff options
author | Will Woods <wwoods@redhat.com> | 2012-05-03 14:45:28 -0400 |
---|---|---|
committer | Will Woods <wwoods@redhat.com> | 2012-05-04 13:47:00 -0400 |
commit | e135c5d179da0290b2389c76f66e6739c62101a8 (patch) | |
tree | c76402e865660cd6ed3254181274c5adec8d52f2 /dracut | |
parent | f99f5b215144a62c36c1322f855bbe0e89a3b453 (diff) | |
download | anaconda-e135c5d179da0290b2389c76f66e6739c62101a8.tar.gz anaconda-e135c5d179da0290b2389c76f66e6739c62101a8.tar.xz anaconda-e135c5d179da0290b2389c76f66e6739c62101a8.zip |
dracut: fix kickstarting with 'network --device=MAC'
parse-kickstart needs to check the device to see if it's a MAC and do
the right thing when it is.
Diffstat (limited to 'dracut')
-rwxr-xr-x | dracut/parse-kickstart | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/dracut/parse-kickstart b/dracut/parse-kickstart index 50c8c0101..0c8110861 100755 --- a/dracut/parse-kickstart +++ b/dracut/parse-kickstart @@ -135,11 +135,31 @@ def init_logger(): pass return logger +def is_mac(addr): + return addr and len(addr) == 17 and addr.count(":") == 5 # good enough + +def find_devname(mac): + for netif in os.listdir("/sys/class/net"): + try: + thismac = readfile("/sys/class/net/%s/address" % netif) + except IOError: + pass + else: + if thismac.lower() == mac.lower(): + return netif + 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 + net.device = "eth0" # 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.. if net.bootProto in (BOOTPROTO_DHCP, BOOTPROTO_BOOTP): ip="dhcp" @@ -203,15 +223,18 @@ def readfile(f): def ksnet_to_ifcfg(net, filename=None): '''Write an ifcfg file for the given kickstart network config''' - if not net.device: + dev = net.device + if is_mac(dev): + dev = find_devname(dev) + if not dev: return ifcfg = dict() if filename is None: - filename = "/tmp/ifcfg/ifcfg-%s" % net.device + filename = "/tmp/ifcfg/ifcfg-%s" % dev 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['DEVICE'] = dev + ifcfg['HWADDR'] = readfile("/sys/class/net/%s/address" % dev) ifcfg['UUID'] = readfile("/proc/sys/kernel/random/uuid") ifcfg['ONBOOT'] = "yes" if net.onboot else "no" |