Blame SOURCES/bz1171732-1-fence_emerson.patch

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