This is the mail archive of the
cluster-cvs@sourceware.org
mailing list for the cluster.
master - [fence] Fence agent for ePowerSwitch 8M+ (fence_eps)
- From: Jan Friesse <honzaf at fedoraproject dot org>
- To: cluster-cvs-relay at redhat dot com
- Date: Tue, 21 Oct 2008 12:01:55 +0000 (UTC)
- Subject: master - [fence] Fence agent for ePowerSwitch 8M+ (fence_eps)
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=bde145ebc02c1c621b2e90a2426c0f8e31b8cf34
Commit: bde145ebc02c1c621b2e90a2426c0f8e31b8cf34
Parent: 7a8e0cb1600ab2caf2e4d0dd20ddaf97345d557e
Author: Jan Friesse <jfriesse@redhat.com>
AuthorDate: Tue Oct 21 14:00:45 2008 +0200
Committer: Jan Friesse <jfriesse@redhat.com>
CommitterDate: Tue Oct 21 14:00:45 2008 +0200
[fence] Fence agent for ePowerSwitch 8M+ (fence_eps)
bz 467112
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.
---
fence/agents/eps/Makefile | 5 ++
fence/agents/eps/fence_eps.py | 111 +++++++++++++++++++++++++++++++++++++++++
fence/man/fence_eps.8 | 106 +++++++++++++++++++++++++++++++++++++++
3 files changed, 222 insertions(+), 0 deletions(-)
diff --git a/fence/agents/eps/Makefile b/fence/agents/eps/Makefile
new file mode 100644
index 0000000..fc665bc
--- /dev/null
+++ b/fence/agents/eps/Makefile
@@ -0,0 +1,5 @@
+include ../../../make/defines.mk
+
+TARGET= fence_eps
+
+include $(OBJDIR)/make/fencebuild.mk
diff --git a/fence/agents/eps/fence_eps.py b/fence/agents/eps/fence_eps.py
new file mode 100644
index 0000000..c91d5af
--- /dev/null
+++ b/fence/agents/eps/fence_eps.py
@@ -0,0 +1,111 @@
+#!/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("@FENCEAGENTSLIBDIR@")
+from fencing import *
+
+#BEGIN_VERSION_GENERATION
+RELEASE_VERSION="ePowerSwitch 8M+ (eps)"
+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):
+ # String for Authorization header
+ auth_str = 'Basic ' + string.strip(base64.encodestring(options["-l"]+':'+options["-p"]))
+ 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)
+
+ 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" ]
+
+ eps_define_new_opts()
+
+ # Because we DON'T need password, we must do little hack
+ input_opts=process_input(device_opt)
+ if ((not input_opts.has_key("-p")) and (not input_opts.has_key("-S"))):
+ input_opts["-p"]=""
+ if (not input_opts.has_key("-l")):
+ input_opts["-l"]=""
+
+ options = check_input(device_opt,input_opts)
+
+ 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/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)