Blame SOURCES/bz1171732-1-fence_emerson.patch

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