Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=ef85cb7d4... Commit: ef85cb7d44f4772b258c03352b6d8ca75c6107df Parent: 5901c326a39f68582fd0d5f5d465ced87b9e230d Author: Marek 'marx' Grac mgrac@redhat.com AuthorDate: Wed Apr 2 15:06:55 2014 +0200 Committer: Marek 'marx' Grac mgrac@redhat.com CommitterDate: Wed Apr 2 15:06:55 2014 +0200
fence_raritan: new fence agent for Raritan Dominion PX
Written by David Smith dsmith@mypchelp.com --- .gitignore | 1 + configure.ac | 1 + fence/agents/raritan/Makefile.am | 17 ++++++ fence/agents/raritan/fence_raritan.py | 98 +++++++++++++++++++++++++++++++++ 4 files changed, 117 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore index a711b3a..74198b2 100644 --- a/.gitignore +++ b/.gitignore @@ -67,6 +67,7 @@ fence/agents/node_assassin/fence_na.pod fence/agents/nss_wrapper/fence_nss_wrapper fence/agents/rackswitch/fence_rackswitch fence/agents/rhevm/fence_rhevm +fence/agents/raritan/fence_raritan fence/agents/rsa/fence_rsa fence/agents/rsb/fence_rsb fence/agents/sanbox2/fence_sanbox2 diff --git a/configure.ac b/configure.ac index eaef1d8..c24198c 100644 --- a/configure.ac +++ b/configure.ac @@ -283,6 +283,7 @@ AC_CONFIG_FILES([Makefile fence/agents/netio/Makefile fence/agents/rackswitch/Makefile fence/agents/ovh/Makefile + fence/agents/raritan/Makefile fence/agents/rhevm/Makefile fence/agents/rsa/Makefile fence/agents/rsb/Makefile diff --git a/fence/agents/raritan/Makefile.am b/fence/agents/raritan/Makefile.am new file mode 100644 index 0000000..f41ba56 --- /dev/null +++ b/fence/agents/raritan/Makefile.am @@ -0,0 +1,17 @@ +MAINTAINERCLEANFILES = Makefile.in + +TARGET = fence_raritan + +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/raritan/fence_raritan.py b/fence/agents/raritan/fence_raritan.py new file mode 100644 index 0000000..c8137b0 --- /dev/null +++ b/fence/agents/raritan/fence_raritan.py @@ -0,0 +1,98 @@ +#!/usr/bin/python + +import sys, re, pexpect, exceptions +sys.path.append("@FENCEAGENTSLIBDIR@") +from fencing import * + +#BEGIN_VERSION_GENERATION +RELEASE_VERSION="" +REDHAT_COPYRIGHT="" +BUILD_DATE="" +#END_VERSION_GENERATION + +# --plug should include path to the outlet # such as port 1: +# /system1/outlet1 + +def get_power_status(conn, options): + conn.send_eol("show -d properties=powerState %s" % options["--plug"]) + re_status = re.compile(".*powerState is [12].*") + conn.log_expect(options, re_status, int(options["--shell-timeout"])) + status = { + #"0" : "off", + "1" : "on", + "2" : "off", + }[conn.after.split()[2]] + + return status + +def set_power_status(conn, options): + action = { + "on" : "on", + "off" : "off", + }[options["--action"]] + + conn.send_eol("set %s powerState=%s" % (options["--plug"], action)) + +def main(): + device_opt = [ "ipaddr", "login", "passwd", "port" ] + + atexit.register(atexit_handler) + + opt = process_input(device_opt) + + all_opt["ipport"]["default"] = "23" + + opt["eol"] = "\r\n" + options = check_input(device_opt, opt) + + docs = { } + docs["shortdesc"] = "I/O Fencing agent for Raritan Dominion PX" + docs["longdesc"] = "fence_raritan is an I/O Fencing agent which can be \ +used with the Raritan DPXS12-20 Power Distribution Unit. It logs into \ +device via telnet and reboots a specified outlet. Lengthy telnet connections \ +should be avoided while a GFS cluster is running because the connection will \ +block any necessary fencing actions." + docs["vendorurl"] = "http://www.raritan.com/" + show_docs(options, docs) + + # add support also for delay before login which is very useful for 2-node clusters + if options["--action"] in ["off", "reboot"]: + time.sleep(int(options["--delay"])) + + ## + ## Operate the fencing device + ## We can not use fence_login(), username and passwd are sent on one line + #### + try: + conn = fspawn(options, TELNET_PATH) + conn.send("set binary\n") + conn.send("open %s -%s\n"%(options["--ip"], options["--ipport"])) + screen = conn.read_nonblocking(size=100, timeout=int(options["--shell-timeout"])) + conn.log_expect(options, "Login.*", int(options["--shell-timeout"])) + conn.send_eol("%s" % (options["--username"])) + conn.log_expect(options, "Password.*", int(options["--shell-timeout"])) + conn.send_eol("%s" % (options["--password"])) + conn.log_expect(options, "clp.*", int(options["--shell-timeout"])) + except pexpect.EOF: + fail(EC_LOGIN_DENIED) + except pexpect.TIMEOUT: + fail(EC_LOGIN_DENIED) + result = fence_action(conn, options, set_power_status, get_power_status) + + ## + ## Logout from system + ## + ## In some special unspecified cases it is possible that + ## connection will be closed before we run close(). This is not + ## a problem because everything is checked before. + ###### + try: + conn.send("exit\n") + conn.close() + except: + pass + + sys.exit(result) + +if __name__ == "__main__": + main()
cluster-commits@lists.fedorahosted.org