diff --git a/fence/agents/alom/fence_alom.py b/fence/agents/alom/fence_alom.py index abe0a1ab..f1810d20 100644 --- a/fence/agents/alom/fence_alom.py +++ b/fence/agents/alom/fence_alom.py @@ -1,68 +1,66 @@ #!/usr/bin/python # The Following Agent Has Been Tested On: # # Sun(tm) Advanced Lights Out Manager CMT v1.6.1 # as found on SUN T2000 Niagara import sys, re, pexpect, time, exceptions sys.path.append("@FENCEAGENTSLIBDIR@") from fencing import * #BEGIN_VERSION_GENERATION RELEASE_VERSION="Sun Advanced Lights Out Manager (ALOM)" REDHAT_COPYRIGHT="" BUILD_DATE="" #END_VERSION_GENERATION def get_power_status(conn, options): conn.send_eol("showplatform") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) status = re.search("standby", conn.before.lower()) result = (status != None and "off" or "on") return result def set_power_status(conn, options): cmd_line = (options["--action"] == "on" and "poweron" or "poweroff -f -y") conn.send_eol(cmd_line) conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"])) # Get the machine some time between poweron and poweroff time.sleep(int(options["--power-timeout"])) def main(): device_opt = [ "ipaddr", "login", "passwd", "passwd_script", "cmd_prompt", "secure", "identity_file", "test", "inet4_only", "inet6_only", "ipport" ] atexit.register(atexit_handler) all_opt["secure"]["default"] = "1" all_opt["cmd_prompt"]["default"] = [ "sc\>\ " ] options = check_input(device_opt, process_input(device_opt)) options["telnet_over_ssh"] = 1 docs = { } docs["shortdesc"] = "Fence agent for Sun ALOM" docs["longdesc"] = "fence_alom is an I/O Fencing \ agent which can be used with ALOM connected machines." docs["vendorurl"] = "http://www.sun.com" show_docs(options, docs) # Operate the fencing device conn = fence_login(options) result = fence_action(conn, options, set_power_status, get_power_status, None) # Logout from system try: conn.send_eol("logout") conn.close() - except exceptions.OSError: - pass - except pexpect.ExceptionPexpect: + except: pass sys.exit(result) if __name__ == "__main__": main() diff --git a/fence/agents/apc/fence_apc.py b/fence/agents/apc/fence_apc.py index 9236a309..e98d9ce9 100644 --- a/fence/agents/apc/fence_apc.py +++ b/fence/agents/apc/fence_apc.py @@ -1,228 +1,226 @@ #!/usr/bin/python ##### ## ## The Following Agent Has Been Tested On: ## ## Model Firmware ## +---------------------------------------------+ ## AP7951 AOS v2.7.0, PDU APP v2.7.3 ## AP7941 AOS v3.5.7, PDU APP v3.5.6 ## AP9606 AOS v2.5.4, PDU APP v2.7.3 ## ## @note: ssh is very slow on AP79XX devices protocol (1) and ## cipher (des/blowfish) have to be defined ##### import sys, re, pexpect, exceptions sys.path.append("@FENCEAGENTSLIBDIR@") from fencing import * #BEGIN_VERSION_GENERATION RELEASE_VERSION="New APC Agent - test release on steroids" REDHAT_COPYRIGHT="" BUILD_DATE="March, 2008" #END_VERSION_GENERATION def get_power_status(conn, options): exp_result = 0 outlets = {} conn.send_eol("1") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) version = 0 admin = 0 switch = 0 if (None != re.compile('.* MasterSwitch plus.*', re.IGNORECASE | re.S).match(conn.before)): switch = 1 if (None != re.compile('.* MasterSwitch plus 2', re.IGNORECASE | re.S).match(conn.before)): if (0 == options.has_key("--switch")): fail_usage("Failed: You have to enter physical switch number") else: if (0 == options.has_key("--switch")): options["--switch"] = "1" if (None == re.compile('.*Outlet Management.*', re.IGNORECASE | re.S).match(conn.before)): version = 2 else: version = 3 if (None == re.compile('.*Outlet Control/Configuration.*', re.IGNORECASE | re.S).match(conn.before)): admin = 0 else: admin = 1 if switch == 0: if version == 2: if admin == 0: conn.send_eol("2") else: conn.send_eol("3") else: conn.send_eol("2") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) conn.send_eol("1") else: conn.send_eol(options["--switch"]) while True: exp_result = conn.log_expect(options, [ options["--command-prompt"], "Press " ], int(options["--shell-timeout"])) lines = conn.before.split("\n") show_re = re.compile('(^|\x0D)\s*(\d+)- (.*?)\s+(ON|OFF)\s*') for x in lines: res = show_re.search(x) if (res != None): outlets[res.group(2)] = (res.group(3), res.group(4)) conn.send_eol("") if exp_result == 0: break conn.send(chr(03)) conn.log_expect(options, "- Logout", int(options["--shell-timeout"])) conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) if ["list", "monitor"].count(options["--action"]) == 1: return outlets else: try: (_, status) = outlets[options["--plug"]] return status.lower().strip() except KeyError: fail(EC_STATUS) def set_power_status(conn, options): action = { 'on' : "1", 'off': "2" }[options["--action"]] conn.send_eol("1") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) version = 0 admin2 = 0 admin3 = 0 switch = 0 if (None != re.compile('.* MasterSwitch plus.*', re.IGNORECASE | re.S).match(conn.before)): switch = 1 ## MasterSwitch has different schema for on/off actions action = { 'on' : "1", 'off': "3" }[options["--action"]] if (None != re.compile('.* MasterSwitch plus 2', re.IGNORECASE | re.S).match(conn.before)): if (0 == options.has_key("--switch")): fail_usage("Failed: You have to enter physical switch number") else: if (0 == options.has_key("--switch")): options["--switch"] = 1 if (None == re.compile('.*Outlet Management.*', re.IGNORECASE | re.S).match(conn.before)): version = 2 else: version = 3 if (None == re.compile('.*Outlet Control/Configuration.*', re.IGNORECASE | re.S).match(conn.before)): admin2 = 0 else: admin2 = 1 if switch == 0: if version == 2: if admin2 == 0: conn.send_eol("2") else: conn.send_eol("3") else: conn.send_eol("2") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) if (None == re.compile('.*2- Outlet Restriction.*', re.IGNORECASE | re.S).match(conn.before)): admin3 = 0 else: admin3 = 1 conn.send_eol("1") else: conn.send_eol(options["--switch"]) while 1 == conn.log_expect(options, [ options["--command-prompt"], "Press " ], int(options["--shell-timeout"])): conn.send_eol("") conn.send_eol(options["--plug"]+"") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) if switch == 0: if admin2 == 1: conn.send_eol("1") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) if admin3 == 1: conn.send_eol("1") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) else: conn.send_eol("1") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) conn.send_eol(action) conn.log_expect(options, "Enter 'YES' to continue or to cancel :", int(options["--shell-timeout"])) conn.send_eol("YES") conn.log_expect(options, "Press to continue...", int(options["--shell-timeout"])) conn.send_eol("") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) conn.send(chr(03)) conn.log_expect(options, "- Logout", int(options["--shell-timeout"])) conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) def main(): device_opt = [ "ipaddr", "login", "passwd", "passwd_script", "cmd_prompt", "secure", "port", "identity_file", "switch", "test", "separator", "inet4_only", "inet6_only", "ipport" ] atexit.register(atexit_handler) all_opt["cmd_prompt"]["default"] = "\n>" options = check_input(device_opt, process_input(device_opt)) options["ssh_options"] = "-1 -c blowfish" docs = { } docs["shortdesc"] = "Fence agent for APC over telnet/ssh" docs["longdesc"] = "fence_apc is an I/O Fencing agent \ which can be used with the APC network power switch. It logs into device \ via telnet/ssh and reboots a specified outlet. Lengthy telnet/ssh connections \ should be avoided while a GFS cluster is running because the connection \ will block any necessary fencing actions." docs["vendorurl"] = "http://www.apc.com" show_docs(options, docs) ## Support for --plug [switch]:[plug] notation that was used before if (options.has_key("--plug") == 1) and (-1 != options["--plug"].find(":")): (switch, plug) = options["--plug"].split(":", 1) options["--switch"] = switch options["--plug"] = plug ## ## Operate the fencing device #### conn = fence_login(options) result = fence_action(conn, options, set_power_status, get_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_eol("4") conn.close() - except exceptions.OSError: - pass - except pexpect.ExceptionPexpect: + except: pass sys.exit(result) if __name__ == "__main__": main() diff --git a/fence/agents/bladecenter/fence_bladecenter.py b/fence/agents/bladecenter/fence_bladecenter.py index cf38e10c..2a0caf95 100644 --- a/fence/agents/bladecenter/fence_bladecenter.py +++ b/fence/agents/bladecenter/fence_bladecenter.py @@ -1,121 +1,119 @@ #!/usr/bin/python ##### ## ## 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, exceptions sys.path.append("@FENCEAGENTSLIBDIR@") from fencing import * #BEGIN_VERSION_GENERATION RELEASE_VERSION="New Bladecenter Agent - test release on steroids" REDHAT_COPYRIGHT="" BUILD_DATE="March, 2008" #END_VERSION_GENERATION def get_power_status(conn, options): node_cmd = "system:blade\[" + options["--plug"] + "\]>" conn.send_eol("env -T system:blade[" + options["--plug"] + "]") i = conn.log_expect(options, [ node_cmd, "system>" ] , int(options["--shell-timeout"])) if i == 1: ## Given blade number does not exist if options.has_key("--missing-as-off"): return "off" else: fail(EC_STATUS) conn.send_eol("power -state") conn.log_expect(options, node_cmd, int(options["--shell-timeout"])) status = conn.before.splitlines()[-1] conn.send_eol("env -T system") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) return status.lower().strip() def set_power_status(conn, options): node_cmd = "system:blade\[" + options["--plug"] + "\]>" conn.send_eol("env -T system:blade[" + options["--plug"] + "]") i = conn.log_expect(options, [ node_cmd, "system>" ] , int(options["--shell-timeout"])) if i == 1: ## Given blade number does not exist if options.has_key("--missing-as-off"): return else: fail(EC_GENERIC_ERROR) conn.send_eol("power -"+options["--action"]) conn.log_expect(options, node_cmd, int(options["--shell-timeout"])) conn.send_eol("env -T system") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) def get_blades_list(conn, options): outlets = { } node_cmd = "system>" conn.send_eol("env -T system") conn.log_expect(options, node_cmd, int(options["--shell-timeout"])) conn.send_eol("list -l 2") conn.log_expect(options, node_cmd, int(options["--shell-timeout"])) lines = conn.before.split("\r\n") filter_re = re.compile("^\s*blade\[(\d+)\]\s+(.*?)\s*$") for blade_line in lines: res = filter_re.search(blade_line) if res != None: outlets[res.group(1)] = (res.group(2), "") return outlets def main(): device_opt = [ "ipaddr", "login", "passwd", "passwd_script", "cmd_prompt", "secure", "port", "identity_file", "separator", "inet4_only", "inet6_only", "ipport", "missing_as_off" ] atexit.register(atexit_handler) all_opt["power_wait"]["default"] = "10" all_opt["cmd_prompt"]["default"] = "system>" options = check_input(device_opt, process_input(device_opt)) docs = { } docs["shortdesc"] = "Fence agent for IBM BladeCenter" docs["longdesc"] = "fence_bladecenter is an I/O Fencing agent \ which can be used with IBM Bladecenters with recent enough firmware that \ includes telnet support. It logs into a Brocade chasis via telnet or ssh \ and uses the command line interface to power on and off blades." docs["vendorurl"] = "http://www.ibm.com" show_docs(options, docs) ## ## Operate the fencing device ###### conn = fence_login(options) result = fence_action(conn, options, set_power_status, get_power_status, get_blades_list) ## ## Logout from system ###### try: conn.send_eol("exit") conn.close() - except exceptions.OSError: - pass - except pexpect.ExceptionPexpect: + except: pass sys.exit(result) if __name__ == "__main__": main() diff --git a/fence/agents/drac5/fence_drac5.py b/fence/agents/drac5/fence_drac5.py index bce8cefe..47d8db72 100644 --- a/fence/agents/drac5/fence_drac5.py +++ b/fence/agents/drac5/fence_drac5.py @@ -1,125 +1,123 @@ #!/usr/bin/python ##### ## ## 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 was removed ##### import sys, re, pexpect, exceptions, time sys.path.append("@FENCEAGENTSLIBDIR@") from fencing import * #BEGIN_VERSION_GENERATION RELEASE_VERSION="New Drac5 Agent - test release on steroids" REDHAT_COPYRIGHT="" BUILD_DATE="March, 2008" #END_VERSION_GENERATION def get_power_status(conn, options): if options["model"] == "DRAC CMC": conn.send_eol("racadm serveraction powerstatus -m " + options["--module-name"]) elif options["model"] == "DRAC 5": conn.send_eol("racadm serveraction powerstatus") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) status = re.compile("(^|: )(ON|OFF|Powering ON|Powering OFF)\s*$", re.IGNORECASE | re.MULTILINE).search(conn.before).group(2) if status.lower().strip() in ["on", "powering on", "powering off"]: return "on" else: return "off" def set_power_status(conn, options): action = { 'on' : "powerup", 'off': "powerdown" }[options["--action"]] if options["model"] == "DRAC CMC": conn.send_eol("racadm serveraction " + action + " -m " + options["--module-name"]) elif options["model"] == "DRAC 5": conn.send_eol("racadm serveraction " + action) conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"])) def get_list_devices(conn, options): outlets = { } if options["model"] == "DRAC CMC": conn.send_eol("getmodinfo") list_re = re.compile("^([^\s]*?)\s+Present\s*(ON|OFF)\s*.*$") conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"])) for line in conn.before.splitlines(): if (list_re.search(line)): outlets[list_re.search(line).group(1)] = ("", list_re.search(line).group(2)) elif options["model"] == "DRAC 5": ## DRAC 5 can be used only for one computer ## standard fence library can't handle correctly situation ## when some fence devices supported by fence agent ## works with 'list' and other should returns 'N/A' print "N/A" return outlets def main(): device_opt = [ "ipaddr", "login", "passwd", "passwd_script", "cmd_prompt", "secure", "identity_file", "drac_version", "module_name", "separator", "inet4_only", "inet6_only", "ipport" ] atexit.register(atexit_handler) all_opt["cmd_prompt"]["default"] = [ "\$" ] options = check_input(device_opt, process_input(device_opt)) docs = { } docs["shortdesc"] = "Fence agent for Dell DRAC CMC/5" docs["longdesc"] = "fence_drac5 is an I/O Fencing agent \ which can be used with the Dell Remote Access Card v5 or CMC (DRAC). \ This device provides remote access to controlling power to a server. \ It logs into the DRAC through the telnet/ssh interface of the card. \ By default, the telnet interface is not enabled." docs["vendorurl"] = "http://www.dell.com" show_docs(options, docs) ## ## Operate the fencing device ###### conn = fence_login(options) if conn.before.find("CMC") >= 0: if 0 == options.has_key("--module-name") and 0 == ["monitor", "list"].count(options["--action"].lower()): fail_usage("Failed: You have to enter module name (-m)") options["model"] = "DRAC CMC" elif conn.before.find("DRAC 5") >= 0: options["model"] = "DRAC 5" else: ## Assume this is DRAC 5 by default as we don't want to break anything options["model"] = "DRAC 5" result = fence_action(conn, options, set_power_status, get_power_status, get_list_devices) ## ## Logout from system ###### try: conn.send_eol("exit") time.sleep(1) conn.close() - except exceptions.OSError: - pass - except pexpect.ExceptionPexpect: + except: pass sys.exit(result) if __name__ == "__main__": main() diff --git a/fence/agents/hpblade/fence_hpblade.py b/fence/agents/hpblade/fence_hpblade.py index 6532065a..6cea46aa 100644 --- a/fence/agents/hpblade/fence_hpblade.py +++ b/fence/agents/hpblade/fence_hpblade.py @@ -1,99 +1,97 @@ #!/usr/bin/python ##### ## ## The Following Agent Has Been Tested On: ## * BladeSystem c7000 Enclosure ##### import sys, re, pexpect, exceptions sys.path.append("@FENCEAGENTSLIBDIR@") from fencing import * #BEGIN_VERSION_GENERATION RELEASE_VERSION="New Bladecenter Agent - test release on steroids" REDHAT_COPYRIGHT="" BUILD_DATE="March, 2008" #END_VERSION_GENERATION def get_power_status(conn, options): conn.send_eol("show server status " + options["--plug"]) conn.log_expect(options, options["--command-prompt"] , int(options["--shell-timeout"])) power_re = re.compile("^\s*Power: (.*?)\s*$") status = "unknown" for line in conn.before.splitlines(): res = power_re.search(line) if res != None: status = res.group(1) if status == "unknown": if options.has_key("--missing-as-off"): return "off" else: fail(EC_STATUS) return status.lower().strip() def set_power_status(conn, options): if options["--action"] == "on": conn.send_eol("poweron server " + options["--plug"]) elif options["--action"] == "off": conn.send_eol("poweroff server " + options["--plug"] + " force") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) def get_blades_list(conn, options): outlets = { } conn.send_eol("show server list" ) conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) list_re = re.compile("^\s*(.*?)\s+(.*?)\s+(.*?)\s+OK\s+(.*?)\s+(.*?)\s*$") for line in conn.before.splitlines(): res = list_re.search(line) if res != None: outlets[res.group(1)] = (res.group(2), res.group(4).lower()) return outlets def main(): device_opt = [ "ipaddr", "login", "passwd", "passwd_script", "cmd_prompt", "secure", "port", "identity_file", "separator", "inet4_only", "inet6_only", "ipport", "missing_as_off" ] atexit.register(atexit_handler) all_opt["cmd_prompt"]["default"] = "c7000oa>" options = check_input(device_opt, process_input(device_opt)) docs = { } docs["shortdesc"] = "Fence agent for HP BladeSystem" docs["longdesc"] = "fence_hpblade is an I/O Fencing agent \ which can be used with HP BladeSystem. It logs into an enclosure via telnet or ssh \ and uses the command line interface to power on and off blades." docs["vendorurl"] = "http://www.hp.com" show_docs(options, docs) ## ## Operate the fencing device ###### options["eol"] = "\n" conn = fence_login(options) result = fence_action(conn, options, set_power_status, get_power_status, get_blades_list) ## ## Logout from system ###### try: conn.send_eol("exit") conn.close() - except exceptions.OSError: - pass - except pexpect.ExceptionPexpect: + except: pass sys.exit(result) if __name__ == "__main__": main() diff --git a/fence/agents/ilo_mp/fence_ilo_mp.py b/fence/agents/ilo_mp/fence_ilo_mp.py index 85764c6d..1e149350 100644 --- a/fence/agents/ilo_mp/fence_ilo_mp.py +++ b/fence/agents/ilo_mp/fence_ilo_mp.py @@ -1,72 +1,70 @@ #!/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 def get_power_status(conn, options): conn.send_eol("show /system1") re_state = re.compile('EnabledState=(.*)', re.IGNORECASE) conn.log_expect(options, re_state, int(options["--shell-timeout"])) status = conn.match.group(1).lower() if status.startswith("enabled"): return "on" else: return "off" def set_power_status(conn, options): if options["--action"] == "on": conn.send_eol("start /system1") else: conn.send_eol("stop -f /system1") conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"])) return def main(): device_opt = [ "ipaddr", "login", "passwd", "passwd_script", "secure", "identity_file", "cmd_prompt", "ipport", "separator", "inet4_only", "inet6_only" ] atexit.register(atexit_handler) all_opt["cmd_prompt"]["default"] = [ "MP>", "hpiLO->" ] all_opt["power_wait"]["default"] = 5 options = check_input(device_opt, process_input(device_opt)) docs = { } docs["shortdesc"] = "Fence agent for HP iLO MP" docs["longdesc"] = "" docs["vendorurl"] = "http://www.hp.com" show_docs(options, docs) conn = fence_login(options) conn.send_eol("SMCLP") ## ## Fence operations #### result = fence_action(conn, options, set_power_status, get_power_status) try: conn.send_eol("exit") - except exceptions.OSError: - pass - except pexpect.ExceptionPexpect: + except: pass sys.exit(result) if __name__ == "__main__": main() diff --git a/fence/agents/lpar/fence_lpar.py b/fence/agents/lpar/fence_lpar.py index 0bae359c..252a659d 100644 --- a/fence/agents/lpar/fence_lpar.py +++ b/fence/agents/lpar/fence_lpar.py @@ -1,148 +1,146 @@ #!/usr/bin/python ##### ## ## The Following Agent Has Been Tested On: ## ## Version ## +---------------------------------------------+ ## Tested on HMC ## ##### import sys, re, pexpect, exceptions sys.path.append("@FENCEAGENTSLIBDIR@") from fencing import * #BEGIN_VERSION_GENERATION RELEASE_VERSION="" REDHAT_COPYRIGHT="" BUILD_DATE="" #END_VERSION_GENERATION def get_power_status(conn, options): if options["--hmc-version"] == "3": conn.send("lssyscfg -r lpar -m " + options["--managed"] + " -n " + options["--plug"] + " -F name,state\n") conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"])) try: status = re.compile("^" + options["--plug"] + ",(.*?),.*$", re.IGNORECASE | re.MULTILINE).search(conn.before).group(1) except AttributeError: fail(EC_STATUS_HMC) elif options["--hmc-version"] == "4": conn.send("lssyscfg -r lpar -m "+ options["--managed"] +" --filter 'lpar_names=" + options["--plug"] + "'\n") conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"])) try: status = re.compile(",state=(.*?),", re.IGNORECASE).search(conn.before).group(1) except AttributeError: fail(EC_STATUS_HMC) ## ## Transformation to standard ON/OFF status if possible if status in ["Running", "Open Firmware", "Shutting Down", "Starting"]: status = "on" else: status = "off" return status def set_power_status(conn, options): if options["--hmc-version"] == "3": conn.send("chsysstate -o " + options["--action"] + " -r lpar -m " + options["--managed"] + " -n " + options["--plug"] + "\n") conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"])) elif options["--hmc-version"] == "4": if options["--action"] == "on": conn.send("chsysstate -o on -r lpar -m " + options["--managed"] + " -n " + options["--plug"] + " -f `lssyscfg -r lpar -F curr_profile " + " -m " + options["--managed"] + " --filter \"lpar_names="+ options["--plug"] +"\"`\n" ) else: conn.send("chsysstate -o shutdown -r lpar --immed" + " -m " + options["--managed"] + " -n " + options["--plug"] + "\n") conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"])) def get_lpar_list(conn, options): outlets = { } if options["--hmc-version"] == "3": conn.send("query_partition_names -m " + options["--managed"] + "\n") conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"])) ## We have to remove first 3 lines (command + header) and last line (part of new prompt) #### res = re.search("^.+?\n(.+?\n){2}(.*)\n.*$", conn.before, re.S) if res == None: fail_usage("Unable to parse output of list command") lines = res.group(2).split("\n") for outlet_line in lines: outlets[outlet_line.rstrip()] = ("", "") elif options["--hmc-version"] == "4": conn.send("lssyscfg -r lpar -m " + options["--managed"] + " -F name:state\n") conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"])) ## We have to remove first line (command) and last line (part of new prompt) #### res = re.search("^.+?\n(.*)\n.*$", conn.before, re.S) if res == None: fail_usage("Unable to parse output of list command") lines = res.group(1).split("\n") for outlet_line in lines: (port, status) = outlet_line.split(":") outlets[port] = ("", status) return outlets def main(): device_opt = [ "ipaddr", "login", "passwd", "passwd_script", "secure", "identity_file", "partition", "managed", "hmc_version", "cmd_prompt", "separator", "inet4_only", "inet6_only", "ipport" ] atexit.register(atexit_handler) all_opt["login_timeout"]["default"] = "15" all_opt["secure"]["default"] = "1" all_opt["cmd_prompt"]["default"] = [ ":~>", "]\$", "\$ " ] options = check_input(device_opt, process_input(device_opt)) docs = { } docs["shortdesc"] = "Fence agent for IBM LPAR" docs["longdesc"] = "" show_docs(options, docs) if 0 == options.has_key("--managed"): fail_usage("Failed: You have to enter name of managed system") if (0 == ["list", "monitor"].count(options["--action"].lower())) and (0 == options.has_key("--plug")): fail_usage("Failed: You have to enter name of the partition") if 1 == options.has_key("--hmc-version") and (options["--hmc-version"] != "3" and options["--hmc-version"] != "4"): fail_usage("Failed: You have to enter valid version number: 3 or 4") ## ## Operate the fencing device #### conn = fence_login(options) result = fence_action(conn, options, set_power_status, get_power_status, get_lpar_list) ## ## Logout from system ###### try: conn.send("quit\r\n") conn.close() - except exceptions.OSError: + except: pass - except pexpect.ExceptionPexpect: - pass sys.exit(result) if __name__ == "__main__": main() diff --git a/fence/agents/rsa/fence_rsa.py b/fence/agents/rsa/fence_rsa.py index e1e303f1..578e34d1 100644 --- a/fence/agents/rsa/fence_rsa.py +++ b/fence/agents/rsa/fence_rsa.py @@ -1,81 +1,79 @@ #!/usr/bin/python ##### ## ## The Following Agent Has Been Tested On: ## Main GFEP25A & Boot GFBP25A ## ##### import sys, re, pexpect, exceptions sys.path.append("@FENCEAGENTSLIBDIR@") from fencing import * #BEGIN_VERSION_GENERATION RELEASE_VERSION="New RSA2 Agent - test release on steroids" REDHAT_COPYRIGHT="" BUILD_DATE="" #END_VERSION_GENERATION def get_power_status(conn, options): conn.send_eol("power state") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) match = re.compile("Power: (.*)", re.IGNORECASE).search(conn.before) if (match != None): status = match.group(1) else: status = "undefined" return status.lower().strip() def set_power_status(conn, options): conn.send_eol("power " + options["--action"]) conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"])) def main(): device_opt = [ "ipaddr", "login", "passwd", "passwd_script", "cmd_prompt", "secure", "identity_file", "ipport" ] atexit.register(atexit_handler) all_opt["login_timeout"]["default"] = 10 all_opt["cmd_prompt"]["default"] = [ ">" ] options = check_input(device_opt, process_input(device_opt)) # This device will not allow us to login even with LANG=C options["ssh_options"] = "-F /dev/null" docs = { } docs["shortdesc"] = "Fence agent for IBM RSA" docs["longdesc"] = "fence_rsa is an I/O Fencing agent \ which can be used with the IBM RSA II management interface. It \ logs into an RSA II device via telnet and reboots the associated \ machine. Lengthy telnet connections to the RSA II device should \ be avoided while a GFS cluster is running because the connection \ will block any necessary fencing actions." docs["vendorurl"] = "http://www.ibm.com" show_docs(options, docs) ## ## Operate the fencing device ###### conn = fence_login(options) result = fence_action(conn, options, set_power_status, get_power_status, None) ## ## Logout from system ###### try: conn.send_eol("exit") conn.close() - except exceptions.OSError: - pass - except pexpect.ExceptionPexpect: + except: pass sys.exit(result) if __name__ == "__main__": main() diff --git a/fence/agents/rsb/fence_rsb.py b/fence/agents/rsb/fence_rsb.py index 395a8447..87ed53a7 100755 --- a/fence/agents/rsb/fence_rsb.py +++ b/fence/agents/rsb/fence_rsb.py @@ -1,99 +1,97 @@ #!/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 def get_power_status(conn, options): conn.send("2") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) status = re.compile("Power Status : (on|off)", re.IGNORECASE).search(conn.before).group(1) conn.send("0") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) return (status.lower().strip()) def set_power_status(conn, options): action = { 'on' : "4", 'off': "1" }[options["--action"]] conn.send("2") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) conn.send_eol(action) conn.log_expect(options, ["want to power off", "'yes' or 'no'"], int(options["--shell-timeout"])) conn.send_eol("yes") conn.log_expect(options, "any key to continue", int(options["--power-timeout"])) conn.send_eol("") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) conn.send_eol("0") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) def main(): device_opt = [ "ipaddr", "login", "passwd", "passwd_script", "secure", "identity_file", "separator", "cmd_prompt", "inet4_only", "inet6_only", "ipport", "telnet_port" ] atexit.register(atexit_handler) all_opt["telnet_port"] = { "getopt" : "n:", "longopt" : "telnet_port", "help" : "-n TCP port to use (deprecated, use -u)", "required" : "0", "shortdesc" : "TCP port to use for connection with device (default is 3172 for telnet)", "order" : 1 } all_opt["cmd_prompt"]["default"] = "to quit:" opt = process_input(device_opt) # option -n for backward compatibility (-n is normally port no) if 1 == opt.has_key("-n"): opt["-u"] = opt["-n"] # set default port for telnet only if 0 == opt.has_key("-x") and 0 == opt.has_key("-u"): opt["--ipport"] = 3172 options = check_input(device_opt, opt) docs = { } docs["shortdesc"] = "I/O Fencing agent for Fujitsu-Siemens RSB" docs["longdesc"] = "fence_rsb is an I/O Fencing agent \ which can be used with the Fujitsu-Siemens RSB management interface. It logs \ into device via telnet/ssh and reboots a specified outlet. Lengthy telnet/ssh \ connections should be avoided while a GFS cluster is running because the connection \ will block any necessary fencing actions." docs["vendorurl"] = "http://www.fujitsu.com" show_docs(options, docs) ## ## Operate the fencing device #### conn = fence_login(options) result = fence_action(conn, options, set_power_status, get_power_status, None) ## ## 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_eol("0") conn.close() - except exceptions.OSError: - pass - except pexpect.ExceptionPexpect: + except: pass sys.exit(result) if __name__ == "__main__": main() diff --git a/fence/agents/virsh/fence_virsh.py b/fence/agents/virsh/fence_virsh.py index b1573851..113de8fd 100644 --- a/fence/agents/virsh/fence_virsh.py +++ b/fence/agents/virsh/fence_virsh.py @@ -1,101 +1,99 @@ #!/usr/bin/python # The Following Agent Has Been Tested On: # # Virsh 0.3.3 on RHEL 5.2 with xen-3.0.3-51 # import sys, re, pexpect, exceptions sys.path.append("@FENCEAGENTSLIBDIR@") from fencing import * #BEGIN_VERSION_GENERATION RELEASE_VERSION="Virsh fence agent" REDHAT_COPYRIGHT="" BUILD_DATE="" #END_VERSION_GENERATION def get_outlets_status(conn, options): if options.has_key("-d"): prefix = SUDO_PATH + " " else: prefix = "" conn.sendline(prefix + "virsh list --all") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) result = {} #This is status of mini finite automata. 0 = we didn't found Id and Name, 1 = we did fa_status = 0 for line in conn.before.splitlines(): domain = re.search("^\s*(\S+)\s+(\S+)\s+(\S+).*$", line) if (domain!=None): if ((fa_status==0) and (domain.group(1).lower()=="id") and (domain.group(2).lower()=="name")): fa_status = 1 elif (fa_status==1): result[domain.group(2)] = ("", (domain.group(3).lower() in ["running", "blocked", "idle", "no state", "paused"] and "on" or "off")) return result def get_power_status(conn, options): outlets = get_outlets_status(conn, options) if (not (options["--plug"] in outlets)): fail_usage("Failed: You have to enter existing name of virtual machine!") else: return outlets[options["--plug"]][1] def set_power_status(conn, options): if options.has_key("-d"): prefix = SUDO_PATH + " " else: prefix = "" conn.sendline(prefix + "virsh %s "%(options["--action"] == "on" and "start" or "destroy")+options["--plug"]) conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"])) time.sleep(1) def main(): device_opt = [ "ipaddr", "login", "passwd", "passwd_script", "cmd_prompt", "secure", "identity_file", "test", "port", "separator", "inet4_only", "inet6_only", "ipport", "sudo" ] atexit.register(atexit_handler) all_opt["secure"]["default"] = "1" all_opt["cmd_prompt"]["default"] = [ "\[EXPECT\]#\ " ] options = check_input(device_opt, process_input(device_opt)) options["ssh_options"] = "-t '/bin/bash -c \"PS1=\[EXPECT\]#\ /bin/bash --noprofile --norc\"'" docs = { } docs["shortdesc"] = "Fence agent for virsh" docs["longdesc"] = "fence_virsh is an I/O Fencing agent \ which can be used with the virtual machines managed by libvirt. \ It logs via ssh to a dom0 and there run virsh command, which does \ all work. \ \n.P\n\ By default, virsh needs root account to do properly work. So you \ must allow ssh login in your sshd_config." show_docs(options, docs) ## Operate the fencing device conn = fence_login(options) result = fence_action(conn, options, set_power_status, get_power_status, get_outlets_status) ## Logout from system try: conn.sendline("quit") conn.close() - except exceptions.OSError: - pass - except pexpect.ExceptionPexpect: + except: pass sys.exit(result) if __name__ == "__main__": main() diff --git a/fence/agents/wti/fence_wti.py b/fence/agents/wti/fence_wti.py index 80b5e968..063352e5 100644 --- a/fence/agents/wti/fence_wti.py +++ b/fence/agents/wti/fence_wti.py @@ -1,162 +1,160 @@ #!/usr/bin/python ##### ## ## The Following Agent Has Been Tested On: ## ## Version Firmware ## +-----------------+---------------------------+ ## WTI RSM-8R4 ?? unable to find out ?? ## WTI MPC-??? ?? unable to find out ?? ## WTI IPS-800-CE v1.40h (no username) ('list' tested) ##### import sys, re, pexpect, exceptions sys.path.append("@FENCEAGENTSLIBDIR@") from fencing import * #BEGIN_VERSION_GENERATION RELEASE_VERSION="New WTI Agent - test release on steroids" REDHAT_COPYRIGHT="" BUILD_DATE="March, 2008" #END_VERSION_GENERATION def get_power_status(conn, options): listing = "" conn.send("/S"+"\r\n") if isinstance(options["--command-prompt"], list): re_all = list(options["--command-prompt"]) else: re_all = [options["--command-prompt"]] re_next = re.compile("Enter: ", re.IGNORECASE) re_all.append(re_next) result = conn.log_expect(options, re_all, int(options["--shell-timeout"])) listing = conn.before if result == (len(re_all) - 1): conn.send("\r\n") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) listing += conn.before plug_section = 0 plug_index = -1 name_index = -1 status_index = -1 plug_header = list() outlets = {} for line in listing.splitlines(): if (plug_section == 2) and line.find("|") >= 0 and line.startswith("PLUG") == False: plug_line = [x.strip().lower() for x in line.split("|")] if len(plug_line) < len(plug_header): plug_section = -1 if ["list", "monitor"].count(options["--action"]) == 0 and options["--plug"].lower() == plug_line[plug_index]: return plug_line[status_index] else: ## We already believe that first column contains plug number if len(plug_line[0]) != 0: outlets[plug_line[0]] = (plug_line[name_index], plug_line[status_index]) elif (plug_section == 1): plug_section = 2 elif (line.upper().startswith("PLUG")): plug_section = 1 plug_header = [x.strip().lower() for x in line.split("|")] plug_index = plug_header.index("plug") name_index = plug_header.index("name") status_index = plug_header.index("status") if ["list", "monitor"].count(options["--action"]) == 1: return outlets else: return "PROBLEM" def set_power_status(conn, options): action = { 'on' : "/on", 'off': "/off" }[options["--action"]] conn.send(action + " " + options["--plug"] + ",y\r\n") conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"])) def main(): device_opt = [ "ipaddr", "login", "passwd", "passwd_script", "cmd_prompt", "secure", "identity_file", "port", "no_login", "no_password", "test", "separator", "inet4_only", "inet6_only", "ipport" ] atexit.register(atexit_handler) all_opt["cmd_prompt"]["default"] = [ "RSM>", "MPC>", "IPS>", "TPS>", "NBB>", "NPS>", "VMR>" ] options = check_input(device_opt, process_input(device_opt)) docs = { } docs["shortdesc"] = "Fence agent for WTI" docs["longdesc"] = "fence_wti is an I/O Fencing agent \ which can be used with the WTI Network Power Switch (NPS). It logs \ into an NPS via telnet or ssh and boots a specified plug. \ Lengthy telnet connections to the NPS should be avoided while a GFS cluster \ is running because the connection will block any necessary fencing actions." docs["vendorurl"] = "http://www.wti.com" show_docs(options, docs) ## ## Operate the fencing device ## ## @note: if it possible that this device does not need either login, password or both of them ##### if 0 == options.has_key("--ssh"): try: try: conn = fspawn(options, TELNET_PATH) conn.send("set binary\n") conn.send("open %s -%s\n"%(options["--ip"], options["-u"])) except pexpect.ExceptionPexpect, ex: sys.stderr.write(str(ex) + "\n") sys.stderr.write("Due to limitations, binary dependencies on fence agents " "are not in the spec file and must be installed separately." + "\n") sys.exit(EC_GENERIC_ERROR) re_login = re.compile("(login: )|(Login Name: )|(username: )|(User Name :)", re.IGNORECASE) re_prompt = re.compile("|".join(map (lambda x: "(" + x + ")", options["--command-prompt"])), re.IGNORECASE) result = conn.log_expect(options, [ re_login, "Password: ", re_prompt ], int(options["--shell-timeout"])) if result == 0: if options.has_key("--username"): conn.send(options["--username"]+"\r\n") result = conn.log_expect(options, [ re_login, "Password: ", re_prompt ], int(options["--shell-timeout"])) else: fail_usage("Failed: You have to set login name") if result == 1: if options.has_key("--password"): conn.send(options["--password"]+"\r\n") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) else: fail_usage("Failed: You have to enter password or password script") except pexpect.EOF: fail(EC_LOGIN_DENIED) except pexpect.TIMEOUT: fail(EC_LOGIN_DENIED) else: conn = fence_login(options) result = fence_action(conn, options, set_power_status, get_power_status, get_power_status) ## ## Logout from system ###### try: conn.send("/X"+"\r\n") conn.close() - except exceptions.OSError: - pass - except pexpect.ExceptionPexpect: + except: pass sys.exit(result) if __name__ == "__main__": main()