Re: [PATCH f17-branch] dracut: fix kickstarting with 'network --device=MAC'

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

 



On Thu, May 03, 2012 at 07:22:19PM -0400, Will Woods wrote:
> parse-kickstart needs to check the device to see if it's a MAC and do
> the right thing when it is.
> ---
>  dracut/parse-kickstart |   34 +++++++++++++++++++++++++++++-----
>  1 files changed, 29 insertions(+), 5 deletions(-)
> 
> diff --git a/dracut/parse-kickstart b/dracut/parse-kickstart
> index e2e9223..6ef8701 100755
> --- a/dracut/parse-kickstart
> +++ b/dracut/parse-kickstart
> @@ -135,11 +135,32 @@ 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):
> +    sysdir="/sys/class/net"
> +    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"
> @@ -204,15 +225,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"
>  
> -- 
> 1.7.7.6

Ack for f17 and master

-- 
Brian C. Lane | Anaconda Team | IRC: bcl #anaconda | Port Orchard, WA (PST8PDT)

Attachment: pgpphHiTnUBss.pgp
Description: PGP signature

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux