Commit b01d264c authored by Mike Hibler's avatar Mike Hibler

Basic power on/off/cycling support for Raritan controllers.

Pretty much the same as for APC, only different OIDs. Could not get
the symbolic names to work, so it is using hardcoded raw OIDs right
now. Still need to add support for power metering.
parent b20912b5
#
# Copyright (c) 2000-2018 University of Utah and the Flux Group.
# Copyright (c) 2000-2019 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -107,7 +107,7 @@ LIBEXEC_STUFF = wanlinksolve wanlinkinfo os_setup mkexpdir console_setup \
LIB_STUFF = libtbsetup.pm exitonwarn.pm libtestbed.pm \
power_rpc27.pm power_apc.pm power_ue.pm power_powduino.pm \
power_sgmote.pm power_racktivity.pm \
power_sgmote.pm power_racktivity.pm power_raritan.pm \
libaudit.pm libreboot.pm libosload.pm libtestbed.py \
libadminmfs.pm libtblog.pm libtblog_simple.pm libArchive.pm \
power_mail.pm power_whol.pm Template.pm power_rmcp.pm \
......
#!/usr/bin/perl -w
#
# Copyright (c) 2000-2018 University of Utah and the Flux Group.
# Copyright (c) 2000-2019 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -53,6 +53,7 @@ use power_whol;
use power_ilo;
use power_icebox;
use power_apc;
use power_raritan;
use power_racktivity;
use power_ue;
use power_powduino;
......@@ -436,6 +437,19 @@ foreach my $power_id (keys %outlets) {
$errors++;
}
}
} elsif ($type eq "Raritan") {
my $device = new power_raritan($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 "RACKTIVITY") {
my $device = new power_racktivity($IP,$verbose);
if (!defined $device) {
......@@ -805,6 +819,29 @@ sub dostatus(@) {
if (defined($status{$ostr}));
}
print "\n";
} elsif ($ctrls{$ctrl} eq "Raritan") {
my $device = new power_raritan($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;
}
}
print "$ctrl Current: ", $status{current}, " Amps\n"
if defined($status{current});
for my $outlet (1..24) {
my $ostr = "outlet$outlet";
print "$ctrl Outlet $outlet: ", $status{$ostr}, "\n"
if (defined($status{$ostr}));
}
print "\n";
} elsif ($ctrls{$ctrl} =~ /^RPC/) {
if (rpc27status($ctrl,\%status)) {
print "Could not get status for $ctrl.\n";
......
#!/usr/bin/perl -w
#
# Copyright (c) 2000-2019 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/>.
#
# }}}
#
#
# snmpit module for Raritan PX2 power controllers
#
# supports new(ip), power(on|off|cyc[le],port), status
#
package power_raritan;
$| = 1; # Turn off line buffering on output
use SNMP;
use strict;
use Data::Dumper;
#
# XXX for configurations in which Raritan unit always returns error
# even when it works.
#
my $ignore_errors = 0;
sub new($$;$) {
# The next two lines are some voodoo taken from perltoot(1)
my $proto = shift;
my $class = ref($proto) || $proto;
my $devicename = shift;
my $debug = shift;
if (!defined($debug)) {
$debug = 0;
}
if ($debug) {
print "power_raritan module initializing... debug level $debug\n";
}
$SNMP::debugging = ($debug - 5) if $debug > 5;
my $mibpath = "/usr/local/share/snmp/mibs";
&SNMP::addMibDirs($mibpath);
&SNMP::addMibFiles("$mibpath/SNMPv2-SMI.txt",
"$mibpath/SNMPv2-MIB.txt",
"$mibpath/RFC1155-SMI.txt",
"$mibpath/PDU2-MIB.txt");
$SNMP::save_descriptions = 1; # must be set prior to mib initialization
SNMP::initMib(); # parses default list of Mib modules
$SNMP::use_enums = 1; #use enum values instead of only ints
print "Opening SNMP session to $devicename..." if $debug;
my $sess =new SNMP::Session(DestHost => $devicename, Community => 'private', Version => '1');
if (!defined($sess)) {
warn("ERROR: Unable to connect to $devicename via SNMP\n");
return undef;
}
my $self = {};
$self->{SESS} = $sess;
$self->{DEBUG} = $debug;
$self->{DEVICENAME} = $devicename;
bless($self,$class);
return $self;
}
my %CtlOIDS = (
# XXX symbolic names do not work for some reason
# default => ["switchingOperation.1", "on", "off", "cycle"]
default => [".1.3.6.1.4.1.13742.6.4.1.2.1.2.1", "on", "off", "cycle"]
);
sub power {
my $self = shift;
my $op = shift;
my @ports = @_;
my $oids = $CtlOIDS{"default"};
my $type = SNMP::translateObj($self->{SESS}->get("sysObjectID.0"));
print "Got type '$type'\n" if $self->{DEBUG};
if ($op eq "on") { $op = @$oids[1]; }
elsif ($op eq "off") { $op = @$oids[2]; }
elsif ($op =~ /cyc/) { $op = @$oids[3]; }
my $errors = 0;
foreach my $port (@ports) {
print STDERR "**** Controlling port $port\n" if ($self->{DEBUG} > 1);
print STDERR "OID is: @$oids[0], operation is $op\n" if ($self->{DEBUG} > 2);
if ($self->UpdateField(@$oids[0],$port,$op)) {
print STDERR "Outlet #$port control failed.\n";
$errors++;
}
}
return $errors;
}
sub status {
my $self = shift;
my $statusp = shift;
my %status;
my $noutletsOID = ".1.3.6.1.4.1.13742.6.3.2.2.1.4.1";
my $StatOID = ".1.3.6.1.4.1.13742.6.4.1.2.1.3.1";
print STDERR "**** Getting status for ports\n" if ($self->{DEBUG} > 1);
my $noutlets = $self->{SESS}->get($noutletsOID);
if (!defined($noutlets)) {
print STDERR $self->{DEVICENAME}, ": no answer from device\n";
return 1;
}
print STDERR "outlets: $noutlets\n" if ($self->{DEBUG} > 2);
my @OIDs = ();
foreach my $n (1..$noutlets) {
push @OIDs, [$StatOID,$n];
}
my $vars = new SNMP::VarList(@OIDs);
my @vals = $self->{SESS}->get($vars);
if (!@vals) {
print STDERR $self->{DEVICENAME}, ": no answer from device\n";
return 1;
}
print("Status is '", join(' ', @vals), "'\n") if $self->{DEBUG};
if ($statusp) {
my $o = 1;
foreach my $ostat (@vals) {
my $outlet = "outlet$o";
$status{$outlet} = $ostat;
$o++;
}
%$statusp = %status;
}
return 0;
}
sub UpdateField {
my ($self,$OID,$port,$val) = @_;
print "sess=$self->{SESS} $OID $port $val\n" if $self->{DEBUG} > 1;
my $Status = 0;
my $retval;
print "Checking port $port of $self->{DEVICENAME} for $val..." if $self->{DEBUG};
$Status = $self->{SESS}->get([[$OID,$port]]);
if (!defined $Status) {
print STDERR "Port $port, change to $val: No answer from device\n";
return 1;
} else {
print "Okay.\nPort $port was $Status\n" if $self->{DEBUG};
if ($Status ne $val) {
print "Setting $port to $val..." if $self->{DEBUG};
$retval = $self->{SESS}->set([[$OID,$port,$val,"INTEGER"]]);
$retval = "" if (!defined($retval));
print "Set returned '$retval'\n" if $self->{DEBUG};
if ($retval) {
return 0;
}
# XXX warn, but otherwise ignore errors
if ($ignore_errors) {
print STDERR "WARNING: $port '$val' failed, ignoring\n";
return 0;
}
return 1;
}
return 0;
}
}
# End with true
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