fence-agents: RHEL6 - fence_hpblade: Fence agent for HP BladeSystem

Marek GrĂ¡c marx at fedoraproject.org
Thu Oct 4 08:51:38 UTC 2012


Gitweb:        http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=64a3c22205f7ee8cd1eb8dcc7ab9aafe1c8e9ee6
Commit:        64a3c22205f7ee8cd1eb8dcc7ab9aafe1c8e9ee6
Parent:        ff4b840516ca20fbe55a002d162d27c189261e4f
Author:        Marek 'marx' Grac <mgrac at redhat.com>
AuthorDate:    Thu May 31 14:57:10 2012 +0200
Committer:     Marek 'marx' Grac <mgrac at redhat.com>
CommitterDate: Thu Oct 4 10:45:21 2012 +0200

fence_hpblade: Fence agent for HP BladeSystem

New fence agent for HP BladeSystem enclosures. Be aware that you will have to set -c / cmd_prompt as it vary a lot.

Resolves: rhbz#818337
---
 configure.ac                          |    1 +
 fence/agents/hpblade/Makefile.am      |   17 +++++
 fence/agents/hpblade/fence_hpblade.py |  115 +++++++++++++++++++++++++++++++++
 fence/agents/lib/fencing.py.py        |    3 +-
 4 files changed, 135 insertions(+), 1 deletions(-)

diff --git a/configure.ac b/configure.ac
index e979675..3e71f43 100644
--- a/configure.ac
+++ b/configure.ac
@@ -262,6 +262,7 @@ AC_CONFIG_FILES([Makefile
 		 fence/agents/eaton_snmp/Makefile
 		 fence/agents/egenera/Makefile
 		 fence/agents/eps/Makefile
+		 fence/agents/hpblade/Makefile
 		 fence/agents/ibmblade/Makefile
 		 fence/agents/ifmib/Makefile
 		 fence/agents/ilo/Makefile
diff --git a/fence/agents/hpblade/Makefile.am b/fence/agents/hpblade/Makefile.am
new file mode 100644
index 0000000..e8ae6ff
--- /dev/null
+++ b/fence/agents/hpblade/Makefile.am
@@ -0,0 +1,17 @@
+MAINTAINERCLEANFILES	= Makefile.in
+
+TARGET			= fence_hpblade
+
+SRC			= $(TARGET).py
+
+EXTRA_DIST		= $(SRC)
+
+sbin_SCRIPTS		= $(TARGET)
+
+man_MANS		= $(TARGET).8
+
+include $(top_srcdir)/make/fencebuild.mk
+include $(top_srcdir)/make/fenceman.mk
+
+clean-local: clean-man
+	rm -f $(TARGET)
diff --git a/fence/agents/hpblade/fence_hpblade.py b/fence/agents/hpblade/fence_hpblade.py
new file mode 100644
index 0000000..b4e9f1b
--- /dev/null
+++ b/fence/agents/hpblade/fence_hpblade.py
@@ -0,0 +1,115 @@
+#!/usr/bin/python
+
+#####
+##
+## The Following Agent Has Been Tested On:
+##  * BladeSystem c7000 Enclosure
+#####
+
+import sys, re, pexpect, exceptions
+sys.path.append("@FENCEAGENTSLIBDIR@")
+from fencing import *
+
+#BEGIN_VERSION_GENERATION
+RELEASE_VERSION="New Bladecenter Agent - test release on steroids"
+REDHAT_COPYRIGHT=""
+BUILD_DATE="March, 2008"
+#END_VERSION_GENERATION
+
+def get_power_status(conn, options):
+	try:
+		conn.send_eol("show server status " + options["-n"])
+		conn.log_expect(options, options["-c"] , int(options["-Y"]))
+		
+		power_re = re.compile("^\s*Power: (.*?)\s*$")
+		status = "unknown"
+		for line in conn.before.splitlines():
+		        res = power_re.search(line)
+		        if res != None:
+		                status = res.group(1)
+
+                if status == "unknown":
+			if options.has_key("-M"):
+				return "off"
+			else:
+				fail(EC_STATUS)
+	except pexpect.EOF:
+		fail(EC_CONNECTION_LOST)
+	except pexpect.TIMEOUT:
+		fail(EC_TIMED_OUT)
+
+	return status.lower().strip()
+
+def set_power_status(conn, options):
+	try:
+	        if options["-o"] == "on":
+	                conn.send_eol("poweron server " + options["-n"])
+                elif options["-o"] == "off":
+                        conn.send_eol("poweroff server " + options["-n"] + " force")
+		conn.log_expect(options, options["-c"], int(options["-Y"]))
+	except pexpect.EOF:
+		fail(EC_CONNECTION_LOST)
+	except pexpect.TIMEOUT:
+		fail(EC_TIMED_OUT)
+
+def get_blades_list(conn, options):
+	outlets = { }
+	try:
+		conn.send_eol("show server list" )
+		conn.log_expect(options, options["-c"], int(options["-Y"]))
+
+		list_re = re.compile("^\s*(.*?)\s+(.*?)\s+(.*?)\s+OK\s+(.*?)\s+(.*?)\s*$")
+		for line in conn.before.splitlines():
+		        res = list_re.search(line)
+		        if res != None:
+		                outlets[res.group(1)] = (res.group(2), res.group(4).lower())
+	except pexpect.EOF:
+		fail(EC_CONNECTION_LOST)
+	except pexpect.TIMEOUT:
+		fail(EC_TIMED_OUT)
+
+	return outlets
+
+def main():
+	device_opt = [  "help", "version", "agent", "quiet", "verbose", "debug",
+			"action", "ipaddr", "login", "passwd", "passwd_script",
+			"cmd_prompt", "secure", "port", "identity_file", "separator",
+			"inet4_only", "inet6_only", "ipport", "missing_as_off",
+			"power_timeout", "shell_timeout", "login_timeout", "power_wait"]
+
+	atexit.register(atexit_handler)
+
+	all_opt["cmd_prompt"]["default"] = "c7000oa>"
+
+	options = check_input(device_opt, process_input(device_opt))
+
+ 	docs = { }        
+	docs["shortdesc"] = "Fence agent for HP BladeSystem"
+	docs["longdesc"] = "fence_hpblade is an I/O Fencing agent \
+which can be used with HP BladeSystem. It logs into an enclosure via telnet or ssh \
+and uses the command line interface to power on and off blades."
+	docs["vendorurl"] = "http://www.hp.com"
+	show_docs(options, docs)
+	
+	##
+	## Operate the fencing device
+	######
+	options["eol"] = "\n"
+	conn = fence_login(options)
+	result = fence_action(conn, options, set_power_status, get_power_status, get_blades_list)
+
+	##
+	## Logout from system
+	######
+	try:
+		conn.send_eol("exit")
+		conn.close()
+	except exceptions.OSError:
+		pass
+	except pexpect.ExceptionPexpect:
+		pass
+	
+	sys.exit(result)
+
+if __name__ == "__main__":
+	main()
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index 2a62242..a9c287a 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -867,7 +867,8 @@ def fence_login(options):
 	if (options.has_key("-4")):
 		force_ipvx="-4 "
 
-	options["eol"] = "\r\n"
+	if (options.has_key("eol") == False):
+		options["eol"] = "\r\n"
 
 	## Do the delay of the fence device before logging in
 	## Delay is important for two-node clusters fencing but we do not need to delay 'status' operations


More information about the cluster-commits mailing list