Prepare for ServerTech PDUs
cover Prepare for ServerTech PDUs
We have taken delivery of two Servertech PDUs which do (near-)zero-crossing switching. We hope these will not suffer from the relays welding shut like our APC PDUs do.
We will control these PDUs via SNMP, as we do for the APC PDUs, but each PDU manufacturer uses their own SNMP range, so adjustments to the code and configuration are needed.
These new arrangements have been tested successfully in a mockup environment.
Ian Jackson (7):
README: Fix a typo
pdu-snmp: Rename from pdu-msw
pdu-snmp: Centralise base OIDs
pdu-snmp: Refactor model handling
pdu-snmp: Support ServerTech PDUs "Pro 1/2" aka "Sentry4" PDU::snmp, PDU::msw: Rename from msw to snmp
pdu-snmp: Fix sleeping
Osstest/PDU/msw.pm | 14 +------------- Osstest/PDU/snmp.pm | 39 +++++++++++++++++++++++++++++++++++++++ README | 9 ++++++--- pdu-msw => pdu-snmp | 45 +++++++++++++++++++++++++++++++++++---------- 4 files changed, 81 insertions(+), 26 deletions(-) create mode 100644 Osstest/PDU/snmp.pm rename pdu-msw => pdu-snmp (78%)
Signature · 1 line
2.20.1
PATCH 1/7 README: Fix a typo
--- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
README +1 -1
@@ -655,7 +655,7 @@ HostProp_<host>_PowerILOM unsupported Fails whenever a power operation is needed msw [--apc6] <pdu> <port-name-regexp|port-num> - Control and APC masterswitch via SNMP. The SNMP + Control an APC masterswitch via SNMP. The SNMP community is `private'. See the `pdu-msw' script. ipmi <mgmt> [<user> [<pass> [<ipmitool options...>]]]
Signature · 1 line
2.20.1
PATCH 2/7 pdu-snmp: Rename from pdu-msw
In reply to Ian JacksonWe are going to make this script control PDUs other than APC ones.
No overall functional change for internal callers. Anyone out-of-tree using this script will need to change the name of the program they run.
--- Osstest/PDU/msw.pm | 2 +- README | 2 +- pdu-msw => pdu-snmp | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) rename pdu-msw => pdu-snmp (95%)
Osstest/PDU/msw.pm +1 -1
@@ -33,7 +33,7 @@ sub new { sub pdu_power_state { my ($mo, $on) = @_; my $onoff= $on ? "on" : "off"; - system_checked("./pdu-msw @{ $mo->{Args} } $onoff"); + system_checked("./pdu-snmp @{ $mo->{Args} } $onoff"); } 1;
README +1 -1
@@ -656,7 +656,7 @@ HostProp_<host>_PowerILOM msw [--apc6] <pdu> <port-name-regexp|port-num> Control an APC masterswitch via SNMP. The SNMP - community is `private'. See the `pdu-msw' script. + community is `private'. See the `pdu-snmp' script. ipmi <mgmt> [<user> [<pass> [<ipmitool options...>]]] Use IPMI by (by running ipmitool). <mgmt> is the name or
pdu-snmp renamed from pdu-msw +3 -3
@@ -19,7 +19,7 @@ my $usagemsg= <<END; usage: - pdu-msw SWITCH-DNS-NAME PORT-NAME-REGEXP|PORT [[delayed-]on|off|0|1|reboot] + pdu-snmp SWITCH-DNS-NAME PORT-NAME-REGEXP|PORT [[delayed-]on|off|0|1|reboot] END use strict qw(refs vars);
@@ -89,7 +89,7 @@ if ($outlet =~ m/^\d+$/) { ($t->[2] ? '*' : ''), $t->[0], $t->[1]); } - die "pdu-msw $dnsname: ". + die "pdu-snmp $dnsname: ". (@found ? "multiple ports match" : "no ports match"). "\n"; }
@@ -119,7 +119,7 @@ sub get () { sub show () { my $mean = get(); - printf "pdu-msw $dnsname: #%s \"%s\" = %s\n", $useport, $usename, $mean; + printf "pdu-snmp $dnsname: #%s \"%s\" = %s\n", $useport, $usename, $mean; return $mean; }
Signature · 1 line
2.20.1
PATCH 3/7 pdu-snmp: Centralise base OIDs
In reply to Ian JacksonDo not hardcoode .3 and .4 in the main logic.
No functional change.
--- pdu-snmp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
pdu-snmp +5 -2
@@ -27,8 +27,11 @@ use Net::SNMP; use Data::Dumper; my $community= 'private'; + my $baseoid= '.1.3.6.1.4.1.318.1.1.4.4.2.1'; my $baseoid_write= "$baseoid.3"; +my $baseoid_name= "$baseoid.4"; +my $baseoid_read= "$baseoid.3"; while (@ARGV && $ARGV[0] =~ m/^-/) { $_ = shift @ARGV;
@@ -52,7 +55,7 @@ die "SNMP error $error " unless defined $session; sub getname ($) { my ($port) = @_; - my $oid= "$baseoid.4.$port"; + my $oid= "$baseoid_name.$port"; my $res= $session->get_request($oid); if ($res) { my $name= $res->{$oid};
@@ -96,7 +99,7 @@ if ($outlet =~ m/^\d+$/) { ($useport,$usename)= @{ $found[0] }; } -my $read_oid= "$baseoid.3.$useport"; +my $read_oid= "$baseoid_read.$useport"; my $write_oid= "$baseoid_write.$useport"; my @map= (undef, qw(
Signature · 1 line
2.20.1
PATCH 4/7 pdu-snmp: Refactor model handling
In reply to Ian JacksonThis makes it easier to see waht is going on and to add new model(s).
No functional change.
--- pdu-snmp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-)
pdu-snmp +21 -6
@@ -28,15 +28,28 @@ use Data::Dumper; my $community= 'private'; -my $baseoid= '.1.3.6.1.4.1.318.1.1.4.4.2.1'; -my $baseoid_write= "$baseoid.3"; -my $baseoid_name= "$baseoid.4"; -my $baseoid_read= "$baseoid.3"; +our ($baseoid, $baseoid_write, $baseoid_name, $baseoid_read); + +sub model_msw () { + # APC MasterSwitch + $baseoid= '.1.3.6.1.4.1.318.1.1.4.4.2.1'; + $baseoid_name= "$baseoid.4"; + $baseoid_read= "$baseoid.3"; + $baseoid_write= "$baseoid.3"; +} + +sub model_apc6 () { + # APC MasterSwitch protocol version 6 (?) + model_msw(); + $baseoid_write= '.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4'; +} + +my $model_name = 'msw'; while (@ARGV && $ARGV[0] =~ m/^-/) { $_ = shift @ARGV; - if (m/^--apc6$/) { - $baseoid_write= '.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4'; + if (m/^--(\w+)$/ && ${*::}{"model_$1"}) { + $model_name= $1; } else { die "$_ ?"; }
@@ -44,6 +57,8 @@ while (@ARGV && $ARGV[0] =~ m/^-/) { if (@ARGV<2 || @ARGV>3 || $ARGV[0] =~ m/^-/) { die "bad usage\n$usagemsg"; } +${*::}{"model_$model_name"}->(); + our ($max_retries) = 16; # timeout = 0.05 * max_retries^2 our ($dnsname,$outlet,$action) = @ARGV;
Signature · 1 line
2.20.1
PATCH 5/7 pdu-snmp: Support ServerTech PDUs "Pro 1/2" aka "Sentry4"
In reply to Ian JacksonValues from Sentry4.mib, from
https://www.servertech.com/support/sentry-mib-oid-tree-downloads
Useful runes used when developing and testing, with "Sentry.mib" from
the Servertech zipfile renamed to "mibs/Sentry4-MIB":
snmpwalk -On -m Sentry4-MIB -M +:mibs/ -Ci -v 2c -c private pdu1 iso.3.6.1.4.1.1718.4 snmpwalk -m Sentry4-MIB -M +:mibs/ -Ci -v 2c -c private pdu1 iso.3.6.1.4.1.1718.4 snmptranslate -Td -m Sentry4-MIB -M +:mibs/ Sentry4-MIB::st4OutletControlAction.1.1.2
--- pdu-snmp | 7 +++++++ 1 file changed, 7 insertions(+)
pdu-snmp +7 -0
@@ -44,6 +44,13 @@ sub model_apc6 () { $baseoid_write= '.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4'; } +sub model_sentry4 () { + $baseoid = ".1.3.6.1.4.1.1718.4.1.8"; + $baseoid_name = "$baseoid.2.1.3.1.1"; # st4OutletName.1.1 + $baseoid_read = "$baseoid.3.1.1.1.1"; # st4OutletState.1.1 + $baseoid_write= "$baseoid.5.1.2.1.1"; # st4OutletControlAction.1.1 +} + my $model_name = 'msw'; while (@ARGV && $ARGV[0] =~ m/^-/) {
Signature · 1 line
2.20.1
PATCH 6/7 PDU::snmp, PDU::msw: Rename from msw to snmp
In reply to Ian JacksonRetain the old name for compatibility with existing configuration.
No change other than to messages.
--- Osstest/PDU/msw.pm | 14 +------------- Osstest/PDU/snmp.pm | 39 +++++++++++++++++++++++++++++++++++++++ README | 9 ++++++--- 3 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 Osstest/PDU/snmp.pm
Osstest/PDU/msw.pm +1 -13
@@ -22,18 +22,6 @@ use warnings; use Osstest; -use parent qw(Osstest::PDU::unsupported); - -sub new { - my ($class, $ho, $methname, @args) = @_; - - return bless { Args => \@args }, $class; -} - -sub pdu_power_state { - my ($mo, $on) = @_; - my $onoff= $on ? "on" : "off"; - system_checked("./pdu-snmp @{ $mo->{Args} } $onoff"); -} +use parent qw(Osstest::PDU::snmp); 1;
Osstest/PDU/snmp.pm new file +39 -0
@@ -0,0 +1,39 @@ +# This is part of "osstest", an automated testing framework for Xen. +# Copyright (C) 2009-2013 Citrix Inc. +# +# This program 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 program 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 program. If not, see <http://www.gnu.org/licenses/>. + + +package Osstest::PDU::snmp; + +use strict; +use warnings; + +use Osstest; + +use parent qw(Osstest::PDU::unsupported); + +sub new { + my ($class, $ho, $methname, @args) = @_; + + return bless { Args => \@args }, $class; +} + +sub pdu_power_state { + my ($mo, $on) = @_; + my $onoff= $on ? "on" : "off"; + system_checked("./pdu-snmp @{ $mo->{Args} } $onoff"); +} + +1;
README +6 -3
@@ -654,9 +654,9 @@ HostProp_<host>_PowerILOM manual Asks the user on the controlling terminal unsupported Fails whenever a power operation is needed - msw [--apc6] <pdu> <port-name-regexp|port-num> - Control an APC masterswitch via SNMP. The SNMP - community is `private'. See the `pdu-snmp' script. + snmp --<model> <pdu> <port-name-regexp|port-num> + Control a PDU via SNMP. The SNMP community is `private'. + See the `pdu-snmp' script for supported model names. ipmi <mgmt> [<user> [<pass> [<ipmitool options...>]]] Use IPMI by (by running ipmitool). <mgmt> is the name or
@@ -667,6 +667,9 @@ HostProp_<host>_PowerILOM Does nothing if `on|off|both' is inapplicable, and has less error checking and less defaulting than ipmi. + msw .... + Deprecated alias for snmp. + Supported specially are: <delay>
Signature · 1 line
2.20.1
PATCH 7/7 pdu-snmp: Fix sleeping
In reply to Ian Jacksonsleep takes only an integer. We have to use select to sleep for fractions of a second.
--- pdu-snmp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
pdu-snmp +1 -1
@@ -172,7 +172,7 @@ if (!defined $action) { my $retries = 0; for (;;) { set($valset); - sleep $retries * 0.1; + select undef,undef,undef, $retries * 0.1; print "now: "; my $got = show(); if ($got eq $map[$valset]) { last; } if ($map[$valset] !~ m{^(?:off|on)$}) {
Signature · 1 line
2.20.1