Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Enterprise Watch List (http://www.linux-archive.org/enterprise-watch-list/)
-   -   dracut/parse-kickstart: handle network --device=link (or none) (http://www.linux-archive.org/enterprise-watch-list/649665-dracut-parse-kickstart-handle-network-device-link-none.html)

Will Woods 03-27-2012 11:49 PM

dracut/parse-kickstart: handle network --device=link (or none)
 
If you have a kickstart where your first network line has no device (or
--device=link), we won't have a valid net.device ("" or "link",
respectively.) Still a valid kickstart though, so we need to generate
correct dracut args for that case.

Also we need to set rd.neednet so the device always goes online in
dracut (matching loader's behavior).

This means we don't need to write ifcfg if net.device is empty:
1) empty 'net.device' is only valid for the first device,
2) first device always comes online,
3) online devices get ifcfg written by dracut.

(It also means we don't need to touch /tmp/net.ifaces, since that happens
in step 3.)
---
dracut/parse-kickstart | 34 ++++++++++++++++++++--------------
1 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/dracut/parse-kickstart b/dracut/parse-kickstart
index d33394e..214d123 100755
--- a/dracut/parse-kickstart
+++ b/dracut/parse-kickstart
@@ -70,19 +70,17 @@ class Network(commands.network.F16_Network):
def dracut_args(self, args, lineno, net):
if len(self.network) == 1: # first network line gets special treatment
net.activate = True # activate by default
- if not net.device: # --device is optional, defaults to..
- net.device = self.handler.ksdevice # kickstart device, if any
- if not net.device:
+ # --device is optional, defaults to ksdevice
+ if net.device == "link" or not net.device:
+ net.device = self.handler.ksdevice # might be empty (ks=file:)
+ elif not net.device:
+ # every other network line needs a --device (and not "link")
log.error("'%s': missing --device", " ".join(args))
# write ifcfg for all listed devices
ksnet_to_ifcfg(net)
- # make sure /tmp/net.ifaces exists so dracut will copy them over
- if not os.path.exists("/tmp/net.ifaces"):
- open("/tmp/net.ifaces", "w")
# anaconda tradition: bring up the first device listed, and no others
if len(self.network) == 1:
- netline = ksnet_to_dracut(args, lineno, net)
- netline += " bootdev=%s" % net.device
+ netline = ksnet_to_dracut(args, lineno, net, bootdev=True)
return netline

# TODO: keymap, lang... device? upgrade? selinux?
@@ -137,13 +135,14 @@ def init_logger():
pass
return logger

-def ksnet_to_dracut(args, lineno, net):
+def ksnet_to_dracut(args, lineno, net, bootdev=False):
'Translate the kickstart network data into dracut network data.'
line = []
+ dev = net.device
if net.bootProto in (BOOTPROTO_DHCP, BOOTPROTO_BOOTP):
- line.append("ip=%s:dhcp" % net.device)
+ line.append("ip=%s:dhcp" % dev if dev else "ip=dhcp")
elif net.bootProto == BOOTPROTO_IBFT:
- line.append("ip=%s:ibft" % net.device)
+ line.append("ip=%s:ibft" % dev if dev else "ip=ibft")
elif net.bootProto == BOOTPROTO_QUERY:
log.error("'%s': --bootproto=query is deprecated", " ".join(args))
elif net.bootProto == BOOTPROTO_STATIC:
@@ -158,20 +157,25 @@ def ksnet_to_dracut(args, lineno, net):
line.append("nameserver=%s" % ns)

if net.ipv6 == "auto":
- line.append("ip=%s:auto6" % net.device)
+ line.append("ip=%s:auto6" % dev if dev else "ip=auto6")
elif net.ipv6 == "dhcp":
- line.append("ip=%s:dhcp6" % net.device)
+ line.append("ip=%s:dhcp6" % dev if dev else "ip=dhcp6")
elif net.ipv6:
line.append("ip=[{0.ipv6}]::{0.gateway}:{0.netmask}:"
"{0.hostname}:{0.device}".format(net))

