diff --git a/fence/agents/alom/fence_alom.py b/fence/agents/alom/fence_alom.py index 8d5a4bdd..3f39b2d1 100644 --- a/fence/agents/alom/fence_alom.py +++ b/fence/agents/alom/fence_alom.py @@ -1,80 +1,68 @@ #!/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): - result = "" - try: - conn.send_eol("showplatform") - conn.log_expect(options, options["-c"], int(options["-Y"])) - status = re.search("standby", conn.before.lower()) - result = (status!=None and "off" or "on") - except pexpect.EOF: - fail(EC_CONNECTION_LOST) - except pexpect.TIMEOUT: - fail(EC_TIMED_OUT) + conn.send_eol("showplatform") + conn.log_expect(options, options["-c"], int(options["-Y"])) + status = re.search("standby", conn.before.lower()) + result = (status != None and "off" or "on") return result def set_power_status(conn, options): - try: - cmd_line = (options["-o"]=="on" and "poweron" or "poweroff -f -y") - conn.send_eol(cmd_line) - conn.log_expect(options, options["-c"], int(options["-g"])) - #Get the machine some time between poweron and poweroff - time.sleep(int(options["-g"])) - - except pexpect.EOF: - fail(EC_CONNECTION_LOST) - except pexpect.TIMEOUT: - fail(EC_TIMED_OUT) + cmd_line = (options["-o"] == "on" and "poweron" or "poweroff -f -y") + conn.send_eol(cmd_line) + conn.log_expect(options, options["-c"], int(options["-g"])) + # Get the machine some time between poweron and poweroff + time.sleep(int(options["-g"])) 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: 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 fa1c3a65..743627a9 100644 --- a/fence/agents/apc/fence_apc.py +++ b/fence/agents/apc/fence_apc.py @@ -1,237 +1,228 @@ #!/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 = {} - try: - conn.send_eol("1") - conn.log_expect(options, options["-c"], int(options["-Y"])) - version = 0 - admin = 0 - switch = 0 + conn.send_eol("1") + conn.log_expect(options, options["-c"], int(options["-Y"])) - 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("-s")): - fail_usage("Failed: You have to enter physical switch number") - else: - if (0 == options.has_key("-s")): - options["-s"] = "1" + version = 0 + admin = 0 + switch = 0 - if (None == re.compile('.*Outlet Management.*', re.IGNORECASE | re.S).match(conn.before)): - version = 2 + 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("-s")): + fail_usage("Failed: You have to enter physical switch number") else: - version = 3 + if (0 == options.has_key("-s")): + options["-s"] = "1" - 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: + 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") - conn.log_expect(options, options["-c"], int(options["-Y"])) - conn.send_eol("1") + else: + conn.send_eol("3") else: - conn.send_eol(options["-s"]) + conn.send_eol("2") + conn.log_expect(options, options["-c"], int(options["-Y"])) + conn.send_eol("1") + else: + conn.send_eol(options["-s"]) - while True: - exp_result = conn.log_expect(options, [ options["-c"], "Press " ], int(options["-Y"])) - 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["-Y"])) - conn.log_expect(options, options["-c"], int(options["-Y"])) - except pexpect.EOF: - fail(EC_CONNECTION_LOST) - except pexpect.TIMEOUT: - fail(EC_TIMED_OUT) + while True: + exp_result = conn.log_expect(options, [ options["-c"], "Press " ], int(options["-Y"])) + 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["-Y"])) + conn.log_expect(options, options["-c"], int(options["-Y"])) if ["list", "monitor"].count(options["-o"]) == 1: return outlets else: try: (_, status) = outlets[options["-n"]] return status.lower().strip() except KeyError: fail(EC_STATUS) def set_power_status(conn, options): action = { 'on' : "1", 'off': "2" }[options["-o"]] - try: - conn.send_eol("1") - conn.log_expect(options, options["-c"], int(options["-Y"])) + conn.send_eol("1") + conn.log_expect(options, options["-c"], int(options["-Y"])) + + 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["-o"]] + if (None != re.compile('.* MasterSwitch plus 2', re.IGNORECASE | re.S).match(conn.before)): + if (0 == options.has_key("-s")): + fail_usage("Failed: You have to enter physical switch number") + else: + if (0 == options.has_key("-s")): + options["-s"] = 1 - 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["-o"]] - if (None != re.compile('.* MasterSwitch plus 2', re.IGNORECASE | re.S).match(conn.before)): - if (0 == options.has_key("-s")): - fail_usage("Failed: You have to enter physical switch number") - else: - if (0 == options.has_key("-s")): - options["-s"] = 1 + if (None == re.compile('.*Outlet Management.*', re.IGNORECASE | re.S).match(conn.before)): + version = 2 + else: + version = 3 - 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 (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: + if switch == 0: + if version == 2: + if admin2 == 0: conn.send_eol("2") - conn.log_expect(options, options["-c"], int(options["-Y"])) - 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("3") else: - conn.send_eol(options["-s"]) + conn.send_eol("2") + conn.log_expect(options, options["-c"], int(options["-Y"])) + 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["-s"]) - while 1 == conn.log_expect(options, [ options["-c"], "Press " ], int(options["-Y"])): - conn.send_eol("") + while 1 == conn.log_expect(options, [ options["-c"], "Press " ], int(options["-Y"])): + conn.send_eol("") - conn.send_eol(options["-n"]+"") - conn.log_expect(options, options["-c"], int(options["-Y"])) + conn.send_eol(options["-n"]+"") + conn.log_expect(options, options["-c"], int(options["-Y"])) - if switch == 0: - if admin2 == 1: - conn.send_eol("1") - conn.log_expect(options, options["-c"], int(options["-Y"])) - if admin3 == 1: - conn.send_eol("1") - conn.log_expect(options, options["-c"], int(options["-Y"])) - else: + if switch == 0: + if admin2 == 1: conn.send_eol("1") conn.log_expect(options, options["-c"], int(options["-Y"])) - - conn.send_eol(action) - conn.log_expect(options, "Enter 'YES' to continue or to cancel :", int(options["-Y"])) - conn.send_eol("YES") - conn.log_expect(options, "Press to continue...", int(options["-Y"])) - conn.send_eol("") - conn.log_expect(options, options["-c"], int(options["-Y"])) - conn.send(chr(03)) - conn.log_expect(options, "- Logout", int(options["-Y"])) + if admin3 == 1: + conn.send_eol("1") + conn.log_expect(options, options["-c"], int(options["-Y"])) + else: + conn.send_eol("1") conn.log_expect(options, options["-c"], int(options["-Y"])) - except pexpect.EOF: - fail(EC_CONNECTION_LOST) - except pexpect.TIMEOUT: - fail(EC_TIMED_OUT) + + conn.send_eol(action) + conn.log_expect(options, "Enter 'YES' to continue or to cancel :", int(options["-Y"])) + conn.send_eol("YES") + conn.log_expect(options, "Press to continue...", int(options["-Y"])) + conn.send_eol("") + conn.log_expect(options, options["-c"], int(options["-Y"])) + conn.send(chr(03)) + conn.log_expect(options, "- Logout", int(options["-Y"])) + conn.log_expect(options, options["-c"], int(options["-Y"])) 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 -n [switch]:[plug] notation that was used before if (options.has_key("-n") == 1) and (-1 != options["-n"].find(":")): (switch, plug) = options["-n"].split(":", 1) options["-s"] = switch options["-n"] = 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: 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 2825dbec..726a15f6 100644 --- a/fence/agents/bladecenter/fence_bladecenter.py +++ b/fence/agents/bladecenter/fence_bladecenter.py @@ -1,136 +1,121 @@ #!/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): - try: - node_cmd = "system:blade\[" + options["-n"] + "\]>" - - conn.send_eol("env -T system:blade[" + options["-n"] + "]") - i = conn.log_expect(options, [ node_cmd, "system>" ] , int(options["-Y"])) - if i == 1: - ## Given blade number does not exist - if options.has_key("-M"): - return "off" - else: - fail(EC_STATUS) - conn.send_eol("power -state") - conn.log_expect(options, node_cmd, int(options["-Y"])) - status = conn.before.splitlines()[-1] - conn.send_eol("env -T system") - conn.log_expect(options, options["-c"], int(options["-Y"])) - except pexpect.EOF: - fail(EC_CONNECTION_LOST) - except pexpect.TIMEOUT: - fail(EC_TIMED_OUT) + node_cmd = "system:blade\[" + options["-n"] + "\]>" + + conn.send_eol("env -T system:blade[" + options["-n"] + "]") + i = conn.log_expect(options, [ node_cmd, "system>" ] , int(options["-Y"])) + if i == 1: + ## Given blade number does not exist + if options.has_key("-M"): + return "off" + else: + fail(EC_STATUS) + conn.send_eol("power -state") + conn.log_expect(options, node_cmd, int(options["-Y"])) + status = conn.before.splitlines()[-1] + conn.send_eol("env -T system") + conn.log_expect(options, options["-c"], int(options["-Y"])) return status.lower().strip() def set_power_status(conn, options): - try: - node_cmd = "system:blade\[" + options["-n"] + "\]>" - - conn.send_eol("env -T system:blade[" + options["-n"] + "]") - i = conn.log_expect(options, [ node_cmd, "system>" ] , int(options["-Y"])) - if i == 1: - ## Given blade number does not exist - if options.has_key("-M"): - return - else: - fail(EC_GENERIC_ERROR) - - conn.send_eol("power -"+options["-o"]) - conn.log_expect(options, node_cmd, int(options["-Y"])) - conn.send_eol("env -T system") - conn.log_expect(options, options["-c"], int(options["-Y"])) - except pexpect.EOF: - fail(EC_CONNECTION_LOST) - except pexpect.TIMEOUT: - fail(EC_TIMED_OUT) + node_cmd = "system:blade\[" + options["-n"] + "\]>" + + conn.send_eol("env -T system:blade[" + options["-n"] + "]") + i = conn.log_expect(options, [ node_cmd, "system>" ] , int(options["-Y"])) + if i == 1: + ## Given blade number does not exist + if options.has_key("-M"): + return + else: + fail(EC_GENERIC_ERROR) + + conn.send_eol("power -"+options["-o"]) + conn.log_expect(options, node_cmd, int(options["-Y"])) + conn.send_eol("env -T system") + conn.log_expect(options, options["-c"], int(options["-Y"])) def get_blades_list(conn, options): outlets = { } - try: - node_cmd = "system>" - - conn.send_eol("env -T system") - conn.log_expect(options, node_cmd, int(options["-Y"])) - conn.send_eol("list -l 2") - conn.log_expect(options, node_cmd, int(options["-Y"])) - - 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), "") - - except pexpect.EOF: - fail(EC_CONNECTION_LOST) - except pexpect.TIMEOUT: - fail(EC_TIMED_OUT) + + node_cmd = "system>" + + conn.send_eol("env -T system") + conn.log_expect(options, node_cmd, int(options["-Y"])) + conn.send_eol("list -l 2") + conn.log_expect(options, node_cmd, int(options["-Y"])) + + 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: pass sys.exit(result) if __name__ == "__main__": main() diff --git a/fence/agents/cisco_ucs/fence_cisco_ucs.py b/fence/agents/cisco_ucs/fence_cisco_ucs.py index d1d5f2bd..5ed2c350 100644 --- a/fence/agents/cisco_ucs/fence_cisco_ucs.py +++ b/fence/agents/cisco_ucs/fence_cisco_ucs.py @@ -1,155 +1,143 @@ #!/usr/bin/python import sys, re import pycurl, StringIO sys.path.append("@FENCEAGENTSLIBDIR@") from fencing import * #BEGIN_VERSION_GENERATION RELEASE_VERSION="New Cisco UCS Agent - test release on steroids" REDHAT_COPYRIGHT="" BUILD_DATE="March, 2008" #END_VERSION_GENERATION RE_COOKIE = re.compile("", \ - int(options["-Y"])) - except pycurl.error, e: - sys.stderr.write(e[1] + "\n") - fail(EC_TIMED_OUT) + res = send_command(options, \ + "", \ + int(options["-Y"])) result = RE_STATUS.search(res) if (result == None): fail(EC_STATUS) else: status = result.group(1) if (status == "up"): return "on" else: return "off" def set_power_status(conn, options): action = { 'on' : "up", 'off' : "down" }[options["-o"]] - try: - res = send_command(options, \ + res = send_command(options, \ "" + \ "" + \ "" + \ "", \ int(options["-Y"])) - except pycurl.error, e: - sys.stderr.write(e[1] + "\n") - fail(EC_TIMED_OUT) return def get_list(conn, options): outlets = { } try: - try: - res = send_command(options, \ - "", \ - int(options["-Y"])) - except pycurl.error, e: - sys.stderr.write(e[1] + "\n") - fail(EC_TIMED_OUT) + res = send_command(options, \ + "", \ + int(options["-Y"])) lines = res.split("= LOG_MODE_VERBOSE: opt["debug_fh"].write(command + "\n") opt["debug_fh"].write(result + "\n") return result def main(): device_opt = [ "ipaddr", "login", "passwd", "passwd_script", "ssl", "inet4_only", "inet6_only", "ipport", "port", "web", "separator", "suborg" ] atexit.register(atexit_handler) options = check_input(device_opt, process_input(device_opt)) docs = { } docs["shortdesc"] = "Fence agent for Cisco UCS" docs["longdesc"] = "fence_cisco_ucs is an I/O Fencing agent which can be \ used with Cisco UCS to fence machines." docs["vendorurl"] = "http://www.cisco.com" show_docs(options, docs) ### Login res = send_command(options, "", int(options["-y"])) result = RE_COOKIE.search(res) if (result == None): ## Cookie is absenting in response fail(EC_LOGIN_DENIED) options["cookie"] = result.group(1) ## ## Modify suborg to format /suborg if options["-s"] != "": if options["-s"].startswith("/") == False: options["-s"] = "/" + options["-s"] if options["-s"].endswith("/") == True: options["-s"] = options["-s"][0:-1] ## ## Fence operations #### result = fence_action(None, options, set_power_status, get_power_status, get_list) ### Logout; we do not care about result as we will end in any case send_command(options, "", int(options["-Y"])) sys.exit(result) if __name__ == "__main__": main() diff --git a/fence/agents/drac5/fence_drac5.py b/fence/agents/drac5/fence_drac5.py index d8f4bb86..f8c129d9 100644 --- a/fence/agents/drac5/fence_drac5.py +++ b/fence/agents/drac5/fence_drac5.py @@ -1,140 +1,125 @@ #!/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): - try: - if options["model"] == "DRAC CMC": - conn.send_eol("racadm serveraction powerstatus -m " + options["-m"]) - elif options["model"] == "DRAC 5": - conn.send_eol("racadm serveraction powerstatus") + if options["model"] == "DRAC CMC": + conn.send_eol("racadm serveraction powerstatus -m " + options["-m"]) + elif options["model"] == "DRAC 5": + conn.send_eol("racadm serveraction powerstatus") - conn.log_expect(options, options["-c"], int(options["-Y"])) - except pexpect.EOF: - fail(EC_CONNECTION_LOST) - except pexpect.TIMEOUT: - fail(EC_TIMED_OUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) 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["-o"]] - try: - if options["model"] == "DRAC CMC": - conn.send_eol("racadm serveraction " + action + " -m " + options["-m"]) - elif options["model"] == "DRAC 5": - conn.send_eol("racadm serveraction " + action) - conn.log_expect(options, options["-c"], int(options["-g"])) - except pexpect.EOF: - fail(EC_CONNECTION_LOST) - except pexpect.TIMEOUT: - fail(EC_TIMED_OUT) + if options["model"] == "DRAC CMC": + conn.send_eol("racadm serveraction " + action + " -m " + options["-m"]) + elif options["model"] == "DRAC 5": + conn.send_eol("racadm serveraction " + action) + conn.log_expect(options, options["-c"], int(options["-g"])) def get_list_devices(conn, options): outlets = { } - try: - 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["-c"], int(options["-g"])) - 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" - except pexpect.EOF: - fail(EC_CONNECTION_LOST) - except pexpect.TIMEOUT: - fail(EC_TIMED_OUT) + 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["-c"], int(options["-g"])) + 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("-m") and 0 == ["monitor", "list"].count(options["-o"].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: 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 c7ceb194..c4f045e2 100644 --- a/fence/agents/hpblade/fence_hpblade.py +++ b/fence/agents/hpblade/fence_hpblade.py @@ -1,113 +1,99 @@ #!/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): - try: - conn.send_eol("show server status " + options["-n"]) - conn.log_expect(options, options["-c"] , int(options["-Y"])) + conn.send_eol("show server status " + options["-n"]) + conn.log_expect(options, options["-c"] , int(options["-Y"])) - 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("-M"): - return "off" - else: - fail(EC_STATUS) - except pexpect.EOF: - fail(EC_CONNECTION_LOST) - except pexpect.TIMEOUT: - fail(EC_TIMED_OUT) + 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("-M"): + return "off" + else: + fail(EC_STATUS) return status.lower().strip() def set_power_status(conn, options): - try: - if options["-o"] == "on": - conn.send_eol("poweron server " + options["-n"]) - elif options["-o"] == "off": - conn.send_eol("poweroff server " + options["-n"] + " force") - conn.log_expect(options, options["-c"], int(options["-Y"])) - except pexpect.EOF: - fail(EC_CONNECTION_LOST) - except pexpect.TIMEOUT: - fail(EC_TIMED_OUT) + if options["-o"] == "on": + conn.send_eol("poweron server " + options["-n"]) + elif options["-o"] == "off": + conn.send_eol("poweroff server " + options["-n"] + " force") + conn.log_expect(options, options["-c"], int(options["-Y"])) def get_blades_list(conn, options): outlets = { } - try: - conn.send_eol("show server list" ) - conn.log_expect(options, options["-c"], int(options["-Y"])) - - 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()) - except pexpect.EOF: - fail(EC_CONNECTION_LOST) - except pexpect.TIMEOUT: - fail(EC_TIMED_OUT) + + conn.send_eol("show server list" ) + conn.log_expect(options, options["-c"], int(options["-Y"])) + + 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: pass sys.exit(result) if __name__ == "__main__": main() diff --git a/fence/agents/ilo/fence_ilo.py b/fence/agents/ilo/fence_ilo.py index 715b163b..66472aa9 100644 --- a/fence/agents/ilo/fence_ilo.py +++ b/fence/agents/ilo/fence_ilo.py @@ -1,122 +1,117 @@ #!/usr/bin/python ##### ## ## The Following Agent Has Been Tested On: ## ## iLO Version ## +---------------------------------------------+ ## iLO / firmware 1.91 / RIBCL 2.22 ## iLO2 / firmware 1.22 / RIBCL 2.22 ## iLO2 / firmware 1.50 / RIBCL 2.22 ##### import sys, re, pexpect sys.path.append("@FENCEAGENTSLIBDIR@") from fencing import * #BEGIN_VERSION_GENERATION RELEASE_VERSION="New ILO Agent - test release on steroids" REDHAT_COPYRIGHT="" BUILD_DATE="March, 2008" #END_VERSION_GENERATION def get_power_status(conn, options): conn.send("\r\n") conn.send("\r\n") conn.send("\r\n") - try: - conn.log_expect(options, "HOST_POWER=\"(.*?)\"", int(options["-g"])) - except pexpect.EOF, e: - fail(EC_STATUS) - except pexpect.TIMEOUT, e: - fail(EC_TIMED_OUT) + conn.log_expect(options, "HOST_POWER=\"(.*?)\"", int(options["-g"])) status = conn.match.group(1) return status.lower().strip() def set_power_status(conn, options): conn.send("\r\n") conn.send("") if options.has_key("fw_processor") and options["fw_processor"] == "iLO2": if options["fw_version"] > 1.29: conn.send("\r\n") else: conn.send("\r\n") elif options["-r"] < 2.21: conn.send("\r\n") else: if options["-o"] == "off": conn.send("\r\n") else: conn.send("\r\n") conn.send("\r\n") return def main(): device_opt = [ "ipaddr", "login", "passwd", "passwd_script", "ssl", "ribcl", "inet4_only", "inet6_only", "ipport" ] atexit.register(atexit_handler) all_opt["login_timeout"]["default"] = "10" all_opt["retry_on"]["default"] = "3" all_opt["ssl"]["default"] = "1" options = check_input(device_opt, process_input(device_opt)) docs = { } docs["shortdesc"] = "Fence agent for HP iLO" docs["longdesc"] = "fence_ilo is an I/O Fencing agent \ used for HP servers with the Integrated Light Out (iLO) PCI card.\ The agent opens an SSL connection to the iLO card. Once the SSL \ connection is established, the agent is able to communicate with \ the iLO card through an XML stream." docs["vendorurl"] = "http://www.hp.com" docs["symlink"] = [("fence_ilo2", "Fence agent for HP iLO2")] show_docs(options, docs) ## ## Login and get version number #### conn = fence_login(options) try: conn.send("\r\n") conn.log_expect(options, [ "", "" ], int(options["-y"])) version = re.compile("= 2: conn.send("\r\n") else: conn.send("\r\n") conn.send("\r\n") if options["-r"] >= 2: conn.send("\r\n") conn.send("\r\n") conn.log_expect(options, "", int(options["-Y"])) options["fw_version"] = float(re.compile("FIRMWARE_VERSION\s*=\s*\"(.*?)\"", re.IGNORECASE).search(conn.before).group(1)) options["fw_processor"] = re.compile("MANAGEMENT_PROCESSOR\s*=\s*\"(.*?)\"", re.IGNORECASE).search(conn.before).group(1) conn.send("\r\n") except pexpect.TIMEOUT: fail(EC_LOGIN_DENIED) except pexpect.EOF: fail(EC_LOGIN_DENIED) ## ## Fence operations #### result = fence_action(conn, options, set_power_status, get_power_status, None) 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 9c18336e..7cf068ac 100644 --- a/fence/agents/ilo_mp/fence_ilo_mp.py +++ b/fence/agents/ilo_mp/fence_ilo_mp.py @@ -1,82 +1,72 @@ #!/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): - try: - conn.send_eol("show /system1") + conn.send_eol("show /system1") - re_state = re.compile('EnabledState=(.*)', re.IGNORECASE) - conn.log_expect(options, re_state, int(options["-Y"])) + re_state = re.compile('EnabledState=(.*)', re.IGNORECASE) + conn.log_expect(options, re_state, int(options["-Y"])) - status = conn.match.group(1).lower() + status = conn.match.group(1).lower() - if status.startswith("enabled"): - return "on" - else: - return "off" - except pexpect.EOF: - fail(EC_CONNECTION_LOST) - except pexpect.TIMEOUT: - fail(EC_TIMED_OUT) + if status.startswith("enabled"): + return "on" + else: + return "off" def set_power_status(conn, options): - try: - if options["-o"] == "on": - conn.send_eol("start /system1") - else: - conn.send_eol("stop -f /system1") + if options["-o"] == "on": + conn.send_eol("start /system1") + else: + conn.send_eol("stop -f /system1") - conn.log_expect(options, options["-c"], int(options["-g"])) + conn.log_expect(options, options["-c"], int(options["-g"])) - return - except pexpect.EOF: - fail(EC_CONNECTION_LOST) - except pexpect.TIMEOUT: - fail(EC_TIMED_OUT) + 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: pass sys.exit(result) if __name__ == "__main__": main() diff --git a/fence/agents/ldom/fence_ldom.py b/fence/agents/ldom/fence_ldom.py index edbb2bf7..0d67e3fd 100644 --- a/fence/agents/ldom/fence_ldom.py +++ b/fence/agents/ldom/fence_ldom.py @@ -1,132 +1,120 @@ #!/usr/bin/python ## ## The Following Agent Has Been Tested On - LDOM 1.0.3 ## The interface is backward compatible so it will work ## with 1.0, 1.0.1 and .2 too. ## ##### import sys, re, pexpect, exceptions sys.path.append("@FENCEAGENTSLIBDIR@") from fencing import * #BEGIN_VERSION_GENERATION RELEASE_VERSION="Logical Domains (LDoms) fence Agent" REDHAT_COPYRIGHT="" BUILD_DATE="" #END_VERSION_GENERATION COMMAND_PROMPT_REG = "\[PEXPECT\]$" COMMAND_PROMPT_NEW = "[PEXPECT]" # Start comunicating after login. Prepare good environment. def start_communication(conn, options): conn.send_eol ("PS1='"+COMMAND_PROMPT_NEW+"'") res = conn.expect([pexpect.TIMEOUT, COMMAND_PROMPT_REG], int(options["-Y"])) if res == 0: #CSH stuff conn.send_eol("set prompt='"+COMMAND_PROMPT_NEW+"'") conn.log_expect(options, COMMAND_PROMPT_REG, int(options["-Y"])) def get_power_status(conn, options): - try: - start_communication(conn, options) + start_communication(conn, options) - conn.send_eol("ldm ls") + conn.send_eol("ldm ls") - conn.log_expect(options, COMMAND_PROMPT_REG, int(options["-Y"])) + conn.log_expect(options, COMMAND_PROMPT_REG, int(options["-Y"])) - result = {} + result = {} - #This is status of mini finite automata. 0 = we didn't found NAME and STATE, 1 = we did - fa_status = 0 + #This is status of mini finite automata. 0 = we didn't found NAME and STATE, 1 = we did + fa_status = 0 - for line in conn.before.splitlines(): - domain = re.search("^(\S+)\s+(\S+)\s+.*$", line) - - if (domain!=None): - if ((fa_status==0) and (domain.group(1)=="NAME") and (domain.group(2)=="STATE")): - fa_status = 1 - elif (fa_status==1): - result[domain.group(1)] = ("", (domain.group(2).lower()=="bound" and "off" or "on")) + for line in conn.before.splitlines(): + domain = re.search("^(\S+)\s+(\S+)\s+.*$", line) - except pexpect.EOF: - fail(EC_CONNECTION_LOST) - except pexpect.TIMEOUT: - fail(EC_TIMED_OUT) + if (domain!=None): + if ((fa_status==0) and (domain.group(1)=="NAME") and (domain.group(2)=="STATE")): + fa_status = 1 + elif (fa_status==1): + result[domain.group(1)] = ("", (domain.group(2).lower()=="bound" and "off" or "on")) if (not (options["-o"] in ['monitor','list'])): if (not (options["-n"] in result)): fail_usage("Failed: You have to enter existing logical domain!") else: return result[options["-n"]][1] else: return result def set_power_status(conn, options): - try: - start_communication(conn, options) + start_communication(conn, options) - cmd_line = "ldm "+(options["-o"]=="on" and "start" or "stop -f")+" \""+options["-n"]+"\"" + cmd_line = "ldm "+(options["-o"]=="on" and "start" or "stop -f")+" \""+options["-n"]+"\"" - conn.send_eol(cmd_line) + conn.send_eol(cmd_line) - conn.log_expect(options, COMMAND_PROMPT_REG, int(options["-g"])) - - except pexpect.EOF: - fail(EC_CONNECTION_LOST) - except pexpect.TIMEOUT: - fail(EC_TIMED_OUT) + conn.log_expect(options, COMMAND_PROMPT_REG, int(options["-g"])) def main(): device_opt = [ "ipaddr", "login", "passwd", "passwd_script", "secure", "identity_file", "test" , "port", "cmd_prompt", "separator", "inet4_only", "inet6_only", "ipport" ] atexit.register(atexit_handler) 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 Sun LDOM" docs["longdesc"] = "fence_ldom is an I/O Fencing agent \ which can be used with LDoms virtual machines. This agent works \ so, that run ldm command on host machine. So ldm must be directly \ runnable.\ \n.P\n\ Very useful parameter is -c (or cmd_prompt in stdin mode). This \ must be set to something, what is displayed after successful login \ to host machine. Default string is space on end of string (default \ for root in bash). But (for example) csh use ], so in that case you \ must use parameter -c with argument ]. Very similar situation is, \ if you use bash and login to host machine with other user than \ root. Than prompt is $, so again, you must use parameter -c." 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, get_power_status) ## ## Logout from system ###### try: conn.send_eol("logout") conn.close() except exceptions.OSError: pass except pexpect.ExceptionPexpect: pass sys.exit(result) if __name__ == "__main__": main() diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py index af216962..9612b40d 100644 --- a/fence/agents/lib/fencing.py.py +++ b/fence/agents/lib/fencing.py.py @@ -1,977 +1,991 @@ #!/usr/bin/python import sys, getopt, time, os import pexpect, re, atexit import __main__ ## do not add code here. #BEGIN_VERSION_GENERATION RELEASE_VERSION = "New fence lib agent - test release on steroids" REDHAT_COPYRIGHT = "" BUILD_DATE = "March, 2008" #END_VERSION_GENERATION LOG_MODE_VERBOSE = 100 LOG_MODE_QUIET = 0 EC_GENERIC_ERROR = 1 EC_BAD_ARGS = 2 EC_LOGIN_DENIED = 3 EC_CONNECTION_LOST = 4 EC_TIMED_OUT = 5 EC_WAITING_ON = 6 EC_WAITING_OFF = 7 EC_STATUS = 8 EC_STATUS_HMC = 9 EC_PASSWORD_MISSING = 10 TELNET_PATH = "/usr/bin/telnet" SSH_PATH = "/usr/bin/ssh" SSL_PATH = "@SBINDIR@/fence_nss_wrapper" SUDO_PATH = "/usr/bin/sudo" all_opt = { "help" : { "getopt" : "h", "longopt" : "help", "help" : "-h, --help Display this help and exit", "required" : "0", "shortdesc" : "Display help and exit", "order" : 54 }, "version" : { "getopt" : "V", "longopt" : "version", "help" : "-V, --version Output version information and exit", "required" : "0", "shortdesc" : "Display version information and exit", "order" : 53 }, "quiet" : { "getopt" : "q", "help" : "", "order" : 50 }, "verbose" : { "getopt" : "v", "longopt" : "verbose", "help" : "-v, --verbose Verbose mode", "required" : "0", "shortdesc" : "Verbose mode", "order" : 51 }, "debug" : { "getopt" : "D:", "longopt" : "debug-file", "help" : "-D, --debug-file= Debugging to output file", "required" : "0", "shortdesc" : "Write debug information to given file", "order" : 52 }, "delay" : { "getopt" : "f:", "longopt" : "delay", "help" : "--delay Wait X seconds before fencing is started", "required" : "0", "shortdesc" : "Wait X seconds before fencing is started", "default" : "0", "order" : 200 }, "agent" : { "getopt" : "", "help" : "", "order" : 1 }, "web" : { "getopt" : "", "help" : "", "order" : 1 }, "action" : { "getopt" : "o:", "longopt" : "action", "help" : "-o, --action= Action: status, reboot (default), off or on", "required" : "1", "shortdesc" : "Fencing Action", "default" : "reboot", "order" : 1 }, "fabric_fencing" : { "getopt" : "", "help" : "", "order" : 1 }, "ipaddr" : { "getopt" : "a:", "longopt" : "ip", "help" : "-a, --ip= IP address or hostname of fencing device", "required" : "1", "shortdesc" : "IP Address or Hostname", "order" : 1 }, "ipport" : { "getopt" : "u:", "longopt" : "ipport", "help" : "-u, --ipport= TCP port to use", "required" : "0", "shortdesc" : "TCP port to use for connection with device", "order" : 1 }, "login" : { "getopt" : "l:", "longopt" : "username", "help" : "-l, --username= Login name", "required" : "?", "shortdesc" : "Login Name", "order" : 1 }, "no_login" : { "getopt" : "", "help" : "", "order" : 1 }, "no_password" : { "getopt" : "", "help" : "", "order" : 1 }, "passwd" : { "getopt" : "p:", "longopt" : "password", "help" : "-p, --password= Login password or passphrase", "required" : "0", "shortdesc" : "Login password or passphrase", "order" : 1 }, "passwd_script" : { "getopt" : "S:", "longopt" : "password-script=", "help" : "-S, --password-script=