cluster: RHEL55 - fence_sanbox2: Really add new fence agent + new option login_eol_lf

Marek Grác marx at fedoraproject.org
Fri Oct 9 10:39:33 UTC 2009


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=a8b3ef06aedef9e05c3aef62448233ac993e617a
Commit:        a8b3ef06aedef9e05c3aef62448233ac993e617a
Parent:        819956029c9328a3169ba6cb378b4be16088854b
Author:        Marek 'marx' Grac <mgrac at redhat.com>
AuthorDate:    Fri Oct 9 12:38:01 2009 +0200
Committer:     Marek 'marx' Grac <mgrac at redhat.com>
CommitterDate: Fri Oct 9 12:38:01 2009 +0200

fence_sanbox2: Really add new fence agent + new option login_eol_lf

I forgot to add fence agent in previous patch :(

This option is used for login method using telnet. By default most of the fence agents
work with username\r\n but on some devices (e.g. HP iLO MP, sanbox2) it is interpreted
as there is empty password. [from STABLE3 - 819956029c9328a3169ba6cb378b4be16088854b]
---
 fence/agents/lib/fencing.py.py        |   14 +++-
 fence/agents/sanbox2/fence_sanbox2.py |  154 +++++++++++++++++++++++++++++++++
 2 files changed, 166 insertions(+), 2 deletions(-)

diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index ca9fb4b..471e7e2 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -138,6 +138,11 @@ all_opt = {
 		"longopt" : "ribcl-version",
 		"help" : "-r, --ribcl-version=<version>  Force ribcl version to use",
 		"order" : 1 },
+	"login_eol_lf" : {
+		"getopt" : "",
+		"help" : "",
+		"order" : 1
+		},
 	"cmd_prompt" : {
 		"getopt" : "c:",
 		"longopt" : "command-prompt",
@@ -575,6 +580,11 @@ def fence_login(options):
 	if (options.has_key("-4")):
 		force_ipvx="-4 "
 
+	if (options["device_opt"].count("login_eol_lf")):
+		login_eol = "\n"
+	else:
+		login_eol = "\r\n"
+
 	try:
 		re_login = re.compile("(login: )|(Login Name:  )|(username: )|(User Name :)", re.IGNORECASE)
 		re_pass  = re.compile("password", re.IGNORECASE)
@@ -614,9 +624,9 @@ def fence_login(options):
 			conn.send("set binary\n")
 			conn.send("open %s -%s\n"%(options["-a"], options["-u"]))
 			conn.log_expect(options, re_login, LOGIN_TIMEOUT)
-			conn.send(options["-l"]+"\r\n")
+			conn.send(options["-l"] + login_eol)
 			conn.log_expect(options, re_pass, SHELL_TIMEOUT)
-			conn.send(options["-p"]+"\r\n")
+			conn.send(options["-p"] + login_eol)
 			conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
 	except pexpect.EOF:
 		fail(EC_LOGIN_DENIED) 
diff --git a/fence/agents/sanbox2/fence_sanbox2.py b/fence/agents/sanbox2/fence_sanbox2.py
new file mode 100644
index 0000000..54122a5
--- /dev/null
+++ b/fence/agents/sanbox2/fence_sanbox2.py
@@ -0,0 +1,154 @@
+#!/usr/bin/python
+
+#####
+##
+## The Following Agent Has Been Tested On:
+##
+##  Version            Firmware
+## +-----------------+---------------------------+
+#####
+
+import sys, re, pexpect
+sys.path.append("@FENCEAGENTSLIBDIR@")
+from fencing import *
+
+#BEGIN_VERSION_GENERATION
+RELEASE_VERSION="New Sanbox2 Agent - test release on steroids"
+REDHAT_COPYRIGHT=""
+BUILD_DATE="March, 2008"
+#END_VERSION_GENERATION
+
+def get_power_status(conn, options):
+	status_trans = {
+		'online' : "on",
+		'offline' : "off"
+	}
+	try:
+		conn.send("show port " + options["-n"] + "\n")
+		conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
+	except pexpect.EOF:
+		fail(EC_CONNECTION_LOST)
+	except pexpect.TIMEOUT:
+		try:
+			conn.send("admin end\n")
+			conn.send("exit\n")
+			conn.close()
+		except:
+			pass
+		fail(EC_TIMED_OUT)
+	
+	status = re.compile(".*AdminState\s+(online|offline)\s+", re.IGNORECASE | re.MULTILINE).search(conn.before).group(1)
+
+	try:
+		return status_trans[status.lower().strip()]
+	except KeyError:
+		return "PROBLEM"
+
+def set_power_status(conn, options):
+	action = {
+		'on' : "online",
+		'off' : "offline"
+	}[options["-o"]]
+
+        try:
+        	conn.send("set port " + options["-n"] + " state " + action + "\n")
+		conn.log_expect(options, options["-c"], POWER_TIMEOUT)
+	except pexpect.EOF:
+		fail(EC_CONNECTION_LOST)
+	except pexpect.TIMEOUT:
+		try:
+			conn.send("admin end\n")
+			conn.send("exit\n")
+			conn.close()
+		except:
+			pass
+		fail(EC_TIMED_OUT)                                                                         	
+
+	try:
+		conn.send("set port " + options["-n"] + " state " + action + "\n")
+		conn.log_expect(options, options["-c"], POWER_TIMEOUT)
+	except pexpect.EOF:
+		fail(EC_CONNECTION_LOST)
+	except pexpect.TIMEOUT:
+		try:
+			conn.send("admin end\n")
+			conn.send("exit\n")
+			conn.close()
+		except:
+			pass
+		fail(EC_TIMED_OUT)
+
+def get_list_devices(conn, options):
+	outlets = { }
+
+	try:
+		conn.send("show port" + "\n")
+		conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
+
+		list_re = re.compile("^\s+(\d+?)\s+(Online|Offline)\s+", re.IGNORECASE)
+		for line in conn.before.splitlines():
+			if (list_re.search(line)):
+				status = {
+					'online' : "ON",
+					'offline' : "OFF"
+				}[list_re.search(line).group(2).lower()]
+				outlets[list_re.search(line).group(1)] = ("", status)
+
+	except pexpect.EOF:
+		fail(EC_CONNECTION_LOST)
+	except pexpect.TIMEOUT:
+		try:
+			conn.send("admin end\n")
+			conn.send("exit\n")
+			conn.close()
+		except:
+			pass
+		fail(EC_TIMED_OUT)
+		
+	return outlets
+
+def main():
+	device_opt = [  "help", "version", "agent", "quiet", "verbose", "debug",
+			"io_fencing", "ipaddr", "login", "passwd", "passwd_script",
+			"cmd_prompt", "port", "ipport", "login_eol_lf", "separator" ]
+
+	atexit.register(atexit_handler)
+
+	options = check_input(device_opt, process_input(device_opt))
+
+	## 
+	## Fence agent specific defaults
+	#####
+	if 0 == options.has_key("-c"):
+		options["-c"] = [ " #> " ]
+
+	##
+	## Operate the fencing device
+	##
+	conn = fence_login(options)
+
+	conn.send("admin start\n")
+	conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
+
+	if (re.search("\(admin\)", conn.before, re.MULTILINE) == None):
+		## Someone else is in admin section, we can't enable/disable
+		## ports so we will rather exit
+		sys.stderr.write("Failed: Unable to switch to admin section\n")
+		sys.exit(EC_GENERIC_ERROR)
+
+	fence_action(conn, options, set_power_status, get_power_status, get_list_devices)
+
+	##
+	## Logout from system
+	######
+	try:
+		conn.send("admin end\n")
+		conn.send("exit\n")
+		conn.close()
+	except exceptions.OSError:
+		pass
+	except pexpect.ExceptionPexpect:
+		pass
+
+if __name__ == "__main__":
+	main()


More information about the cluster-commits mailing list