if net.mtu:
# XXX FIXME: dracut doesn't support mtu= (yet)
- line.append("mtu=%s:%u" % (net.device, net.mtu))
+ line.append("mtu=%s:%u" % (dev, net.mtu) if dev else "mtu=%u" % 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

+ if bootdev:
+ if dev:
+ line.append("bootdev=%s" % dev)
+ line.append("rd.neednet=1")
+
if net.essid or net.wepkey or net.wpakey:
# TODO: make dracut support wireless? (do we care?)
log.error("'%s': dracut doesn't support wireless networks",
@@ -187,6 +191,8 @@ def readfile(f):

def ksnet_to_ifcfg(net, filename=None):
'Write an ifcfg file for the given kickstart network config'
+ if not net.device:
+ return
ifcfg = dict()
if filename is None:
filename = "/tmp/ifcfg/ifcfg-%s" % net.device
--
1.7.7.6

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

"Brian C. Lane" 03-28-2012 04:26 AM

dracut/parse-kickstart: handle network --device=link (or none)
 
On Tue, Mar 27, 2012 at 07:49:24PM -0400, Will Woods wrote:

> -def ksnet_to_dracut(args, lineno, net):
> +def ksnet_to_dracut(args, lineno, net, bootdev=False):
> 'Translate the kickstart network data into dracut network data.'
> line = []
> + dev = net.device
> if net.bootProto in (BOOTPROTO_DHCP, BOOTPROTO_BOOTP):
> - line.append("ip=%s:dhcp" % net.device)
> + line.append("ip=%s:dhcp" % dev if dev else "ip=dhcp")

I don't think that's what you meant to do. If dev is None you're going
to end up with:

ip=ip=dhcp

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

Will Woods 03-28-2012 03:13 PM

dracut/parse-kickstart: handle network --device=link (or none)
 
On Tue, 2012-03-27 at 21:26 -0700, Brian C. Lane wrote:

> > + line.append("ip=%s:dhcp" % dev if dev else "ip=dhcp")
>
> I don't think that's what you meant to do. If dev is None you're going
> to end up with:
>
> ip=ip=dhcp

Actually, no: the 'if .. else' construct[1] has higher precedence than
anything except 'lambda'[2]. Try it and see:

for dev in ("eth0", "", None):
str = "ip=%s:dhcp" % dev if dev else "ip=dhcp"
print str

I did actually test this code before sending it for review - I try to
test everything I send, or clearly mark it as untested otherwise. I
assume that's what everyone does? Do we need to codify that or anything?

-w

[1] Called "Conditional Expressions", introduced in Python 2.5 by PEP308
[2] http://docs.python.org/reference/expressions.html#summary

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

Chris Lumens 03-28-2012 03:22 PM

dracut/parse-kickstart: handle network --device=link (or none)
 
> > > + line.append("ip=%s:dhcp" % dev if dev else "ip=dhcp")

Someone's been looking at too much perl.

I know other people have written similar constructions in their patches
in the past, and we've always asked them to take it out.

> I did actually test this code before sending it for review - I try to
> test everything I send, or clearly mark it as untested otherwise. I
> assume that's what everyone does? Do we need to codify that or anything?

We don't really have any rules about it. Certainly, everyone ought to
test what they write before they send it and especially for release
branches. Master is of course a little less important. I'll admit I've
sent off stuff untested before, or at least not tested thoroughly
enough.

- Chris

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

Will Woods 04-03-2012 09:32 PM

dracut/parse-kickstart: handle network --device=link (or none)
 
If you have a kickstart where your first network line has no device (or
--device=link), we won't have a valid net.device ("" or "link",
respectively.) Still a valid kickstart though, so we need to generate
correct dracut args for that case.

Also we need to set rd.neednet so the device always goes online in
dracut (matching loader's behavior).

This means we don't need to write ifcfg if net.device is empty:
1) empty 'net.device' is only valid for the first device,
2) first device always comes online,
3) online devices get ifcfg written by dracut.

(It also means we don't need to touch /tmp/net.ifaces, since that happens
in step 3.)
---
dracut/parse-kickstart | 62 +++++++++++++++++++++++++++++++-----------------
1 files changed, 40 insertions(+), 22 deletions(-)

