Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Elijah Grubb
emulab-devel
Commits
fc58529c
Commit
fc58529c
authored
Nov 25, 2014
by
Mike Hibler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change to accept multiple nodes and to (re)create file with current setting.
parent
092e2dec
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
115 additions
and
74 deletions
+115
-74
db/libdb.pm.in
db/libdb.pm.in
+11
-3
utils/pxelinux_makeconf.in
utils/pxelinux_makeconf.in
+104
-71
No files found.
db/libdb.pm.in
View file @
fc58529c
...
...
@@ -547,9 +547,9 @@ sub TBBootWhat($;$$)
# powered off in that state, or maybe we go into one of the MFSes to
# await further instructions.
#
sub TBPxelinuxConfig($)
sub TBPxelinuxConfig($
;$
)
{
my ($node) = @_;
my ($node
,$actionp
) = @_;
my $nodeid = $node->node_id();
my $action;
my $verbose = 1;
...
...
@@ -593,6 +593,14 @@ sub TBPxelinuxConfig($)
$action = "pxewait";
}
#
# XXX if $actionp is set, we just want to return the action to take
#
if ($actionp) {
$$actionp = $action;
return;
}
my $cnet = LocalInterfaceLookupControl($node);
if ($cnet && $cnet->mac() &&
$cnet->mac() =~ /^(..)(..)(..)(..)(..)(..)$/) {
...
...
@@ -613,7 +621,7 @@ sub TBPxelinuxConfig($)
}
# argh...gotta use a setuid script to install a new pxelinux config!
if (!system("$TB/sbin/pxelinux_makeconf -d -a $action $nodeid >>/tmp/p
_m
.log 2>&1")) {
if (!system("$TB/sbin/pxelinux_makeconf -d -a $action $nodeid >>/tmp/p
xelinux_makeconf
.log 2>&1")) {
print("$nodeid: set pxelinux boot to '$action'\n");
return;
}
...
...
utils/pxelinux_makeconf.in
View file @
fc58529c
...
...
@@ -30,17 +30,18 @@ use Getopt::Std;
#
sub
usage
()
{
print
STDERR
"
Usage: pxelinux_makeconf [-a action] node
\n
";
print
STDERR
"
Usage: pxelinux_makeconf
[-A]
[-a action] node
\n
";
print
STDERR
"
Options:
\n
";
print
STDERR
"
-A - Recreate boot files for all nodes
\n
";
print
STDERR
"
-a action - Menu action to select, one of:
\n
";
print
STDERR
"
diskboot, mfsboot, pxewait, pxefail, nfsboot
\n
";
print
STDERR
"
Without an action it will (someday) determine the correct
\n
";
print
STDERR
"
current boot action and configure it for that.
\n
";
print
STDERR
"
diskboot, mfsboot, pxewait, pxefail, nfsboot, default
\n
";
print
STDERR
"
'default' (set to current) is the default.
\n
";
exit
(
-
1
);
}
my
$optlist
=
"
a:d
";
my
$action
;
my
$optlist
=
"
A
a:d
";
my
$action
=
"
default
"
;
my
$debug
=
0
;
my
$doall
=
0
;
#
# Configure variables
...
...
@@ -80,6 +81,7 @@ my $configdir = "/tftpboot/pxelinux.cfg";
my
$template
=
"
$configdir
/boot.template
";
# Protos
sub
donode
($$);
#
# Parse command arguments. Once we return from getopts, all that should be
...
...
@@ -93,94 +95,125 @@ if (defined($options{"d"})) {
$debug
=
1
;
}
if
(
defined
(
$options
{"
a
"}))
{
if
(
$options
{"
a
"}
=~
/^(diskboot|mfsboot|nfsboot|pxewait|pxefail)$/
)
{
if
(
$options
{"
a
"}
=~
/^(diskboot|mfsboot|nfsboot|pxewait|pxefail
|default
)$/
)
{
$action
=
$
1
;
}
else
{
usage
();
}
}
if
(
defined
(
$options
{"
A
"}))
{
print
STDERR
"
Not implemented yet...
\n
";
exit
(
2
);
# XXX
if
(
!
$action
)
{
print
STDERR
"
Sorry, gotta specify an action right now...
\n
";
exit
(
1
);
$doall
=
1
;
$action
=
"
default
";
}
# Right now we only act on a single node. No reason we cannot do more.
if
(
@ARGV
<
1
)
{
if
(
!
$doall
&&
@ARGV
<
1
)
{
usage
();
}
my
$nodeid
;
if
(
$ARGV
[
0
]
=~
/^([-\w]+)$/
)
{
$nodeid
=
$
1
;
my
@nodes
;
if
(
$doall
)
{
# find all the pxelinux nodes...
;
}
else
{
print
STDERR
"
$ARGV
[0]: bogus nodeid!
\n
";
usage
();
@nodes
=
@ARGV
;
}
print
"
$nodeid
: called to set action
$action
\n
"
if
(
$debug
);
my
$rv
=
0
;
foreach
my
$nodeid
(
@nodes
)
{
if
(
$nodeid
=~
/^([-\w]+)$/
)
{
$nodeid
=
$
1
;
}
else
{
print
STDERR
"
$nodeid
: bogus nodeid!
\n
";
usage
();
}
# No permissions checks right now, we assume the caller is legit.
my
$node
=
Node
->
Lookup
(
$nodeid
);
if
(
!
$node
)
{
print
STDERR
"
$nodeid
: bogus node!
\n
";
usage
();
}
# No permissions checks right now, we assume the caller is legit.
my
$node
=
Node
->
Lookup
(
$nodeid
);
if
(
!
$node
)
{
print
STDERR
"
$nodeid
: bogus node!
\n
";
usage
();
}
if
(
$node
->
boot_method
()
ne
"
pxelinux
")
{
print
STDERR
"
$nodeid
: not a pxelinux booted node.
\n
";
exit
(
0
);
$rv
+=
donode
(
$node
,
$action
);
}
my
$cnet
=
Interface
->
LookupControl
(
$node
);
if
(
!
$cnet
||
!
$cnet
->
mac
()
||
$cnet
->
mac
()
!~
/^(..)(..)(..)(..)(..)(..)$/
)
{
print
STDERR
"
$nodeid
: bogus cnet MAC.
\n
";
exit
(
1
);
}
else
{
$cfile
=
"
/tftpboot/pxelinux.cfg/01-$1-$2-$3-$4-$5-$6
";
}
exit
(
$rv
);
# already exists, see if it is set correctly
if
(
-
e
"
$cfile
"
&&
open
(
FD
,
"
<
$cfile
"))
{
while
(
<
FD
>
)
{
if
(
/^ONTIMEOUT\s+(\S+)/
)
{
if
(
$
1
eq
$action
)
{
close
(
FD
);
exit
(
0
);
}
last
;
sub
donode
($$)
{
my
(
$node
,
$action
)
=
@_
;
my
$nodeid
=
$node
->
node_id
();
print
"
$nodeid
: called to set action
$action
\n
"
if
(
$debug
);
if
(
$node
->
boot_method
()
ne
"
pxelinux
")
{
print
STDERR
"
$nodeid
: not a pxelinux booted node, ignored
\n
";
return
0
;
}
if
(
$action
eq
"
default
")
{
TBPxelinuxConfig
(
$node
,
\
$action
);
if
(
$action
eq
"
default
"
||
$action
eq
"
pxefail
")
{
# something went wrong
print
STDERR
"
$nodeid
: could not determine the correct action!?
\n
";
return
1
;
}
}
close
(
FD
);
}
#
# Need to create a new version.
# XXX racy. Maybe we should do "install -C"?
#
my
$tmpfile
=
"
$configdir
/
$nodeid
.
$PID
";
if
(
open
(
IFD
,
"
<
$template
")
&&
open
(
OFD
,
"
>
$tmpfile
"))
{
while
(
<
IFD
>
)
{
s/%default%/$action/
;
s/%nodeid%/$nodeid/
;
print
OFD
;
my
$cnet
=
Interface
->
LookupControl
(
$node
);
if
(
!
$cnet
||
!
$cnet
->
mac
()
||
$cnet
->
mac
()
!~
/^(..)(..)(..)(..)(..)(..)$/
)
{
print
STDERR
"
$nodeid
: bogus cnet MAC.
\n
";
return
1
;
}
else
{
$cfile
=
"
$configdir
/01-$1-$2-$3-$4-$5-$6
";
}
close
(
IFD
);
close
(
OFD
);
chmod
(
0644
,
$tmpfile
);
if
(
!
rename
(
$tmpfile
,
$cfile
))
{
unlink
(
$tmpfile
);
print
STDERR
"
$nodeid
: could not install new pxelinux config!
\n
";
exit
(
1
);
# already exists, see if it is set correctly
if
(
-
e
"
$cfile
"
&&
open
(
FD
,
"
<
$cfile
"))
{
while
(
<
FD
>
)
{
if
(
/^ONTIMEOUT\s+(\S+)/
)
{
if
(
$
1
eq
$action
)
{
close
(
FD
);
print
"
$nodeid
: already set to '
$action
'
\n
"
if
(
$debug
);
return
0
;
}
last
;
}
}
close
(
FD
);
}
print
"
$nodeid
: updated
$cfile
with action
$action
\n
"
if
(
$debug
);
exit
(
0
);
}
print
STDERR
"
$nodeid
: could not read template or write config!
\n
";
exit
(
1
);
#
# Need to create a new version.
# XXX racy. Maybe we should do "install -C"?
#
my
$tmpfile
=
"
$configdir
/
$nodeid
.
$PID
";
if
(
open
(
IFD
,
"
<
$template
")
&&
open
(
OFD
,
"
>
$tmpfile
"))
{
while
(
<
IFD
>
)
{
s/%default%/$action/
;
s/%nodeid%/$nodeid/
;
print
OFD
;
}
close
(
IFD
);
close
(
OFD
);
chmod
(
0644
,
$tmpfile
);
if
(
!
rename
(
$tmpfile
,
$cfile
))
{
unlink
(
$tmpfile
);
print
STDERR
"
$nodeid
: could not install new pxelinux config!
\n
";
return
1
;
}
print
"
$nodeid
: updated
$cfile
with action
$action
\n
"
if
(
$debug
);
return
0
;
}
print
STDERR
"
$nodeid
: could not read template or write config!
\n
";
return
1
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment