Commit beed30e3 authored by Leigh Stoller's avatar Leigh Stoller

Minor modifications to use Dave's ilO module with the Drac widgets.

Everything else works the same; stick the required entries in the
interfaces tables and the outlets_remoteauth table.

Oh, I ripped out the existing parallelizzation code and replaced it
with the library code emutil::ParRun(), which is slowly making its way
across the system, replacing all the one-off cases of using fork to
parallelize things. Very handy.
parent b8108ba9
......@@ -295,6 +295,7 @@ foreach my $power_id (keys %outlets) {
if ($power_id eq "mail" || $power_id =~ /^whol-/
|| $power_id=~ /^rmcp-/
|| $power_id eq 'drac'
|| $power_id eq 'ilo' || $power_id eq 'ilo2') {
$type = $power_id;
$IP = "";
......@@ -359,7 +360,7 @@ foreach my $power_id (keys %outlets) {
print "Control of $nodestr failed.\n"; ++$exitval;
++$errors;
}
} elsif ($type eq 'ilo2' || $type eq 'ilo') {
} elsif ($type eq 'ilo2' || $type eq 'ilo' || $type eq 'drac') {
if (iloctrl($type,$op,@nodes)) {
print "Control of $nodestr failed.\n"; ++$exitval;
++$errors;
......
......@@ -2,12 +2,13 @@
#
# EMULAB-COPYRIGHT
# Copyright (c) 2008 University of Utah and the Flux Group.
# Copyright (c) 2008-2010 University of Utah and the Flux Group.
# All rights reserved.
#
#
# Handle iLO or iLO 2 remote power control.
# Also handle DRAC since its so similar.
# Node must have an interface such that role='other' and
# interface_type='ilo2' or 'ilo'.
#
......@@ -22,12 +23,13 @@ use Exporter;
use lib "@prefix@/lib";
use libdb;
use emutil;
use IO::Pty;
use POSIX qw(setsid);
use POSIX ":sys_wait_h";
my $debug = 0;
my $debug = 1;
# Always parallelize for now cause we are vulnerable to timeouts with
# unreachable nodes or weird iLO crap.
my $parallelize = 1;
......@@ -67,7 +69,7 @@ sub iloctrl($$@) {
" where node_id='$n' and role='other'" .
" and interface_type='$type'");
if (!defined($res) || !$res || $res->num_rows() == 0) {
warn "No $type interface for $n; cannot find iLO IP!\n";
warn "No $type interface for $n; cannot find $type IP!\n";
++$exitval;
next;
}
......@@ -83,47 +85,48 @@ sub iloctrl($$@) {
}
my ($krole,$kuid,$kkey) = $res->fetchrow();
$ilo_nodeinfo{$n} = [ $IP,$krole,$kuid,$kkey ];
$ilo_nodeinfo{$n} = [ $n,$IP,$krole,$kuid,$kkey ];
}
my %kids = ();
my $timeout = 30;
for my $n (keys(%ilo_nodeinfo)) {
my ($IP,$krole,$kuid,$kkey) = @{$ilo_nodeinfo{$n}};
if ($parallelize) {
if (my $pid = fork()) {
$kids{$pid} = 1;
}
else {
my $tret;
eval {
$tret = iloexec($n,$type,$cmd,$IP,$krole,$kuid,$kkey,
$timeout);
};
if ($@) {
print "$@";
exit -1;
}
if ($parallelize) {
my $coderef = sub {
my ($n,$IP,$krole,$kuid,$kkey) = @{ $_[0] };
my $tret;
eval {
$tret = iloexec($n,$type,$cmd,$IP,$krole,$kuid,$kkey,$timeout);
};
if ($@) {
print "$@";
return -1;
}
return 0;
};
my @results = ();
my @ilos = values(%ilo_nodeinfo);
if (ParRun(undef, \@results, $coderef, @ilos)) {
print STDERR "*** power_ilo: Internal error in ParRun()!\n";
return -1;
}
else {
if (iloexec($n,$type,$cmd,$IP,$krole,$kuid,$kkey,$timeout)) {
++$exitval;
}
#
# Check the exit codes.
#
foreach my $result (@results) {
++$exitval
if ($result != 0);
}
}
else {
for my $key (keys(%ilo_nodeinfo)) {
my ($n,$IP,$krole,$kuid,$kkey) = @{$ilo_nodeinfo{$key}};
# grab child exit vals
if ($parallelize) {
while (wait() > 0) {
if ($?) {
if (iloexec($n,$type,$cmd,$IP,$krole,$kuid,$kkey,$timeout)) {
++$exitval;
}
}
}
return $exitval;
}
......@@ -147,24 +150,28 @@ sub iloexec($$$$$$$;$) {
my $power_cmd;
if ($cmd eq 'cycle') {
$power_cmd = 'power reset';
$power_cmd = ($type eq "drac" ?
'racadm serveraction powercycle' : 'power reset');
}
elsif ($cmd eq 'reset') {
$power_cmd = 'power warm';
$power_cmd = ($type eq "drac" ?
'racadm serveraction hardreset' : 'power warm');
}
elsif ($cmd eq 'on') {
$power_cmd = 'power on';
$power_cmd = ($type eq "drac" ?
'racadm serveraction powerup' : 'power on');
}
elsif ($cmd eq 'off') {
$power_cmd = 'power off';
$power_cmd = ($type eq "drac" ?
'racadm serveraction powerdown' : 'power off');
}
else {
warn "Bad iLO power command $cmd";
return -11;
}
if ($type ne 'ilo' && $type ne 'ilo2') {
warn "Unsupported iLO type $type!";
if ($type ne 'ilo' && $type ne 'ilo2' && $type ne "drac") {
warn "Unsupported iLO/DRAC type $type!";
return -7;
}
......@@ -175,7 +182,13 @@ sub iloexec($$$$$$$;$) {
if ($key ne '') {
$ssh_cmd .= " -i '$key'";
}
@expect_seq = (['hpiLO-> ',$power_cmd],['hpiLO-> ','exit']);
if ($type eq "drac") {
@expect_seq = (['\$ ', $power_cmd],
['\$ ', 'exit']);
}
else {
@expect_seq = (['hpiLO-> ',$power_cmd],['hpiLO-> ','exit']);
}
}
elsif ($key_role eq 'ssh-passwd') {
$ssh_cmd .= " -o PubkeyAuthentication=no";
......@@ -184,8 +197,15 @@ sub iloexec($$$$$$$;$) {
warn "iLO key_role ssh-passwd specified, but no passwd!";
return -13;
}
@expect_seq = (['password: ',$key],['hpiLO-> ',$power_cmd],
['hpiLO-> ','exit']);
if ($type eq "drac") {
@expect_seq = (['password: ', $key],
['\$ ', $power_cmd],
['\$ ', 'exit']);
}
else {
@expect_seq = (['password: ',$key],['hpiLO-> ',$power_cmd],
['hpiLO-> ','exit']);
}
}
else {
warn "Unsupported key_role $key_role!";
......
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