diff --git a/dracut/parse-kickstart b/dracut/parse-kickstart
index d33394e..4bb2a54 100755
--- a/dracut/parse-kickstart
+++ b/dracut/parse-kickstart
@@ -70,19 +70,17 @@ class Network(commands.network.F16_Network):
def dracut_args(self, args, lineno, net):
if len(self.network) == 1: # first network line gets special treatment
net.activate = True # activate by default
- if not net.device: # --device is optional, defaults to..
- net.device = self.handler.ksdevice # kickstart device, if any
- if not net.device:
+ # --device is optional, defaults to ksdevice
+ if net.device == "link" or not net.device:
+ net.device = self.handler.ksdevice # might be empty (ks=file:)
+ elif not net.device:
+ # every other network line needs a --device (and not "link")
log.error("'%s': missing --device", " ".join(args))
# write ifcfg for all listed devices
ksnet_to_ifcfg(net)
- # make sure /tmp/net.ifaces exists so dracut will copy them over
- if not os.path.exists("/tmp/net.ifaces"):
- open("/tmp/net.ifaces", "w")
# anaconda tradition: bring up the first device listed, and no others
if len(self.network) == 1:
- netline = ksnet_to_dracut(args, lineno, net)
- netline += " bootdev=%s" % net.device
+ netline = ksnet_to_dracut(args, lineno, net, bootdev=True)
return netline

# TODO: keymap, lang... device? upgrade? selinux?
@@ -137,13 +135,16 @@ def init_logger():
pass
return logger

-def ksnet_to_dracut(args, lineno, net):
+def ksnet_to_dracut(args, lineno, net, bootdev=False):
'Translate the kickstart network data into dracut network data.'
line = []
+
+ ip=""
+ # NOTE: dracut currently only does ipv4 *or* ipv6, so only one ip=arg..
if net.bootProto in (BOOTPROTO_DHCP, BOOTPROTO_BOOTP):
- line.append("ip=%s:dhcp" % net.device)
+ ip="dhcp"
elif net.bootProto == BOOTPROTO_IBFT:
- line.append("ip=%s:ibft" % net.device)
+ ip="ibft"
elif net.bootProto == BOOTPROTO_QUERY:
log.error("'%s': --bootproto=query is deprecated", " ".join(args))
elif net.bootProto == BOOTPROTO_STATIC:
@@ -152,30 +153,45 @@ def ksnet_to_dracut(args, lineno, net):
if missing:
log.warn("line %u: network missing %s", lineno, missing)
else:
- line.append("ip={0.ip}::{0.gateway}:{0.netmask}:"
- "{0.hostname}:{0.device}".format(net))
- for ns in net.nameserver.split(","):
- line.append("nameserver=%s" % ns)
-
- if net.ipv6 == "auto":
- line.append("ip=%s:auto6" % net.device)
+ ip="{0.ip}::{0.gateway}:{0.netmask}:"
+ "{0.hostname}:{0.device}:none".format(net)
+ elif net.ipv6 == "auto":
+ ip="auto6"
elif net.ipv6 == "dhcp":
- line.append("ip=%s:dhcp6" % net.device)
+ ip="dhcp6"
elif net.ipv6:
- line.append("ip=[{0.ipv6}]::{0.gateway}:{0.netmask}:"
- "{0.hostname}:{0.device}".format(net))
+ 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))
+ else:
+ line.append("ip=%s" % ip)
+
+ for ns in net.nameserver.split(","):
+ line.append("nameserver=%s" % ns)

if net.mtu:
# XXX FIXME: dracut doesn't support mtu= (yet)
- line.append("mtu=%s:%u" % (net.device, net.mtu))
+ if net.device:
+ line.append("mtu=%s:%u" % (net.device, net.mtu))
+ else:
+ line.append("mtu=%u" % 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

+ if bootdev:
+ if net.device:
+ line.append("bootdev=%s" % net.device)
+ line.append("rd.neednet=1")
+
if net.essid or net.wepkey or net.wpakey:
# TODO: make dracut support wireless? (do we care?)
log.error("'%s': dracut doesn't support wireless networks",
" ".join(args))
+
return " ".join(line)

def readfile(f):
@@ -187,6 +203,8 @@ def readfile(f):

def ksnet_to_ifcfg(net, filename=None):
'Write an ifcfg file for the given kickstart network config'
+ if not net.device:
+ return
ifcfg = dict()
if filename is None:
filename = "/tmp/ifcfg/ifcfg-%s" % net.device
--
1.7.7.6

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


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

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.