Commit 79e2351c authored by Kirk Webb's avatar Kirk Webb

Add power management commands/support for UE class.

Also properly integrate UE class into os_load process.
parent a277d373
......@@ -389,12 +389,26 @@ sub cmd_unforward($@) {
# Given a valid node_id, reboot a device.
#
sub cmd_reboot($;@) {
my ($node_id) = @_;
my ($node_id, $suplcmd) = @_;
# Check and untaint arguments;
die "tbadb::cmd_reboot: node_id argument missing!\n"
if (!$node_id);
if ($suplcmd) {
SW1: for ($suplcmd) {
/^wait$/ && do {
$suplcmd = "WAIT";
last SW1;
};
/^fastboot$/ && do {
$suplcmd = "FASTBOOT";
last SW1;
};
die "tbadb::cmd_reboot: Unknown supplementary command: $suplcmd\n";
}
}
# Make sure user has access to requested node
my $node = Node->Lookup($node_id);
die "tbadb::cmd_reboot: Invalid node name $node_id!\n"
......@@ -408,9 +422,13 @@ sub cmd_reboot($;@) {
if (!$rpcin || !$rpcout);
# Request device reboot via remote host.
my $arghash = { NODE_ID => $node_id };
if ($suplcmd) {
$arghash->{$suplcmd} = 1;
}
die "tbadb::cmd_reboot: Failed to send 'reboot' RPC!\n"
if (!SendRPCData($rpcout,
EncodeCall("reboot", { NODE_ID => $node_id })));
EncodeCall("reboot", $arghash)));
# Wait for reboot and grab returned result.
my $pdu;
......
......@@ -91,6 +91,7 @@ my $GREP = "/bin/grep";
my $IMAGE_CACHE = "/z/tbadb_img_cache";
my $WM_HIGH = 50 * 1000 * 1000 * 1000; # 50 GB
my $WM_LOW = 40 * 1000 * 1000 * 1000; # 40 GB
my $ADBD_LISTENPORT = 5555;
my $MINPORT = 8001;
my $MAXPORT = 8100;
my $HOUSEKEEPING_INTERVAL = 60;
......@@ -526,37 +527,49 @@ sub rpc_reboot($) {
my $node_id = $data->{ARGS}->{NODE_ID};
my $dowait = $data->{ARGS}->{WAIT};
my $fastboot = $data->{ARGS}->{FASTBOOT};
# Do a bit of arg checking.
$dowait = defined($dowait) && int($dowait) ? 1 : 0;
$fastboot = defined($fastboot) && int($fastboot) ? 1 : 0;
if (!$node_id) {
warn "tbadb_serv::rpc_reboot: No node_id provided in RPC args!\n";
send_error($data->{FID}, RPCERR_BADARGS, "node_id missing.");
exit 1;
}
if (!exists($NMAP{$node_id})) {
warn "tbadb::rpc_loadimage: unknown/bad node_id: $node_id\n";
warn "tbadb_serv::rpc_reboot: unknown/bad node_id: $node_id\n";
send_error($data->{FID}, RPCERR_BADARGS, "Unknown/bad node_id.");
exit 1;
}
my $serial = $NMAP{$node_id};
# Reboot the unit.
warn "tbadb_serv::rpc_reboot: rebooting node $node_id\n";
if (!reboot_android($node_id)) {
warn "tbadb_serv::rpc_reboot: failed to reboot $node_id!\n";
send_error($data->{FID}, RPCERR_NODE_ERR, "Reboot failed.");
exit 1;
# Reboot the unit as directed.
if ($fastboot) {
warn "tbadb_serv::rpc_reboot: rebooting node into fastboot: $node_id\n";
if (!enter_fastboot($node_id)) {
warn "tbadb_serv::rpc_reboot: failed to enter fastboot: $node_id!\n";
send_error($data->{FID}, RPCERR_NODE_ERR, "Reboot (fastboot) failed.");
exit 1;
}
}
# Wait for device to boot up, if requested to do so.
if ($dowait) {
warn "tbadb_serv::rpc_reboot: waiting for $node_id to come up.\n";
if (!wait_for_node($node_id)) {
warn "tbadb_serv::rpc_reboot: failed waiting for $node_id to boot!\n";
send_error($data->{FID}, RPCERR_NODE_ERR, "Boot failed.");
else {
warn "tbadb_serv::rpc_reboot: rebooting node $node_id\n";
if (!reboot_android($node_id)) {
warn "tbadb_serv::rpc_reboot: failed to reboot $node_id!\n";
send_error($data->{FID}, RPCERR_NODE_ERR, "Reboot failed.");
exit 1;
}
# Wait for device to boot up, if requested to do so.
if ($dowait) {
warn "tbadb_serv::rpc_reboot: waiting for $node_id to come up.\n";
if (!wait_for_node($node_id)) {
warn "tbadb_serv::rpc_reboot: failed waiting for $node_id to boot!\n";
send_error($data->{FID}, RPCERR_NODE_ERR, "Boot failed.");
exit 1;
}
}
}
# Report success.
......@@ -1064,9 +1077,15 @@ sub setup_android_forward($$;$$) {
goto BADFWD;
}
# Restart adbd on the UE listening on tcpip port 5555
if (system("$ADB -s $serial tcpip $ADBD_LISTENPORT") != 0) {
warn "tbadb_serv::setup_android_forward: could not restart adbd on $node_id to listen on tcpip port $ADBD_LISTENPORT!\n";
goto BADFWD;
}
# Forward!
if (system("$ADB -s $serial forward tcp:$port tcp:5555 >/dev/null 2>&1") != 0) {
warn "tbadb_serv::setup_android_forward: could not forward adbd port on node_id to local port $port!\n";
if (system("$ADB -s $serial forward tcp:$port tcp:$ADBD_LISTENPORT >/dev/null 2>&1") != 0) {
warn "tbadb_serv::setup_android_forward: could not forward adbd port on $node_id to local port $port!\n";
goto BADFWD;
}
......
......@@ -104,7 +104,7 @@ LIBEXEC_STUFF = wanlinksolve wanlinkinfo os_setup mkexpdir console_setup \
$(WEB_BIN_SCRIPTS) $(WEB_SBIN_SCRIPTS)
LIB_STUFF = libtbsetup.pm exitonwarn.pm libtestbed.pm \
power_rpc27.pm power_apc.pm \
power_rpc27.pm power_apc.pm power_ue.pm \
power_sgmote.pm power_racktivity.pm \
libaudit.pm libreboot.pm libosload.pm libtestbed.py \
libadminmfs.pm libtblog.pm libtblog_simple.pm libArchive.pm \
......
......@@ -43,6 +43,7 @@ use NodeType;
use Image;
use User;
use OSinfo;
use EmulabConstants;
use English;
use event;
use Data::Dumper;
......@@ -1274,14 +1275,14 @@ sub SetupReloadUE($)
{
my $reload_info = $_[0];
my $node = $reload_info->{'node'};
my $imageid = $reload_info->{'imageid'};
my $image = (@{$reload_info->{'images'}})[0];
my $osid = $reload_info->{'osid'};
#
# Get the path to the image
# Get some image details for tbadb
#
my $img = Image->Lookup($imageid);
my $path = $img->path();
my $imgpid = $image->pid();
my $imgname = $image->imagename();
#
# Tell stated that we're about to start reloading
......@@ -1298,9 +1299,9 @@ sub SetupReloadUE($)
# Invoke local script that calls the remote end that
# actually does the work.
#
my $rv = system("$TBADB upload $path $node");
my $rv = system("$TBADB -n $node loadimage $imgpid $imgname");
if ($rv) {
tberror "$node: tbadb failed";
tberror "$node: tbadb loadimage failed!";
return -1;
}
......@@ -1312,7 +1313,7 @@ sub SetupReloadUE($)
system("$osselect $osid $node");
if ($?) {
tberror "os_select $osid failed!";
goto failednode;
return -1;
}
#
......
......@@ -2190,7 +2190,7 @@ sub AddNode($$)
# libosload will handle the alternate way images need to be loaded.
#
package libossetup_ue;
use base qw(libossetup_handler);
use base qw(libossetup_pc);
use libdb;
use libtestbed;
......@@ -2201,17 +2201,5 @@ use English;
use Data::Dumper;
use overload ('""' => 'Stringify');
sub New($$) {
my ($class, $parent) = @_;
my $self = $class->SUPER::New("ue", $parent);
bless($self, $class);
return $self;
}
sub AddNode($$)
{
my ($self, $node) = @_;
return $self->SUPER::AddNode($node);
}
# This needs to be the last thing in the file.
1;
......@@ -54,6 +54,7 @@ use power_ilo;
use power_icebox;
use power_apc;
use power_racktivity;
use power_ue;
use libtestbed;
use User;
use Node;
......@@ -364,7 +365,7 @@ foreach my $power_id (keys %outlets) {
if ($power_id eq "mail" || $power_id =~ /^whol-/
|| $power_id=~ /^rmcp-/
|| $power_id eq 'ipmi15' || $power_id eq 'ipmi20'
|| $power_id eq 'drac'
|| $power_id eq 'drac' || $power_id eq 'ue'
|| $power_id eq 'ilo' || $power_id eq 'ilo2' || $power_id eq 'ilo3') {
$type = $power_id;
$IP = "";
......@@ -459,6 +460,11 @@ foreach my $power_id (keys %outlets) {
print "Control of $nodestr failed.\n"; $exitval++;
$errors++;
}
} elsif ($type eq "ue") {
if (uectrl($op,@nodes)) {
print "Control of $nodestr failed.\n"; $exitval++;
$errors++;
}
} elsif ($type =~ /whol-(\w+)/) {
my $iface = $1;
if (wholctrl($op,$iface,@nodes)) {
......
#!/usr/bin/perl -wT
#
# Copyright (c) 2004 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
# A little perl module to power cycle a ue attached to a console host -
# basically just a wrapper around the tbadb script.
package power_ue;
use Exporter;
@ISA = ("Exporter");
@EXPORT = qw( uectrl );
#
# Commands we run
#
my $TBROOT = '@prefix@';
my $TBADB = "$TBROOT/bin/tbadb";
# Turn off line buffering on output
$| = 1;
# usage: uectrl(cmd, devices)
# cmd = { "cycle" | "on" | "off" }
# devices = list of one or more physcial ue names.
#
# Returns 0 on success. Non-zero on failure.
#
sub uectrl($@) {
my ($cmd, @devices) = @_;
my $tbadb_cmd;
my $err = 0;
#
# Call TBADB as appropriate for device. Note that we don't power down UE
# nodes. Instead, we reload them into "fastboot".
#
SWITCH: for ($cmd) {
# Just reboot the device normally. Presumably it is in
# fastboot mode if we are "powering" it on.
/^on$/i || /^cycle$/i and do {
$tbadb_cmd = "reboot";
last SWITCH;
};
# Put the device in "fastboot" mode.
/^off$/i and do {
$tbadb_cmd = "reboot fastboot";
last SWITCH;
};
# DEFAULT
print STDERR "power_ue: Unknown command: $cmd\n";
return 1;
}
foreach my $dev (@devices) {
if (system("$TBADB -n $dev $tbadb_cmd") != 0) {
print STDERR "power_ue: \"$cmd\" command failed for $dev\n";
$err = 1;
}
}
return $err;
}
1;
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