This is the mail archive of the cluster-cvs@sourceware.org mailing list for the cluster.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RHEL5 - [fence] Fence agent for ePowerSwitch 8M+ (fence_eps)


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=0e267af266f2c779225fbf45d7cb340aaf27ac6e
Commit:        0e267af266f2c779225fbf45d7cb340aaf27ac6e
Parent:        e07369b28d7a569e742d80152ef10c9d42bc2650
Author:        Jan Friesse <jfriesse@redhat.com>
AuthorDate:    Wed Oct 22 17:05:41 2008 +0200
Committer:     Jan Friesse <jfriesse@redhat.com>
CommitterDate: Wed Oct 22 17:05:41 2008 +0200

[fence] Fence agent for ePowerSwitch 8M+ (fence_eps)

Fence agent for ePowerSwitch 8M+ works only on 8M+ device, because
this is only one with hidden page (this feature has to be allowed,
otherwise agent will not work) feature support.

This also led to update of Python fencing library for support of no_password
option, which may be used for this device.

Bugzilla #467112
---
 fence/agents/eps/Makefile      |   38 ++++++++++++++
 fence/agents/eps/fence_eps.py  |  108 ++++++++++++++++++++++++++++++++++++++++
 fence/agents/lib/fencing.py.py |   17 ++++--
 fence/man/Makefile             |    3 +-
 fence/man/fence_eps.8          |  106 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 265 insertions(+), 7 deletions(-)

diff --git a/fence/agents/eps/Makefile b/fence/agents/eps/Makefile
new file mode 100644
index 0000000..3e086c9
--- /dev/null
+++ b/fence/agents/eps/Makefile
@@ -0,0 +1,38 @@
+###############################################################################
+###############################################################################
+##
+##  Copyright (C) Sistina Software, Inc.  1997-2003  All rights reserved.
+##  Copyright (C) 2004 Red Hat, Inc.  All rights reserved.
+##  
+##  This copyrighted material is made available to anyone wishing to use,
+##  modify, copy, or redistribute it subject to the terms and conditions
+##  of the GNU General Public License v.2.
+##
+###############################################################################
+###############################################################################
+
+SOURCE= fence_eps.py
+TARGET= fence_eps
+
+top_srcdir=../..
+include ${top_srcdir}/make/defines.mk
+
+all: $(TARGET)
+
+fence_eps: fence_eps.py
+	: > $(TARGET)
+	awk "{print}(\$$1 ~ /#BEGIN_VERSION_GENERATION/){exit 0}" $(SOURCE) >> $(TARGET)
+	echo "FENCE_RELEASE_NAME=\"${RELEASE}\";" >> $(TARGET)
+	${top_srcdir}/scripts/define2var ${top_srcdir}/config/copyright.cf sh REDHAT_COPYRIGHT >> $(TARGET)
+	echo "BUILD_DATE=\"(built `date`)\";" >> $(TARGET)
+	awk -v p=0 "(\$$1 ~ /#END_VERSION_GENERATION/){p = 1} {if(p==1)print}" $(SOURCE) >> $(TARGET)
+	chmod +x $(TARGET)
+
+install: all
+	if [ ! -d ${sbindir} ]; then \
+		install -d ${sbindir}; \
+	fi
+	install -m755 ${TARGET} ${sbindir}
+
+clean:
+	rm -f $(TARGET)
diff --git a/fence/agents/eps/fence_eps.py b/fence/agents/eps/fence_eps.py
new file mode 100644
index 0000000..69068b1
--- /dev/null
+++ b/fence/agents/eps/fence_eps.py
@@ -0,0 +1,108 @@
+#!/usr/bin/python
+
+# The Following Agent Has Been Tested On:
+# ePowerSwitch 8M+ version 1.0.0.4
+
+import sys, re, time
+import httplib, base64, string,socket
+sys.path.append("/usr/lib/fence")
+from fencing import *
+
+#BEGIN_VERSION_GENERATION
+FENCE_RELEASE_NAME=""
+REDHAT_COPYRIGHT=""
+BUILD_DATE=""
+#END_VERSION_GENERATION
+
+# Log actions and results from EPS device
+def eps_log(options,str):
+	if options["log"]>=LOG_MODE_VERBOSE:
+		options["debug_fh"].write(str)
+
+# Run command on EPS device.
+# @param options Device options
+# @param params HTTP GET parameters (without ?)
+def eps_run_command(options, params):
+	try:
+		# New http connection
+		conn = httplib.HTTPConnection(options["-a"])
+
+		request_str="/"+options["-c"]
+
+		if (params!=""):
+			request_str+="?"+params
+
+		eps_log(options,"GET "+request_str+"\n")
+		conn.putrequest('GET', request_str)
+
+		if (options.has_key("-l")):
+			if (not options.has_key("-p")):
+				options["-p"]="" # Default is empty password
+				
+			# String for Authorization header
+			auth_str = 'Basic ' + string.strip(base64.encodestring(options["-l"]+':'+options["-p"]))
+			eps_log(options,"Authorization:"+auth_str+"\n")
+			conn.putheader('Authorization',auth_str)
+
+		conn.endheaders()
+
+		response = conn.getresponse()
+
+		eps_log(options,"%d %s\n"%(response.status,response.reason))
+
+		#Response != OK -> couldn't login
+		if (response.status!=200):
+			fail(EC_LOGIN_DENIED)
+
+		result=response.read()
+		eps_log(options,result+"\n")
+		conn.close()
+
+	except socket.timeout:
+		fail(EC_TIMED_OUT)
+	except socket.error:
+		fail(EC_LOGIN_DENIED)
+
+	return result
+
+def get_power_status(conn, options):
+	result = ""
+
+	ret_val=eps_run_command(options,"")
+
+	status=re.search("p"+options["-n"].lower()+"=(0|1)\s*\<br\>",ret_val.lower())
+	if status==None:
+		fail_usage("Failed: You have to enter existing physical plug!")
+
+	result=(status.group(1)=="1" and "on" or "off")
+
+	return result
+
+def set_power_status(conn, options):
+	ret_val=eps_run_command(options,"P%s=%s"%(options["-n"],(options["-o"]=="on" and "1" or "0")))
+
+# Define new option
+def eps_define_new_opts():
+	all_opt["hidden_page"]={
+		"getopt":"c:",
+		"help":"-c <page>      Name of hidden page (default hidden.htm)",
+		"order": 1}
+
+# Starting point of fence agent
+def main():
+	device_opt = [  "help", "version", "agent", "quiet", "verbose", "debug",
+			"action", "ipaddr", "login", "passwd", "passwd_script",
+			"test", "port", "hidden_page", "no_login", "no_password" ]
+
+	eps_define_new_opts()
+
+	options = check_input(device_opt,process_input(device_opt))
+
+	if (not options.has_key("-c")):
+		options["-c"]="hidden.htm"
+
+	#Run fence action. Conn is None, beacause we always need run new curl command
+	fence_action(None, options, set_power_status, get_power_status)
+
+if __name__ == "__main__":
+	main()
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index dd4049a..9e7aa97 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -74,6 +74,10 @@ all_opt = {
 		"getopt" : "",
 		"help" : "",
 		"order" : 1 },
