From 6c0e696eb3fa74645a269e8449829aecaf41200c Mon Sep 17 00:00:00 2001 From: Marek 'marx' Grac Date: Thu, 18 Jun 2015 18:38:04 +0200 Subject: [PATCH 1/3] fence_emerson: New fence agent for Emerson's devices MPX and MPH2 Thanks to Emerson Network Power Resolves: rhbz#1171732 --- configure.ac | 1 + fence/agents/emerson/Makefile.am | 17 ++++ fence/agents/emerson/fence_emerson.py | 67 ++++++++++++++ tests/data/metadata/fence_emerson.xml | 165 ++++++++++++++++++++++++++++++++++ 4 files changed, 250 insertions(+) create mode 100644 fence/agents/emerson/Makefile.am create mode 100644 fence/agents/emerson/fence_emerson.py create mode 100644 tests/data/metadata/fence_emerson.xml diff --git a/configure.ac b/configure.ac index 9d996d3..7abd701 100644 --- a/configure.ac +++ b/configure.ac @@ -272,6 +272,7 @@ AC_CONFIG_FILES([Makefile fence/agents/drac5/Makefile fence/agents/dummy/Makefile fence/agents/eaton_snmp/Makefile + fence/agents/emerson/Makefile fence/agents/eps/Makefile fence/agents/hpblade/Makefile fence/agents/ibmblade/Makefile diff --git a/fence/agents/emerson/Makefile.am b/fence/agents/emerson/Makefile.am new file mode 100644 index 0000000..f7e5497 --- /dev/null +++ b/fence/agents/emerson/Makefile.am @@ -0,0 +1,17 @@ +MAINTAINERCLEANFILES = Makefile.in + +TARGET = fence_emerson + +SRC = $(TARGET).py + +EXTRA_DIST = $(SRC) + +sbin_SCRIPTS = $(TARGET) + +man_MANS = $(TARGET).8 + +FENCE_TEST_ARGS = -l test -p test -a test -n 1 + +include $(top_srcdir)/make/fencebuild.mk +include $(top_srcdir)/make/fenceman.mk +include $(top_srcdir)/make/agentpycheck.mk diff --git a/fence/agents/emerson/fence_emerson.py b/fence/agents/emerson/fence_emerson.py new file mode 100644 index 0000000..1ef911b --- /dev/null +++ b/fence/agents/emerson/fence_emerson.py @@ -0,0 +1,67 @@ +#!/usr/bin/python -tt + +import sys +import atexit +sys.path.append("@FENCEAGENTSLIBDIR@") +from fencing import * +from fencing_snmp import FencingSnmp + +#BEGIN_VERSION_GENERATION +RELEASE_VERSION="Emerson SNMP fence agent" +REDHAT_COPYRIGHT="" +BUILD_DATE="" +#END_VERSION_GENERATION + +### CONSTANTS ### +STATUSES_OID = ".1.3.6.1.4.1.476.1.42.3.8.50.20.1.95" +CONTROL_OID = ".1.3.6.1.4.1.476.1.42.3.8.50.20.1.100" +NAMES_OID = ".1.3.6.1.4.1.476.1.42.3.8.50.20.1.10" + +# Status constants returned as value from SNMP +STATUS_DOWN = 1 +STATUS_UP = 2 + +# Status constants to set as value to SNMP +STATUS_SET_OFF = 0 +STATUS_SET_ON = 1 + +def get_power_status(conn, options): + (_, status) = conn.get("%s.%s"% (STATUSES_OID, options["--plug"])) + return status == str(STATUS_UP) and "on" or "off" + +def set_power_status(conn, options): + conn.set("%s.%s" % (CONTROL_OID, options["--plug"]), + (options["--action"] == "on" and STATUS_SET_ON or STATUS_SET_OFF)) + +def get_outlets_status(conn, _): + result = {} + res_outlet = conn.walk(STATUSES_OID, 30) + + for outlet_info in res_outlet: + port_num = ".".join(outlet_info[0].split('.')[-3:]) + port_alias = conn.get("%s.%s"% (NAMES_OID, port_num))[1] + port_status = (outlet_info[1] == str(STATUS_UP) and "on" or "off") + result[port_num] = (port_alias, port_status) + return result + +def main(): + device_opt = ["ipaddr", "login", "passwd", "no_login", "no_password", \ + "port", "snmp_version", "community"] + + atexit.register(atexit_handler) + + options = check_input(device_opt, process_input(device_opt)) + + docs = {} + docs["shortdesc"] = "Fence agent for Emerson over SNMP" + docs["longdesc"] = "fence_emerson is an I/O Fencing agent \ + which can be used with MPX and MPH2 managed rack PDU." + docs["vendorurl"] = "http://www.emersonnetworkpower.com" + show_docs(options, docs) + + # Operate the fencing device + result = fence_action(FencingSnmp(options), options, set_power_status, get_power_status, get_outlets_status) + + sys.exit(result) +if __name__ == "__main__": + main() diff --git a/tests/data/metadata/fence_emerson.xml b/tests/data/metadata/fence_emerson.xml new file mode 100644 index 0000000..3b49b56 --- /dev/null +++ b/tests/data/metadata/fence_emerson.xml @@ -0,0 +1,165 @@ + + +fence_emerson is an I/O Fencing agent which can be used with MPX and MPH2 managed rack PDU. +http://www.emersonnetworkpower.com + + + + + Fencing Action + + + + + Set the community string + + + + + Forces agent to use IPv4 addresses only + + + + + Forces agent to use IPv6 addresses only + + + + + IP Address or Hostname + + + + + TCP/UDP port to use for connection with device + + + + + Login Name + + + + + Login password or passphrase + + + + + Script to retrieve password + + + + + Physical plug number, name of virtual machine or UUID + + + + + + Set authentication protocol (MD5|SHA) + + + + + Set privacy protocol password + + + + + Script to run to retrieve privacy password + + + + + + Set privacy protocol (DES|AES) + + + + + + Set security level (noAuthNoPriv|authNoPriv|authPriv) + + + + + + Specifies SNMP version to use (1,2c,3) + + + + + Verbose mode + + + + + Write debug information to given file + + + + + Display version information and exit + + + + + Display help and exit + + + + + Separator for CSV created by operation list + + + + + Wait X seconds before fencing is started + + + + + Wait X seconds for cmd prompt after login + + + + + Test X seconds for status change after ON/OFF + + + + + Wait X seconds after issuing ON/OFF + + + + + Wait X seconds for cmd prompt after issuing command + + + + + Count of attempts to retry power on + + + + + + + + + + + + -- 1.9.3