Blob Blame History Raw
From 6c0e696eb3fa74645a269e8449829aecaf41200c Mon Sep 17 00:00:00 2001
From: Marek 'marx' Grac <mgrac@redhat.com>
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 @@
+<?xml version="1.0" ?>
+<resource-agent name="fence_emerson" shortdesc="Fence agent for Emerson over SNMP" >
+<longdesc>fence_emerson is an I/O Fencing agent 	which can be used with MPX and MPH2 managed rack PDU.</longdesc>
+<vendor-url>http://www.emersonnetworkpower.com</vendor-url>
+<parameters>
+	<parameter name="action" unique="0" required="1">
+		<getopt mixed="-o, --action=[action]" />
+		<content type="string" default="reboot"  />
+		<shortdesc lang="en">Fencing Action</shortdesc>
+	</parameter>
+	<parameter name="community" unique="0" required="0">
+		<getopt mixed="-c, --community=[community]" />
+		<content type="string"  />
+		<shortdesc lang="en">Set the community string</shortdesc>
+	</parameter>
+	<parameter name="inet4_only" unique="0" required="0">
+		<getopt mixed="-4, --inet4-only" />
+		<content type="boolean"  />
+		<shortdesc lang="en">Forces agent to use IPv4 addresses only</shortdesc>
+	</parameter>
+	<parameter name="inet6_only" unique="0" required="0">
+		<getopt mixed="-6, --inet6-only" />
+		<content type="boolean"  />
+		<shortdesc lang="en">Forces agent to use IPv6 addresses only</shortdesc>
+	</parameter>
+	<parameter name="ipaddr" unique="0" required="1">
+		<getopt mixed="-a, --ip=[ip]" />
+		<content type="string"  />
+		<shortdesc lang="en">IP Address or Hostname</shortdesc>
+	</parameter>
+	<parameter name="ipport" unique="0" required="0">
+		<getopt mixed="-u, --ipport=[port]" />
+		<content type="string" default="161"  />
+		<shortdesc lang="en">TCP/UDP port to use for connection with device</shortdesc>
+	</parameter>
+	<parameter name="login" unique="0" required="0">
+		<getopt mixed="-l, --username=[name]" />
+		<content type="string"  />
+		<shortdesc lang="en">Login Name</shortdesc>
+	</parameter>
+	<parameter name="passwd" unique="0" required="0">
+		<getopt mixed="-p, --password=[password]" />
+		<content type="string"  />
+		<shortdesc lang="en">Login password or passphrase</shortdesc>
+	</parameter>
+	<parameter name="passwd_script" unique="0" required="0">
+		<getopt mixed="-S, --password-script=[script]" />
+		<content type="string"  />
+		<shortdesc lang="en">Script to retrieve password</shortdesc>
+	</parameter>
+	<parameter name="port" unique="0" required="1">
+		<getopt mixed="-n, --plug=[id]" />
+		<content type="string"  />
+		<shortdesc lang="en">Physical plug number, name of virtual machine or UUID</shortdesc>
+	</parameter>
+	<parameter name="snmp_auth_prot" unique="0" required="0">
+		<getopt mixed="-b, --snmp-auth-prot=[prot]" />
+		<content type="select"  >
+			<option value="MD5" />
+			<option value="SHA" />
+		</content>
+		<shortdesc lang="en">Set authentication protocol (MD5|SHA)</shortdesc>
+	</parameter>
+	<parameter name="snmp_priv_passwd" unique="0" required="0">
+		<getopt mixed="-P, --snmp-priv-passwd=[pass]" />
+		<content type="string"  />
+		<shortdesc lang="en">Set privacy protocol password</shortdesc>
+	</parameter>
+	<parameter name="snmp_priv_passwd_script" unique="0" required="0">
+		<getopt mixed="-R, --snmp-priv-passwd-script" />
+		<content type="string"  />
+		<shortdesc lang="en">Script to run to retrieve privacy password</shortdesc>
+	</parameter>
+	<parameter name="snmp_priv_prot" unique="0" required="0">
+		<getopt mixed="-B, --snmp-priv-prot=[prot]" />
+		<content type="select"  >
+			<option value="DES" />
+			<option value="AES" />
+		</content>
+		<shortdesc lang="en">Set privacy protocol (DES|AES)</shortdesc>
+	</parameter>
+	<parameter name="snmp_sec_level" unique="0" required="0">
+		<getopt mixed="-E, --snmp-sec-level=[level]" />
+		<content type="select"  >
+			<option value="noAuthNoPriv" />
+			<option value="authNoPriv" />
+			<option value="authPriv" />
+		</content>
+		<shortdesc lang="en">Set security level (noAuthNoPriv|authNoPriv|authPriv)</shortdesc>
+	</parameter>
+	<parameter name="snmp_version" unique="0" required="0">
+		<getopt mixed="-d, --snmp-version=[version]" />
+		<content type="select"  >
+			<option value="1" />
+			<option value="2c" />
+			<option value="3" />
+		</content>
+		<shortdesc lang="en">Specifies SNMP version to use (1,2c,3)</shortdesc>
+	</parameter>
+	<parameter name="verbose" unique="0" required="0">
+		<getopt mixed="-v, --verbose" />
+		<content type="boolean"  />
+		<shortdesc lang="en">Verbose mode</shortdesc>
+	</parameter>
+	<parameter name="debug" unique="0" required="0">
+		<getopt mixed="-D, --debug-file=[debugfile]" />
+		<content type="string"  />
+		<shortdesc lang="en">Write debug information to given file</shortdesc>
+	</parameter>
+	<parameter name="version" unique="0" required="0">
+		<getopt mixed="-V, --version" />
+		<content type="boolean"  />
+		<shortdesc lang="en">Display version information and exit</shortdesc>
+	</parameter>
+	<parameter name="help" unique="0" required="0">
+		<getopt mixed="-h, --help" />
+		<content type="boolean"  />
+		<shortdesc lang="en">Display help and exit</shortdesc>
+	</parameter>
+	<parameter name="separator" unique="0" required="0">
+		<getopt mixed="-C, --separator=[char]" />
+		<content type="string" default=","  />
+		<shortdesc lang="en">Separator for CSV created by operation list</shortdesc>
+	</parameter>
+	<parameter name="delay" unique="0" required="0">
+		<getopt mixed="--delay=[seconds]" />
+		<content type="string" default="0"  />
+		<shortdesc lang="en">Wait X seconds before fencing is started</shortdesc>
+	</parameter>
+	<parameter name="login_timeout" unique="0" required="0">
+		<getopt mixed="--login-timeout=[seconds]" />
+		<content type="string" default="5"  />
+		<shortdesc lang="en">Wait X seconds for cmd prompt after login</shortdesc>
+	</parameter>
+	<parameter name="power_timeout" unique="0" required="0">
+		<getopt mixed="--power-timeout=[seconds]" />
+		<content type="string" default="20"  />
+		<shortdesc lang="en">Test X seconds for status change after ON/OFF</shortdesc>
+	</parameter>
+	<parameter name="power_wait" unique="0" required="0">
+		<getopt mixed="--power-wait=[seconds]" />
+		<content type="string" default="0"  />
+		<shortdesc lang="en">Wait X seconds after issuing ON/OFF</shortdesc>
+	</parameter>
+	<parameter name="shell_timeout" unique="0" required="0">
+		<getopt mixed="--shell-timeout=[seconds]" />
+		<content type="string" default="3"  />
+		<shortdesc lang="en">Wait X seconds for cmd prompt after issuing command</shortdesc>
+	</parameter>
+	<parameter name="retry_on" unique="0" required="0">
+		<getopt mixed="--retry-on=[attempts]" />
+		<content type="string" default="1"  />
+		<shortdesc lang="en">Count of attempts to retry power on</shortdesc>
+	</parameter>
+</parameters>
+<actions>
+	<action name="on" automatic="0"/>
+	<action name="off" />
+	<action name="reboot" />
+	<action name="status" />
+	<action name="list" />
+	<action name="monitor" />
+	<action name="metadata" />
+</actions>
+</resource-agent>
-- 
1.9.3