FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 05-03-2012, 11:22 PM
Will Woods
 
Default 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.
---
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

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 05-04-2012, 12:13 AM
"Brian C. Lane"
 
Default dracut: fix kickstarting with 'network --device=MAC'

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)
_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 05-04-2012, 07:36 AM
Vratislav Podzimek
 
Default dracut: fix kickstarting with 'network --device=MAC'

On Thu, 2012-05-03 at 19:22 -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
Why do you define $sysdir and then use the "/sys/class/net" instead of
it?

> +
> 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"
>

--
Vratislav Podzimek <vpodzime@redhat.com>

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 05-04-2012, 05:38 PM
Will Woods
 
Default dracut: fix kickstarting with 'network --device=MAC'

On Fri, 2012-05-04 at 09:36 +0200, Vratislav Podzimek wrote:
> On Thu, 2012-05-03 at 19:22 -0400, Will Woods wrote:
> > +def find_devname(mac):
> > + sysdir="/sys/class/net"
> > + for netif in os.listdir("/sys/class/net"):
[snip]
> Why do you define $sysdir and then use the "/sys/class/net" instead of
> it?

Whoops, good catch - I meant to drop the sysdir="/sys/class/net" line,
but forgot. I'll amend before I push.

-w

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

Thread Tools




All times are GMT. The time now is 02:48 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org