+	"no_password" : {
+		"getopt" : "",
+		"help" : "",
+		"order" : 1 },
 	"passwd" : {
 		"getopt" : "p:",
 		"help" : "-p <password>  Login password or passphrase",
@@ -296,12 +300,13 @@ def check_input(device_opt, opt):
 	if 0 == options.has_key("-a"):
 		fail_usage("Failed: You have to enter fence address")
 
-	if 0 == device_opt.count("identity_file"):
-		if 0 == (options.has_key("-p") or options.has_key("-S")):
-			fail_usage("Failed: You have to enter password or password script")
-	else: 
-		if 0 == (options.has_key("-p") or options.has_key("-S") or options.has_key("-k")):
-			fail_usage("Failed: You have to enter password, password script or identity file")
+	if (device_opt.count("no_password") == 0):
+		if 0 == device_opt.count("identity_file"):
+			if 0 == (options.has_key("-p") or options.has_key("-S")):
+				fail_usage("Failed: You have to enter password or password script")
+			else: 
+				if 0 == (options.has_key("-p") or options.has_key("-S") or options.has_key("-k")):
+					fail_usage("Failed: You have to enter password, password script or identity file")
 
 	if 0 == options.has_key("-x") and 1 == options.has_key("-k"):
 		fail_usage("Failed: You have to use identity file together with ssh connection (-x)")
diff --git a/fence/man/Makefile b/fence/man/Makefile
index 72f1555..e593980 100644
--- a/fence/man/Makefile
+++ b/fence/man/Makefile
@@ -20,11 +20,12 @@ TARGET8= \
 	fence_brocade.8 \
 	fence_drac.8 \
 	fence_egenera.8 \
+	fence_eps.8 \
 	fence_ilo.8 \
 	fence_manual.8 \
 	fence_mcdata.8 \
 	fence_node.8 \
-        fence_rib.8 \
+	fence_rib.8 \
 	fence_sanbox2.8 \
 	fence_scsi.8 \
 	fence_tool.8 \
diff --git a/fence/man/fence_eps.8 b/fence/man/fence_eps.8
new file mode 100644
index 0000000..3685837
--- /dev/null
+++ b/fence/man/fence_eps.8
@@ -0,0 +1,106 @@
+.TH fence_eps 8
+
+.SH NAME
+fence_eps - I/O Fencing agent for ePowerSwitch 8M+ power switch
+
+.SH SYNOPSIS
+.B
+fence_eps
+[\fIOPTION\fR]...
+
+.SH DESCRIPTION
+fence_eps is an I/O Fencing agent which can be used with the ePowerSwitch 8M+ power
+switch to fence connected machines. Fence agent works (in 2008/10/21) ONLY on 8M+
+device, because this is only one, which has support for hidden page feature.
+
+Agent basically works by connecting to hidden page and pass appropriate arguments
+to GET request. This means, that hidden page feature must be enabled and properly
+configured.
+
+fence_eps accepts options on the command line as well as from stdin.
+Fenced sends parameters through stdin when it execs the agent.  fence_eps
+can be run by itself with command line options.  This is useful for testin
+and for turning outlets on or off from scripts.
+
+.SH OPTIONS
+.TP
+\fB-a\fP \fIIPaddress\fR
+IP address or hostname of ePowerSwitch 8M+ device. If device is configured
+to listen on nonstandard port (other than 80), it's possible to use :port syntax
+(ex. psip:8080).
+.TP
+\fB-h\fP
+Print out a help message describing available options, then exit.
+.TP
+\fB-l\fP \fIlogin\fR
+Login name.
+.TP
+\fB-o\fP \fIaction\fR
+The action required.  This can be reboot (default), status, off or on.
+.TP
+\fB-p\fP \fIpassword\fR
+Password for login.
+.TP
+\fB-S\fP \fIscript\fR
+Script to run to retrieve password.
+.TP
+\fB-n\fP \fIname\fR
+Physical plug number. Entered without P and with preceding zero (where is needed).
+.TP
+\fB-c\fP \fIname\fR
+Name of hidden page. Default is (hidden.htm)
+.TP
+\fB-T\fP
+Test only.  Answer NO to the confirmation prompt instead of YES.
+.TP
+\fB-q\fP
+Quiet mode.
+.TP
+\fB-v\fP
+Verbose. Record session to stdout, or debug file if specified (see -D).
+.TP
+\fB-D\fP
+Specifies file, where will be written debug messages from session.
+.TP
+\fB-V\fP
+Print out a version message, then exit.
+
+.SH STDIN PARAMETERS
+.TP
+\fIagent = < param >\fR
+This option is used by fence_node(8) and is ignored by fence_eps.
+.TP
+\fIipaddr = < hostname | ip >\fR
+IP address or hostname of ePowerSwitch 8M+ device. If device is configured
+to listen on nonstandard port (other than 80), it's possible to use :port syntax
+(ex. psip:8080).
+.TP
+\fIlogin = < param >\fR
+Login name.
+.TP
+\fIoption = < param >\fR
+The action required.  This can be reboot (default), status, off or on.
+.TP
+\fIpasswd = < param >\fR
+Password for login.
+.TP
+\fIpasswd_script = < param >\fR
+Script to run to retrieve password.
+.TP
+\fIport = < param >\fR
+Physical plug number. Entered without P and with preceding zero (where is needed)
+.TP
+\fIhidden_page = < param >\fR
+Name of hidden page. Default is (hidden.htm)
+.TP
+\fItest = < param >\fR
+Test only.  Answer NO to the confirmation prompt instead of YES.
+.TP
+\fIverbose = < param >\fR
+Verbose.  Record session to stdout, or debug file if specified (see debug).
+.TP
+\fIdebug = < param >\fR
+Specifies file, where will be written debug messages from session.
+
+.SH SEE ALSO
+fence(8), fence_node(8)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]