Commit 4a4dcaa2 authored by Mike Hibler's avatar Mike Hibler

Add -w option to os_select to put a node in PXEWAIT.

Replaces a direct DB query in the elabinelab code to perform the same function.
Also, make sure that os_select allows a symbolic osid in a form that the
OSinfo->Lookup() method actually accepts (pid/osname rather than osname).
parent 86baef16
......@@ -2718,19 +2718,38 @@ sub OSSelect($$$$)
$osinfo = $nextosinfo;
}
print STDERR "Current opmode for $nodeid is $curmode.\n"
if ($debug);
print STDERR "Setting $field for $nodeid to $osinfo.\n"
if ($debug && defined($osinfo));
if (defined($osinfo) && !defined($field)) {
print STDERR "No field specified for OSSelect on $node_id\n";
return -1;
}
# Set/Clear the osid.
DBQueryWarn("update nodes set ${field}=".
(defined($osinfo) ? "'" . $osinfo->osid() . "' " : "NULL ") .
"where node_id='$nodeid'")
or return -1;
if ($debug) {
print STDERR "Current opmode for $nodeid is $curmode.\n";
if (defined($osinfo)) {
print STDERR "Setting $field for $nodeid to $osinfo.\n";
} elsif (defined($field)) {
print STDERR "Clearing $field for $nodeid.\n";
} else {
print STDERR "Clearing all boot_osids for $nodeid.\n";
}
}
return -1
if ($self->ResetNextOpMode($debug) < 0);
if (!defined($field)) {
# Clear all osids.
DBQueryWarn("update nodes set ".
"def_boot_osid=NULL,next_boot_osid=NULL,temp_boot_osid=NULL ".
"where node_id='$nodeid'")
or return -1;
} else {
# Set/Clear the osid.
DBQueryWarn("update nodes set ${field}=".
(defined($osinfo) ? "'" . $osinfo->osid() . "' " : "NULL ") .
"where node_id='$nodeid'")
or return -1;
return -1
if ($self->ResetNextOpMode($debug) < 0);
}
return Refresh($self);
}
......
......@@ -2,7 +2,7 @@
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2010 University of Utah and the Flux Group.
# Copyright (c) 2000-2011 University of Utah and the Flux Group.
# All rights reserved.
#
......@@ -19,12 +19,14 @@ Usage: os_select [-h] [-d] [-c] [-1 | -t] [<osid>] <node> [<node> ...]
-t Apply change to temporary boot field
-b Reset to default boot osid. Do not provide an osid.
-l Show the current settings.
osid OS identifier for the selected OS (see web interface for listing)
-w Put the nodes in PXEWAIT mode (clears all osids)
osid OS identifier for the selected OS. Must be either numeric ID or
a string in the form <pid>/<osname> (see web interface for listing)
node Node identifiers (ie pcXX)
EOF
exit(-1);
}
my $optlist = "hdc1tbl";
my $optlist = "hdc1tblw";
# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin';
......@@ -70,6 +72,7 @@ my $tempmode = 0; # apply change to temp_boot_osid.
my $clear = 0; # Clear the selected boot (def,temp,next).
my $default = 0; # Reset back to default osid.
my $list = 0; # Just list the current settings.
my $waitmode = 0; # Send the node into PXEWAIT
my @nodes = ();
my $osid;
my $osinfo;
......@@ -90,15 +93,21 @@ if (defined($options{"t"})) { $tempmode=1; }
if (defined($options{"c"})) { $clear=1; }
if (defined($options{"b"})) { $default=1; }
if (defined($options{"l"})) { $list=1; }
if (defined($options{"w"})) { $waitmode=1; }
# In clearmode, there is no OSID. Just a list of nodes.
if (! ($clear || $list || $default)) {
if ($waitmode + $list + $clear + $default > 1) {
print STDERR "Should specify only one of -b, -c, -l, -w\n";
usage();
}
# In certain modes, there is no OSID. Just a list of nodes.
if (! ($clear || $list || $default || $waitmode)) {
usage()
if (@ARGV < 2);
$osid = shift();
# Untaint args.
if ($osid =~ /^([-\w\+\.]+)$/) {
if ($osid =~ /^([-\w\+\.\/]+)$/) {
$osid = $1;
}
else {
......@@ -139,9 +148,9 @@ if ($UID && !TBAdmin($UID)) {
#
# Grab the info for the OSID.
#
if (! ($clear || $list || $default)) {
if (defined($osid)) {
$osinfo = OSinfo->Lookup($osid);
fatal("Improper DB entry for OSID: $osid")
fatal("Unknown OSID: $osid")
if (!defined($osinfo));
}
elsif ($default) {
......@@ -175,6 +184,13 @@ foreach my $node (@nodes) {
next;
}
if ($waitmode) {
if ($nodeobject->OSSelect($osinfo, undef, $debug) != 0) {
fatal("OSSelect(): clearing all fields failed on $node");
}
next;
}
# The field to change in the DB.
my $field = "def_boot_osid";
$field = "next_boot_osid"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment