From mboxrd@z Thu Jan 1 00:00:00 1970 From: mgrac@sourceware.org Date: 22 Apr 2008 15:54:59 -0000 Subject: [Cluster-devel] Cluster Project branch, RHEL4, updated. gfs-kernel_2_6_9_76-47-gbcfdaa6 Message-ID: <20080422155459.10459.qmail@sourceware.org> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Cluster Project". http://sources.redhat.com/git/gitweb.cgi?p=cluster.git;a=commitdiff;h=bcfdaa69b501fef4d01abcf1104d87d00484da66 The branch, RHEL4 has been updated via bcfdaa69b501fef4d01abcf1104d87d00484da66 (commit) from ceee2fe27ece59ef6b3643ab1e7a4cce6688727c (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit bcfdaa69b501fef4d01abcf1104d87d00484da66 Author: Marek 'marx' Grac Date: Tue Apr 22 17:52:01 2008 +0200 fence/agents: New fencings agents There are new fencing agents based on a new library. They need a 'pexpect' package. If it is possible there is support for both telnet and ssh. In this patch there are agents for: APC, BladeCenter, Drac 5, ILo and WTI. Fence agents that support ssh in 4.7 are iLO, DRAC5, WTI, APC, and BladeCenter ----------------------------------------------------------------------- Summary of changes: fence/agents/apc/apc.py | 94 +++++++++ fence/agents/bladecenter/bladecenter.py | 84 ++++++++ fence/agents/drac/drac5.py | 73 +++++++ fence/agents/ilo/ilo.py | 71 +++++++ fence/agents/lib/fencing.py | 339 +++++++++++++++++++++++++++++++ fence/agents/wti/wti.py | 103 ++++++++++ 6 files changed, 764 insertions(+), 0 deletions(-) create mode 100755 fence/agents/apc/apc.py create mode 100755 fence/agents/bladecenter/bladecenter.py create mode 100755 fence/agents/drac/drac5.py create mode 100755 fence/agents/ilo/ilo.py create mode 100644 fence/agents/lib/fencing.py create mode 100755 fence/agents/wti/wti.py diff --git a/fence/agents/apc/apc.py b/fence/agents/apc/apc.py new file mode 100755 index 0000000..bcea997 --- /dev/null +++ b/fence/agents/apc/apc.py @@ -0,0 +1,94 @@ +#!/usr/bin/python + +## +## Copyright (C) 2008 Red Hat, Inc. All Rights Reserved. +## +## The Following Agent Has Been Tested On: +## +## Model Firmware +## +---------------------------------------------+ +## AP7951 AOS v2.7.0, PDU APP v2.7.3 +## +## @note: ssh is very slow on AP7951 device +##### + +import sys, re, pexpect +sys.path.append("../lib/") +from fencing import * + +def get_power_status(conn, options): + result = "" + try: + conn.send("1\r\n") + conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.send("2\r\n") + while 1 == conn.log_expect(options, [ options["-c"], "Press " ], SHELL_TIMEOUT): + result += conn.before + conn.send("\r\n") + result += conn.before + conn.send(chr(03)) + conn.log_expect(options, "- Logout", SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + except pexpect.EOF: + fail(EC_CONNECTION_LOST) + except pexpect.TIMEOUT: + fail(EC_TIMED_OUT) + + status = re.compile("\s*"+options["-n"]+"-.*(ON|OFF)", re.IGNORECASE).search(result).group(1) + return status.lower().strip() + +def set_power_status(conn, options): + action = { + 'on' : "1", + 'off': "2" + }[options["-o"]] + + try: + conn.send("1\r\n") + conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.send("2\r\n") + while 1 == conn.log_expect(options, [ options["-c"], "Press " ], SHELL_TIMEOUT): + conn.send("\r\n") + conn.send(options["-n"]+"\r\n") + conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.send(action+"\r\n") + conn.log_expect(options, "Enter 'YES' to continue or to cancel :", SHELL_TIMEOUT) + conn.send("YES\r\n") + conn.log_expect(options, "Press to continue...", SHELL_TIMEOUT) + conn.send("\r\n") + conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.send(chr(03)) + conn.log_expect(options, "- Logout", SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + except pexcept.EOF: + fail(EC_CONNECTION_LOST) + except pexcept.TIMEOUT: + fail(EC_TIMED_OUT) + +def main(): + device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", + "action", "ipaddr", "login", "passwd", "passwd_script", + "secure", "port", "test" ] + + options = check_input(device_opt, process_input(device_opt)) + + ## + ## Fence agent specific defaults + ##### + if 0 == options.has_key("-c"): + options["-c"] = "\n>" + + ## + ## Operate the fencing device + #### + conn = fence_login(options) + fence_action(conn, options, set_power_status, get_power_status) + + ## + ## Logout from system + ###### + conn.sendline("4") + conn.close() + +if __name__ == "__main__": + main() diff --git a/fence/agents/bladecenter/bladecenter.py b/fence/agents/bladecenter/bladecenter.py new file mode 100755 index 0000000..cbc7daa --- /dev/null +++ b/fence/agents/bladecenter/bladecenter.py @@ -0,0 +1,84 @@ +#!/usr/bin/python + +## +## Copyright (C) 2008 Red Hat, Inc. All Rights Reserved. +## +## The Following Agent Has Been Tested On: +## +## Model Firmware +## +--------------------+---------------------------+ +## (1) Main application BRET85K, rev 16 +## Boot ROM BRBR67D, rev 16 +## Remote Control BRRG67D, rev 16 +## +##### + +import sys, re, pexpect +sys.path.append("../lib/") +from fencing import * + +def get_power_status(conn, options): + try: + node_cmd = "system:blade\[" + options["-n"] + "\]>" + + conn.send("env -T system:blade[" + options["-n"] + "]\r\n") + conn.log_expect(options, node_cmd, SHELL_TIMEOUT) + conn.send("power -state\r\n") + conn.log_expect(options, node_cmd, SHELL_TIMEOUT) + status = conn.before.splitlines()[-1] + conn.send("env -T system\r\n") + conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + except pexpect.EOF: + fail(EC_CONNECTION_LOST) + except pexpect.TIMEOUT: + fail(EC_TIMED_OUT) + + return status.lower().strip() + +def set_power_status(conn, options): + action = { + 'on' : "powerup", + 'off': "powerdown" + }[options["-o"]] + + try: + node_cmd = "system:blade\[" + options["-n"] + "\]>" + + conn.send("env -T system:blade[" + options["-n"] + "]\r\n") + conn.log_expect(options, node_cmd, SHELL_TIMEOUT) + conn.send("power -"+options["-o"]+"\r\n") + conn.log_expect(options, node_cmd, SHELL_TIMEOUT) + conn.send("env -T system\r\n") + conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + except pexcept.EOF: + fail(EC_CONNECTION_LOST) + except pexcept.TIMEOUT: + fail(EC_TIMED_OUT) + +def main(): + device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", + "action", "ipaddr", "login", "passwd", "passwd_script", + "cmd_prompt", "secure", "port" ] + + options = check_input(device_opt, process_input(device_opt)) + + ## + ## Fence agent specific defaults + ##### + if 0 == options.has_key("-c"): + options["-c"] = "system>" + + ## + ## Operate the fencing device + ###### + conn = fence_login(options) + fence_action(conn, options, set_power_status, get_power_status) + + ## + ## Logout from system + ###### + conn.send("exit\r\n") + conn.close() + +if __name__ == "__main__": + main() diff --git a/fence/agents/drac/drac5.py b/fence/agents/drac/drac5.py new file mode 100755 index 0000000..63012fc --- /dev/null +++ b/fence/agents/drac/drac5.py @@ -0,0 +1,73 @@ +#!/usr/bin/python + +## +## Copyright (C) 2008 Red Hat, Inc. All Rights Reserved. +## +## The Following Agent Has Been Tested On: +## +## DRAC Version Firmware +## +-----------------+---------------------------+ +## DRAC 5 1.0 (Build 06.05.12) +## DRAC 5 1.21 (Build 07.05.04) +## +## @note: drac_version, modulename were removed +##### + +import sys, re, pexpect +sys.path.append("../lib/") +from fencing import * + +def get_power_status(conn, options): + try: + conn.sendline("racadm serveraction powerstatus") + conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + except pexpect.EOF: + fail(EC_CONNECTION_LOST) + except pexpect.TIMEOUT: + fail(EC_TIMED_OUT) + + status = re.compile("Server power status: (.*)", re.IGNORECASE).search(conn.before).group(1) + return status.lower().strip() + +def set_power_status(conn, options): + action = { + 'on' : "powerup", + 'off': "powerdown" + }[options["-o"]] + + try: + conn.sendline("racadm serveraction " + action) + conn.log_expect(options, options["-c"], POWER_TIMEOUT) + except pexcept.EOF: + fail(EC_CONNECTION_LOST) + except pexcept.TIMEOUT: + fail(EC_TIMED_OUT) + +def main(): + device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", + "action", "ipaddr", "login", "passwd", "passwd_script", + "cmd_prompt", "secure", + "drac_version", "module_name" ] + + 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) + fence_action(conn, options, set_power_status, get_power_status) + + ## + ## Logout from system + ###### + conn.sendline("exit") + conn.close() + +if __name__ == "__main__": + main() diff --git a/fence/agents/ilo/ilo.py b/fence/agents/ilo/ilo.py new file mode 100755 index 0000000..1f3e330 --- /dev/null +++ b/fence/agents/ilo/ilo.py @@ -0,0 +1,71 @@ +#!/usr/bin/python + +## +## Copyright (C) 2008 Red Hat, Inc. All Rights Reserved. +## +## The Following Agent Has Been Tested On: +## +## iLO Version +## +---------------------------------------------+ +## iLO Advanced 1.91 +## +## @note: We can't use conn.sendline because we need to send CR/LF +##### + +import sys, re, pexpect +sys.path.append("../lib/") +from fencing import * + +def get_power_status(conn, options): + try: + conn.send("POWER\r\n") + conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + except pexpect.EOF: + fail(EC_CONNECTION_LOST) + except pexpect.TIMEOUT: + fail(EC_TIMED_OUT) + + status = re.compile("server power is currently: (.*)", re.IGNORECASE).search(conn.before).group(1) + return status.lower().strip() + +def set_power_status(conn, options): + action = { + 'on' : "powerup", + 'off': "powerdown" + }[options["-o"]] + + try: + conn.send("power " + options["-o"] + "\r\n") + conn.log_expect(options, options["-c"], POWER_TIMEOUT) + except pexcept.EOF: + fail(EC_CONNECTION_LOST) + except pexcept.TIMEOUT: + fail(EC_TIMED_OUT) + +def main(): + device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", + "action", "ipaddr", "login", "passwd", "passwd_script", + "secure", "ribcl" ] + + options = check_input(device_opt, process_input(device_opt)) + + ## + ## Fence agent specific defaults + ##### + if 0 == options.has_key("-c"): + options["-c"] = "hpiLO->" + + ## + ## Operate the fencing device + #### + conn = fence_login(options) + fence_action(conn, options, set_power_status, get_power_status) + + ## + ## Logout from system + ###### + conn.send("quit\r\n") + conn.close() + +if __name__ == "__main__": + main() diff --git a/fence/agents/lib/fencing.py b/fence/agents/lib/fencing.py new file mode 100644 index 0000000..39d1285 --- /dev/null +++ b/fence/agents/lib/fencing.py @@ -0,0 +1,339 @@ +#!/usr/bin/python + +## +## Copyright (C) 2008 Red Hat, Inc. All Rights Reserved. +## +##### +import sys, getopt, time, os +import pexpect, re +import telnetlib + +POWER_TIMEOUT = 20 +SHELL_TIMEOUT = 3 +LOGIN_TIMEOUT = 5 + +LOG_MODE_VERBOSE = 100 +LOG_MODE_QUIET = 0 + +EC_BAD_ARGS = 2 +EC_LOGIN_DENIED = 3 +EC_CONNECTION_LOST = 4 +EC_TIMED_OUT = 5 +EC_WAITING_ON = 6 +EC_WAITING_OFF = 7 + +all_opt = { + "help" : { + "getopt" : "h", + "help" : "-h Display this help and exit", + "order" : 54 }, + "version" : { + "getopt" : "V", + "help" : "-V Output version information and exit", + "order" : 53 }, + "quiet" : { + "getopt" : "q", + "help" : "-q Quiet mode", + "order" : 50 }, + "verbose" : { + "getopt" : "v", + "help" : "-v Verbose mode", + "order" : 51 }, + "debug" : { + "getopt" : "D:", + "help" : "-D Debugging to output file", + "order" : 52 }, + "agent" : { + "getopt" : "", + "help" : "", + "order" : 1 }, + "action" : { + "getopt" : "o:", + "help" : "-o Action: status, reboot (default), off or on", + "order" : 1 }, + "ipaddr" : { + "getopt" : "a:", + "help" : "-a IP address or hostname of fencing device", + "order" : 1 }, + "login" : { + "getopt" : "l:", + "help" : "-l Login name", + "order" : 1 }, + "no_login" : { + "getopt" : "", + "help" : "", + "order" : 1 }, + "passwd" : { + "getopt" : "p:", + "help" : "-p Login password", + "order" : 1 }, + "passwd_script" : { + "getopt" : "S:", + "help" : "-S