Commit f66517f5 authored by chuck cranor's avatar chuck cranor

add power support for IBM BladeCenter chassis

Add power support for the IBM BladeCenter chassis (power_ibmbc.pm).
This is the chassis used in the old Roadrunner cluster at LANL.  Each
chassis has 14 blades in it.  The management IP API is accessed from
boss via ssh.  A ssh keypair should be setup to allow for passwordless
ssh access.  We assume the admin has installed the keypair on boss
(in /usr/testbed/etc/{ibmbc,ibmbc.pub}) and on each chassis for
the standard "USERID" account.  The key files should be owned by
an account like "operator" to avoid ssh complaining about key file
permissions in some cases.

The module will end up running commands like:

      ssh USERID@chassis-mm power -on -T 'blade[1]'
      ssh USERID@chassis-mm power -off -T 'blade[1]'
      ssh USERID@chassis-mm power -cycle -T 'blade[1]'

(we'll add "-i /usr/testbed/etc/ibmbc" to "ssh" if the key file is present)

using this requires the following "mysql tbdb" cmds on boss:
  one-time operation:
     insert into node_types (class,type) values ('power', 'ibmbc');

  per-chassis operations:
     # assumes that "rr1" is blade1 of chassis "bch1"
     insert into nodes (node_id,type,phys_nodeid,role,priority,status,
                        eventstate,op_mode,allocstate)
     values ('bch1', 'ibmbc', 'bch1', 'powerctrl', 10001, 'down',
                        'ISUP', 'NONE', 'FREE_DIRTY');

     # adds IP of the chassis management module
     insert into interfaces (node_id,IP,mask,interface_type,iface,role) values
          ('bch1', '172.19.148.61', '255.255.240.0','','eth0','other');

  per-blade operation:
     insert into outlets (node_id,power_id,outlet)
            values ('rr1', 'bch1', 1);   # outlet 1==blade1, etc.
parent a5b3a465
......@@ -117,7 +117,8 @@ LIB_STUFF = libtbsetup.pm exitonwarn.pm libtestbed.pm \
power_ilo.pm libvtop.pm libptop.pm \
libossetup.pm \
power_ipmi.pm libosload_new.pm libosload_switch.pm \
libosload_ue.pm libossetup_switch.pm power_icebox.pm \
libosload_ue.pm libossetup_switch.pm power_ibmbc.pm \
power_icebox.pm \
libvtop_stable.pm libvtop_test.pm \
libosload_dell_s3048.pm libosload_dell_s4048.pm \
libosload_mlnx_sn2410.pm libosload_dell.pm \
......
Power support for the IBM BladeCenter chassis (power_ibmbc.pm).
This is the chassis used in the old Roadrunner cluster at LANL. Each
chassis has 14 blades in it. The management IP API is accessed from
boss via ssh. A ssh keypair should be setup to allow for passwordless
ssh access. We assume the admin has installed the keypair on boss
(in /usr/testbed/etc/{ibmbc,ibmbc.pub}) and on each chassis for
the standard "USERID" account. The key files should be owned by
an account like "operator" to avoid ssh complaining about key file
permissions in some cases.
The module will end up running commands like:
ssh USERID@chassis-mm power -on -T 'blade[1]'
ssh USERID@chassis-mm power -off -T 'blade[1]'
ssh USERID@chassis-mm power -cycle -T 'blade[1]'
(we'll add "-i /usr/testbed/etc/ibmbc" to "ssh" if the key file is present)
using this requires the following "mysql tbdb" cmds on boss:
one-time operation:
insert into node_types (class,type) values ('power', 'ibmbc');
per-chassis operations:
# assumes that "rr1" is blade1 of chassis "bch1"
insert into nodes (node_id,type,phys_nodeid,role,priority,status,
eventstate,op_mode,allocstate)
values ('bch1', 'ibmbc', 'bch1', 'powerctrl', 10001, 'down',
'ISUP', 'NONE', 'FREE_DIRTY');
# adds IP of the chassis management module
insert into interfaces (node_id,IP,mask,interface_type,iface,role) values
('bch1', '172.19.148.61', '255.255.240.0','','eth0','other');
per-blade operation:
insert into outlets (node_id,power_id,outlet)
values ('rr1', 'bch1', 1); # outlet 1==blade1, etc.
......@@ -51,6 +51,7 @@ use power_sgmote;
use power_mail;
use power_whol;
use power_ilo;
use power_ibmbc;
use power_icebox;
use power_apc;
use power_raritan;
......@@ -414,6 +415,19 @@ foreach my $power_id (keys %outlets) {
}
}
}
elsif ($type eq "ibmbc") {
my $device = new power_ibmbc($IP,$verbose);
if (!defined $device) {
warn "Unable to contact controller for $nodestr. Skipping...\n";
next;
} else {
print "Calling device->power($op,@outlets)\n" if $verbose > 1;
if ($device->power($op,@outlets)) {
print "Control of $nodestr failed.\n";
$errors++;
}
}
}
elsif ($type eq "icebox") {
my $device = new power_icebox($IP,$verbose);
if (!defined $device) {
......@@ -778,7 +792,28 @@ sub dostatus(@) {
for my $ctrl (@nwanted) {
my %status;
if ($ctrls{$ctrl} eq 'icebox') {
if ($ctrls{$ctrl} eq 'ibmbc') {
my $device = new power_ibmbc($IPs{$ctrl}, $verbose);
if (!defined $device) {
warn "Unable to contact controller $ctrl.\n";
$errors++;
next;
} else {
print "Calling device->status()\n"
if $verbose > 1;
if ($device->status(\%status)) {
print "Could not get status for $ctrl.\n";
$errors++;
next;
}
for my $outlet (1..14) {
my $ostr = "outlet$outlet";
print "$ctrl Outlet $outlet: ", $status{$ostr}, "\n"
if (defined($status{$ostr}));
}
print "\n";
}
} elsif ($ctrls{$ctrl} eq 'icebox') {
my $device = new power_icebox($IPs{$ctrl}, $verbose);
if (!defined $device) {
warn "Unable to contact controller $ctrl.\n";
......
#! /usr/bin/perl -w
#
# Copyright (c) 2014, Carnegie Mellon University.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the University nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#
# power_ibmbc.pm IBM BladeCenter emulab power manager
# 16-Dec-2014 chuck@ece.cmu.edu
#
#
# this should be pretty simple. put root's emulab ssh key in the
# USERID's account's authorized_keys, then we can simply ssh over
# to the manager to perform power operations
#
package power_ibmbc;
use strict;
use IPC::Open2;
use POSIX;
#
# configuration
#
my($TB, $USERID, $SSHKEY, $TIMEOUT);
$TB = "@prefix@";
$USERID = 'USERID'; # userid on remote, this the default
$SSHKEY = "$TB/etc/ibmbc"; # will use root key if not present
$TIMEOUT = 10; # 10 second timeout on ssh
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin'; # untaint path
#
# helper fns
#
#
# twaitpid(seconds,pidspec): timed wait system call.
#
# seconds: undef - disable timeout, could wait forever
# < 0 - invalid param, converted to zero
# 0 - poll for process, don't block
# > 0 - max wait time
#
# pidspec: -1 - wait for any child process
# 0 - wait for any child in process group
# > 0 - wait for a specific pid
# < -1 - wait for any process in absolute value process group
#
# return values:
# -1 - no processes that match pidspec that we could wait for
# 0 - timed out before matching process could exit
# pid - process id of process that we waited for
#
# note that you can only wait for your own child processes (i.e.
# you can't wait for other people's processes to exit, that gives -1).
#
sub twaitpid {
my($secs, $pid) = @_;
my($rv, $wval);
$secs = 0 if ($secs < 0); # usage error, convert to poll
return(waitpid($pid, 0)) if (!defined($secs));
return(waitpid($pid, WNOHANG)) if ($secs == 0);
# must do this in an eval to trap the timeout signal
$rv = eval {
local $SIG{'ALRM'} = sub { die "timeout" };
alarm($secs);
$wval = waitpid($pid, 0);
alarm(0);
$wval;
};
$rv = 0 if (!defined($rv)); # happens if timeout fires
return($rv);
}
#
# timed_cmd(timeout, cmd...): run a cmd w/time limit.
# return value (where exit-value is >= 0):
# command ran: [exit-value, outline1, outline2, ... ]
# run failed: [-1, error-message]
#
sub timed_cmd {
my($secs) = shift;
my(@cmd) = @_;
my(@rv, $endat, $childpid, $rd, $wr);
my($rin, $rout, $to, $nfound, $outbuf, $cnt, $waitrv);
# init status and compute timeout (if enabled)
$rv[0] = undef;
$endat = (defined($secs)) ? (time + $secs) : undef;
# fork child process to run the command
$childpid = open2($rd, $wr, @cmd);
if ($childpid <= 0) {
return([-1, "open2 failed"]);
}
# parent loops for output
$outbuf = '';
while (1) {
$rin = '';
vec($rin, fileno($rd), 1) = 1;
if (defined($endat)) {
$to = $endat - time;
$to = 0 if ($to < 0);
} else {
undef($to);
}
$nfound = select($rout=$rin, undef, undef, $to);
if ($nfound < 1) { # select error, or timeout error
kill 9, $childpid;
@rv = (-1, (($nfound < 0) ? "select error $!" : "timeout"));
last;
}
$cnt = sysread($rd, $outbuf, 1024, length($outbuf));
# refactor output into lines and push on @rv
while (($_ = index($outbuf, "\n")) != -1) {
push(@rv, substr($outbuf, 0, $_));
$outbuf = substr($outbuf, $_ + 1);
}
if ($cnt < 1) { # eof
push(@rv, $outbuf) if (length($outbuf)); # residual
last;
}
}
#
# dispose of the fds, and collect the wait status.
# we use twaitpid to handle the rare case where child closes stdout
# but doesn't actually exit (it shouldn't do that).
#
close($rd);
close($wr);
$waitrv = twaitpid(1, $childpid);
if ($waitrv != $childpid) {
kill 'KILL', $childpid; # it is sure to be dead now
twaitpid(10, $childpid);
}
$rv[0] = $? >> 8 unless (defined($rv[0])); # if no error -1 in it
return(\@rv);
}
#
# new(obj,dev,debug): create object. the object is a blessed hash
# where we store the device name and debug level.
#
sub new($$;$) {
my($class, $dev, $dbg, $obj);
$class = shift;
$class = ref($class) if (ref($class)); # save class for blessing
($dev, $dbg) = @_;
$dbg = 0 unless (defined($dbg));
print "power_ibmbc: new(dev=$dev, dbg=$dbg)\n" if ($dbg);
$obj = { 'DEBUG' => $dbg, 'DEVICENAME' => $dev };
bless($obj, $class);
return($obj);
}
#
# power(obj,op,ports): power operation. return error count.
#
sub power {
my($self, $op, @ports) = @_;
my($mm_host, @sk, $port, $rv, $blade, $errcnt);
$mm_host = $USERID . '@' . $$self{'DEVICENAME'};
@sk = ("-i", $SSHKEY) if (-r $SSHKEY);
#
# maps to this:
# ssh USERID@narwhal4-mm power -on -T 'blade[2]'
# ssh USERID@narwhal4-mm power -off -T 'blade[2]'
# ssh USERID@narwhal4-mm power -cycle -T 'blade[2]'
#
foreach $port (@ports) {
$blade = sprintf 'system:blade[%d]', $port;
$rv = timed_cmd($TIMEOUT, "/usr/bin/ssh", @sk, $mm_host,
"power", "-$op", "-T", $blade);
$errcnt++ if (ref($rv) ne 'ARRAY' || $$rv[0] != 0);
print "power_ibmbc: result: ", join("\n", @$rv), "\n"
if ($$self{'DEBUG'} && ref($rv) eq 'ARRAY');
}
return($errcnt);
}
#
# status(obj,\%sthref): power status into sthref. return error count.
#
sub status {
my($self, $href) = @_;
my($mm_host, @sk, $rv, $ln, %present, @outs, $bl, $blade, $state, $got);
$mm_host = $USERID . '@' . $$self{'DEVICENAME'};
@sk = ("-i", $SSHKEY) if (-r $SSHKEY);
$rv = timed_cmd($TIMEOUT, "/usr/bin/ssh", @sk, $mm_host,
"list", "-l", "all");
return(1) unless ($$rv[0] == 0);
shift(@$rv); # discard status
foreach $ln (@$rv) {
next unless ($ln =~ /^\s*blade\[(\d+)\]/);
$present{$1} = 1;
}
@outs = sort { $a <=> $b } keys %present;
print "power_ibmbc: PRESENT: ",
join(' ', @outs), "\n" if ($$self{'DEBUG'});
#
# XXX: is there a command that can give us all the blade's
# status in one ssh command?
#
foreach $bl (@outs) {
$blade = sprintf 'system:blade[%d]', $bl;
$rv = timed_cmd($TIMEOUT, "/usr/bin/ssh", @sk, $mm_host,
"power", "-T", $blade, "-state");
$state = 'Unknown';
if ($$rv[0] == 0) {
$got = $$rv[$#$rv];
$got = $1 if ($got =~ /^(\w+)/);
$state = $got if ($got eq 'On' || $got eq 'Off');
}
$$href{"outlet$bl"} = $state;
print "power_ibmbc: blade/outlet $bl = $state\n" if ($$self{'DEBUG'});
}
return(0);
}
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