diff --git a/fence/agents/alom/fence_alom.py b/fence/agents/alom/fence_alom.py index 3f39b2d1..abe0a1ab 100644 --- a/fence/agents/alom/fence_alom.py +++ b/fence/agents/alom/fence_alom.py @@ -1,68 +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): conn.send_eol("showplatform") - conn.log_expect(options, options["-c"], int(options["-Y"])) + 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["-o"] == "on" and "poweron" or "poweroff -f -y") + cmd_line = (options["--action"] == "on" and "poweron" or "poweroff -f -y") conn.send_eol(cmd_line) - conn.log_expect(options, options["-c"], int(options["-g"])) + conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"])) # Get the machine some time between poweron and poweroff - time.sleep(int(options["-g"])) + 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: 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 743627a9..9236a309 100644 --- a/fence/agents/apc/fence_apc.py +++ b/fence/agents/apc/fence_apc.py @@ -1,228 +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 = {} conn.send_eol("1") - conn.log_expect(options, options["-c"], int(options["-Y"])) + 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("-s")): + if (0 == options.has_key("--switch")): fail_usage("Failed: You have to enter physical switch number") else: - if (0 == options.has_key("-s")): - options["-s"] = "1" + 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["-c"], int(options["-Y"])) + conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) conn.send_eol("1") else: - conn.send_eol(options["-s"]) + conn.send_eol(options["--switch"]) while True: - exp_result = conn.log_expect(options, [ options["-c"], "Press " ], int(options["-Y"])) + 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["-Y"])) - conn.log_expect(options, options["-c"], int(options["-Y"])) + 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["-o"]) == 1: + if ["list", "monitor"].count(options["--action"]) == 1: return outlets else: try: - (_, status) = outlets[options["-n"]] + (_, 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["-o"]] + }[options["--action"]] conn.send_eol("1") - conn.log_expect(options, options["-c"], int(options["-Y"])) + 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["-o"]] + }[options["--action"]] if (None != re.compile('.* MasterSwitch plus 2', re.IGNORECASE | re.S).match(conn.before)): - if (0 == options.has_key("-s")): + if (0 == options.has_key("--switch")): fail_usage("Failed: You have to enter physical switch number") else: - if (0 == options.has_key("-s")): - options["-s"] = 1 + 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["-c"], int(options["-Y"])) + 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["-s"]) + conn.send_eol(options["--switch"]) - while 1 == conn.log_expect(options, [ options["-c"], "Press " ], int(options["-Y"])): + while 1 == conn.log_expect(options, [ options["--command-prompt"], "Press " ], int(options["--shell-timeout"])): conn.send_eol("") - conn.send_eol(options["-n"]+"") - conn.log_expect(options, options["-c"], int(options["-Y"])) + 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["-c"], int(options["-Y"])) + conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) if admin3 == 1: conn.send_eol("1") - conn.log_expect(options, options["-c"], int(options["-Y"])) + conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) else: conn.send_eol("1") - conn.log_expect(options, options["-c"], int(options["-Y"])) + 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["-Y"])) + 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["-Y"])) + conn.log_expect(options, "Press to continue...", int(options["--shell-timeout"])) conn.send_eol("") - conn.log_expect(options, options["-c"], int(options["-Y"])) + conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) conn.send(chr(03)) - conn.log_expect(options, "- Logout", int(options["-Y"])) - conn.log_expect(options, options["-c"], int(options["-Y"])) + 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 -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 + ## 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: 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 726a15f6..cf38e10c 100644 --- a/fence/agents/bladecenter/fence_bladecenter.py +++ b/fence/agents/bladecenter/fence_bladecenter.py @@ -1,121 +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): - node_cmd = "system:blade\[" + options["-n"] + "\]>" + node_cmd = "system:blade\[" + options["--plug"] + "\]>" - conn.send_eol("env -T system:blade[" + options["-n"] + "]") - i = conn.log_expect(options, [ node_cmd, "system>" ] , int(options["-Y"])) + 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("-M"): + 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["-Y"])) + 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["-c"], int(options["-Y"])) + 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["-n"] + "\]>" + node_cmd = "system:blade\[" + options["--plug"] + "\]>" - conn.send_eol("env -T system:blade[" + options["-n"] + "]") - i = conn.log_expect(options, [ node_cmd, "system>" ] , int(options["-Y"])) + 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("-M"): + if options.has_key("--missing-as-off"): return else: fail(EC_GENERIC_ERROR) - conn.send_eol("power -"+options["-o"]) - conn.log_expect(options, node_cmd, int(options["-Y"])) + 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["-c"], int(options["-Y"])) + 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["-Y"])) + conn.log_expect(options, node_cmd, int(options["--shell-timeout"])) conn.send_eol("list -l 2") - conn.log_expect(options, node_cmd, int(options["-Y"])) + 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: 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 5ed2c350..2a81c68a 100644 --- a/fence/agents/cisco_ucs/fence_cisco_ucs.py +++ b/fence/agents/cisco_ucs/fence_cisco_ucs.py @@ -1,143 +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"])) + "/ls-" + options["--plug"] + "/power\"/>", \ + int(options["--shell-timeout"])) 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"]] + }[options["--action"]] res = send_command(options, \ "" + \ - "" + \ - "" + \ + "" + \ + "" + \ "", \ - int(options["-Y"])) + int(options["--shell-timeout"])) return def get_list(conn, options): outlets = { } try: res = send_command(options, \ "", \ - int(options["-Y"])) + int(options["--shell-timeout"])) 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"])) + res = send_command(options, "", int(options["--login-timeout"])) 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"])) + send_command(options, "", int(options["--shell-timeout"])) sys.exit(result) if __name__ == "__main__": main() diff --git a/fence/agents/drac5/fence_drac5.py b/fence/agents/drac5/fence_drac5.py index f8c129d9..bce8cefe 100644 --- a/fence/agents/drac5/fence_drac5.py +++ b/fence/agents/drac5/fence_drac5.py @@ -1,125 +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): if options["model"] == "DRAC CMC": - conn.send_eol("racadm serveraction powerstatus -m " + options["-m"]) + 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["-c"], int(options["-Y"])) + 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["-o"]] + }[options["--action"]] if options["model"] == "DRAC CMC": - conn.send_eol("racadm serveraction " + action + " -m " + options["-m"]) + 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["-c"], int(options["-g"])) + 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["-c"], int(options["-g"])) + 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("-m") and 0 == ["monitor", "list"].count(options["-o"].lower()): + 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: 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 c4f045e2..6532065a 100644 --- a/fence/agents/hpblade/fence_hpblade.py +++ b/fence/agents/hpblade/fence_hpblade.py @@ -1,99 +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): - conn.send_eol("show server status " + options["-n"]) - conn.log_expect(options, options["-c"] , int(options["-Y"])) + 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("-M"): + 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["-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"])) + 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["-c"], int(options["-Y"])) + 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: 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 66472aa9..c85a0637 100644 --- a/fence/agents/ilo/fence_ilo.py +++ b/fence/agents/ilo/fence_ilo.py @@ -1,117 +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") conn.send("\r\n") - conn.log_expect(options, "HOST_POWER=\"(.*?)\"", int(options["-g"])) + conn.log_expect(options, "HOST_POWER=\"(.*?)\"", int(options["--power-timeout"])) status = conn.match.group(1) return status.lower().strip() def set_power_status(conn, options): - conn.send("\r\n") + 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") + elif options["--ribcl-version"] < 2.21: + conn.send("\r\n") else: - if options["-o"] == "off": + if options["--action"] == "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"])) + conn.log_expect(options, [ "", "" ], int(options["--login-timeout"])) version = re.compile("= 2: + if options["--ribcl-version"] >= 2: conn.send("\r\n") else: conn.send("\r\n") - conn.send("\r\n") - if options["-r"] >= 2: + conn.send("\r\n") + if options["--ribcl-version"] >= 2: conn.send("\r\n") conn.send("\r\n") - conn.log_expect(options, "", int(options["-Y"])) + conn.log_expect(options, "", int(options["--shell-timeout"])) 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 7cf068ac..85764c6d 100644 --- a/fence/agents/ilo_mp/fence_ilo_mp.py +++ b/fence/agents/ilo_mp/fence_ilo_mp.py @@ -1,72 +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): conn.send_eol("show /system1") re_state = re.compile('EnabledState=(.*)', re.IGNORECASE) - conn.log_expect(options, re_state, int(options["-Y"])) + 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["-o"] == "on": + if options["--action"] == "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["--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: 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 0d67e3fd..0f41d759 100644 --- a/fence/agents/ldom/fence_ldom.py +++ b/fence/agents/ldom/fence_ldom.py @@ -1,120 +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"])) + res = conn.expect([pexpect.TIMEOUT, COMMAND_PROMPT_REG], int(options["--shell-timeout"])) if res == 0: #CSH stuff conn.send_eol("set prompt='"+COMMAND_PROMPT_NEW+"'") - conn.log_expect(options, COMMAND_PROMPT_REG, int(options["-Y"])) + conn.log_expect(options, COMMAND_PROMPT_REG, int(options["--shell-timeout"])) def get_power_status(conn, options): start_communication(conn, options) conn.send_eol("ldm ls") - conn.log_expect(options, COMMAND_PROMPT_REG, int(options["-Y"])) + conn.log_expect(options, COMMAND_PROMPT_REG, int(options["--shell-timeout"])) result = {} #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")) - if (not (options["-o"] in ['monitor','list'])): - if (not (options["-n"] in result)): + if (not (options["--action"] in ['monitor','list'])): + if (not (options["--plug"] in result)): fail_usage("Failed: You have to enter existing logical domain!") else: - return result[options["-n"]][1] + return result[options["--plug"]][1] else: return result def set_power_status(conn, options): start_communication(conn, options) - cmd_line = "ldm "+(options["-o"]=="on" and "start" or "stop -f")+" \""+options["-n"]+"\"" + cmd_line = "ldm "+(options["--action"]=="on" and "start" or "stop -f")+" \""+options["--plug"]+"\"" conn.send_eol(cmd_line) - conn.log_expect(options, COMMAND_PROMPT_REG, int(options["-g"])) + conn.log_expect(options, COMMAND_PROMPT_REG, int(options["--power-timeout"])) 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/lpar/fence_lpar.py b/fence/agents/lpar/fence_lpar.py index 4522dfd6..0bae359c 100644 --- a/fence/agents/lpar/fence_lpar.py +++ b/fence/agents/lpar/fence_lpar.py @@ -1,148 +1,148 @@ #!/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["-H"] == "3": - conn.send("lssyscfg -r lpar -m " + options["-s"] + " -n " + options["-n"] + " -F name,state\n") - conn.log_expect(options, options["-c"], int(options["-g"])) + 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["-n"] + ",(.*?),.*$", re.IGNORECASE | re.MULTILINE).search(conn.before).group(1) + status = re.compile("^" + options["--plug"] + ",(.*?),.*$", re.IGNORECASE | re.MULTILINE).search(conn.before).group(1) except AttributeError: fail(EC_STATUS_HMC) - elif options["-H"] == "4": - conn.send("lssyscfg -r lpar -m "+ options["-s"] +" --filter 'lpar_names=" + options["-n"] + "'\n") - conn.log_expect(options, options["-c"], int(options["-g"])) + 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["-H"] == "3": - conn.send("chsysstate -o " + options["-o"] + " -r lpar -m " + options["-s"] - + " -n " + options["-n"] + "\n") - conn.log_expect(options, options["-c"], int(options["-g"])) - elif options["-H"] == "4": - if options["-o"] == "on": - conn.send("chsysstate -o on -r lpar -m " + options["-s"] + - " -n " + options["-n"] + + 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["-s"] + - " --filter \"lpar_names="+ options["-n"] +"\"`\n" ) + " -m " + options["--managed"] + + " --filter \"lpar_names="+ options["--plug"] +"\"`\n" ) else: conn.send("chsysstate -o shutdown -r lpar --immed" + - " -m " + options["-s"] + " -n " + options["-n"] + "\n") - conn.log_expect(options, options["-c"], int(options["-g"])) + " -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["-H"] == "3": - conn.send("query_partition_names -m " + options["-s"] + "\n") - conn.log_expect(options, options["-c"], int(options["-g"])) + 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["-H"] == "4": - conn.send("lssyscfg -r lpar -m " + options["-s"] + + elif options["--hmc-version"] == "4": + conn.send("lssyscfg -r lpar -m " + options["--managed"] + " -F name:state\n") - conn.log_expect(options, options["-c"], int(options["-g"])) + 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("-s"): + if 0 == options.has_key("--managed"): fail_usage("Failed: You have to enter name of managed system") - if (0 == ["list", "monitor"].count(options["-o"].lower())) and (0 == options.has_key("-n")): + 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("-H") and (options["-H"] != "3" and options["-H"] != "4"): + 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: pass except pexpect.ExceptionPexpect: pass sys.exit(result) if __name__ == "__main__": main() diff --git a/fence/agents/rhevm/fence_rhevm.py b/fence/agents/rhevm/fence_rhevm.py index 7f5abdeb..fb97d51f 100644 --- a/fence/agents/rhevm/fence_rhevm.py +++ b/fence/agents/rhevm/fence_rhevm.py @@ -1,128 +1,128 @@ #!/usr/bin/python import sys, re import pycurl, StringIO sys.path.append("@FENCEAGENTSLIBDIR@") from fencing import * #BEGIN_VERSION_GENERATION RELEASE_VERSION="New RHEV-M Agent - test release on steroids" REDHAT_COPYRIGHT="" BUILD_DATE="March, 2008" #END_VERSION_GENERATION RE_GET_ID = re.compile("(.*?)", re.IGNORECASE) RE_GET_NAME = re.compile("(.*?)", re.IGNORECASE) def get_power_status(conn, options): ### Obtain real ID from name - res = send_command(options, "vms/?search=name%3D" + options["-n"]) + res = send_command(options, "vms/?search=name%3D" + options["--plug"]) result = RE_GET_ID.search(res) if (result == None): # Unable to obtain ID needed to access virtual machine fail(EC_STATUS) options["id"] = result.group(2) result = RE_STATUS.search(res) if (result == None): # We were able to parse ID so output is correct # in some cases it is possible that RHEV-M output does not # contain line. We can assume machine is OFF then return "off" else: status = result.group(1) if (status.lower() == "down"): return "off" else: return "on" def set_power_status(conn, options): action = { 'on' : "start", 'off' : "stop" - }[options["-o"]] + }[options["--action"]] url = "vms/" + options["id"] + "/" + action res = send_command(options, url, "POST") def get_list(conn, options): outlets = { } try: res = send_command(options, "vms") lines = res.split("") c.setopt(pycurl.WRITEFUNCTION, b.write) c.perform() result = b.getvalue() if opt["log"] >= 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" ] atexit.register(atexit_handler) all_opt["power_wait"]["default"] = "1" options = check_input(device_opt, process_input(device_opt)) docs = { } docs["shortdesc"] = "Fence agent for RHEV-M REST API" docs["longdesc"] = "fence_rhevm is an I/O Fencing agent which can be \ used with RHEV-M REST API to fence virtual machines." docs["vendorurl"] = "http://www.redhat.com" show_docs(options, docs) ## ## Fence operations #### result = fence_action(None, options, set_power_status, get_power_status, get_list) sys.exit(result) if __name__ == "__main__": main() diff --git a/fence/agents/rsa/fence_rsa.py b/fence/agents/rsa/fence_rsa.py index 75cf1f7d..e1e303f1 100644 --- a/fence/agents/rsa/fence_rsa.py +++ b/fence/agents/rsa/fence_rsa.py @@ -1,81 +1,81 @@ #!/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["-c"], int(options["-Y"])) + 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["-o"]) - conn.log_expect(options, options["-c"], int(options["-g"])) + 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: 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 40c922e4..395a8447 100755 --- a/fence/agents/rsb/fence_rsb.py +++ b/fence/agents/rsb/fence_rsb.py @@ -1,99 +1,99 @@ #!/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["-c"], int(options["-Y"])) + 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["-c"], int(options["-Y"])) + 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["-o"]] + }[options["--action"]] conn.send("2") - conn.log_expect(options, options["-c"], int(options["-Y"])) + 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["-Y"])) + 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["-g"])) + conn.log_expect(options, "any key to continue", int(options["--power-timeout"])) conn.send_eol("") - conn.log_expect(options, options["-c"], int(options["-Y"])) + conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) conn.send_eol("0") - conn.log_expect(options, options["-c"], int(options["-Y"])) + 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["-u"] = 3172 + 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: pass sys.exit(result) if __name__ == "__main__": main() diff --git a/fence/agents/sanbox2/fence_sanbox2.py b/fence/agents/sanbox2/fence_sanbox2.py index 173c8194..ccbfd8eb 100644 --- a/fence/agents/sanbox2/fence_sanbox2.py +++ b/fence/agents/sanbox2/fence_sanbox2.py @@ -1,153 +1,153 @@ #!/usr/bin/python ##### ## ## The Following Agent Has Been Tested On: ## ## Version Firmware ## +-----------------+---------------------------+ ##### import sys, re, pexpect, exceptions sys.path.append("@FENCEAGENTSLIBDIR@") from fencing import * #BEGIN_VERSION_GENERATION RELEASE_VERSION="New Sanbox2 Agent - test release on steroids" REDHAT_COPYRIGHT="" BUILD_DATE="March, 2008" #END_VERSION_GENERATION def get_power_status(conn, options): status_trans = { 'online' : "on", 'offline' : "off" } try: - conn.send_eol("show port " + options["-n"]) - conn.log_expect(options, options["-c"], int(options["-Y"])) + conn.send_eol("show port " + options["--plug"]) + conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) except pexpect.TIMEOUT: try: conn.send_eol("admin end") conn.send_eol("exit") conn.close() except: pass fail(EC_TIMED_OUT) status = re.compile(".*AdminState\s+(online|offline)\s+", re.IGNORECASE | re.MULTILINE).search(conn.before).group(1) try: return status_trans[status.lower().strip()] except KeyError: return "PROBLEM" def set_power_status(conn, options): action = { 'on' : "online", 'off' : "offline" - }[options["-o"]] + }[options["--action"]] try: - conn.send_eol("set port " + options["-n"] + " state " + action) - conn.log_expect(options, options["-c"], int(options["-g"])) + conn.send_eol("set port " + options["--plug"] + " state " + action) + conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"])) except pexpect.TIMEOUT: try: conn.send_eol("admin end") conn.send_eol("exit") conn.close() except: pass fail(EC_TIMED_OUT) try: - conn.send_eol("set port " + options["-n"] + " state " + action) - conn.log_expect(options, options["-c"], int(options["-g"])) + conn.send_eol("set port " + options["--plug"] + " state " + action) + conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"])) except pexpect.TIMEOUT: try: conn.send_eol("admin end") conn.send_eol("exit") conn.close() except: pass fail(EC_TIMED_OUT) def get_list_devices(conn, options): outlets = { } try: conn.send_eol("show port") - conn.log_expect(options, options["-c"], int(options["-Y"])) + conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) list_re = re.compile("^\s+(\d+?)\s+(Online|Offline)\s+", re.IGNORECASE) for line in conn.before.splitlines(): if (list_re.search(line)): status = { 'online' : "ON", 'offline' : "OFF" }[list_re.search(line).group(2).lower()] outlets[list_re.search(line).group(1)] = ("", status) except pexpect.TIMEOUT: try: conn.send_eol("admin end") conn.send_eol("exit") conn.close() except: pass fail(EC_TIMED_OUT) return outlets def main(): device_opt = [ "fabric_fencing", "ipaddr", "login", "passwd", "passwd_script", "cmd_prompt", "port", "ipport", "separator" ] atexit.register(atexit_handler) all_opt["cmd_prompt"]["default"] = [ " #> " ] options = check_input(device_opt, process_input(device_opt)) docs = { } docs["shortdesc"] = "Fence agent for QLogic SANBox2 FC switches" docs["longdesc"] = "fence_sanbox2 is an I/O Fencing agent which can be used with \ QLogic SANBox2 FC switches. It logs into a SANBox2 switch via telnet and disables a specified \ port. Disabling the port which a machine is connected to effectively fences that machine. \ Lengthy telnet connections to the switch should be avoided while a GFS cluster is running \ because the connection will block any necessary fencing actions." docs["vendorurl"] = "http://www.qlogic.com" show_docs(options, docs) ## ## Operate the fencing device ## conn = fence_login(options) conn.send_eol("admin start") - conn.log_expect(options, options["-c"], int(options["-Y"])) + conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) if (re.search("\(admin\)", conn.before, re.MULTILINE) == None): ## Someone else is in admin section, we can't enable/disable ## ports so we will rather exit sys.stderr.write("Failed: Unable to switch to admin section\n") sys.exit(EC_GENERIC_ERROR) result = fence_action(conn, options, set_power_status, get_power_status, get_list_devices) ## ## Logout from system ###### try: conn.send_eol("admin end") conn.send_eol("exit\n") conn.close() except exceptions.OSError: pass except pexpect.ExceptionPexpect: 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 c8c49a43..b1573851 100644 --- a/fence/agents/virsh/fence_virsh.py +++ b/fence/agents/virsh/fence_virsh.py @@ -1,101 +1,101 @@ #!/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["-c"], int(options["-Y"])) + 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["-n"] in outlets)): + if (not (options["--plug"] in outlets)): fail_usage("Failed: You have to enter existing name of virtual machine!") else: - return outlets[options["-n"]][1] + 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["-o"] == "on" and "start" or "destroy")+options["-n"]) + conn.sendline(prefix + "virsh %s "%(options["--action"] == "on" and "start" or "destroy")+options["--plug"]) - conn.log_expect(options, options["-c"], int(options["-g"])) + 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: pass sys.exit(result) if __name__ == "__main__": main() diff --git a/fence/agents/vmware/fence_vmware.py b/fence/agents/vmware/fence_vmware.py index 6e3f3943..8524480a 100644 --- a/fence/agents/vmware/fence_vmware.py +++ b/fence/agents/vmware/fence_vmware.py @@ -1,334 +1,334 @@ #!/usr/bin/python # # The Following agent has been tested on: # vmrun 2.0.0 build-116503 (from VMware Server 2.0) against: # VMware ESX 4.0.0 # VMware vCenter 4.0.0 # VMware ESX 3.5 # VMware Server 2.0.0 # VMware ESXi 3.5 update 2 # VMware Server 1.0.7 (works but list/status show only running VMs) # # VI Perl API 1.6 against: # VMware ESX 4.0.0 # VMware vCenter 4.0.0 # VMware ESX 3.5 # VMware ESXi 3.5 update 2 # VMware Virtual Center 2.5 # # VMware vSphere SDK for Perl 4.0.0 against: # VMware ESX 4.0.0 # VMware vCenter 4.0.0 # import sys, re, pexpect, exceptions sys.path.append("@FENCEAGENTSLIBDIR@") from fencing import * #BEGIN_VERSION_GENERATION RELEASE_VERSION="VMware Agent using VI Perl API and/or VIX vmrun command" REDHAT_COPYRIGHT="" BUILD_DATE="" #END_VERSION_GENERATION ### CONSTANTS #### # VMware type is ESX/ESXi/VC VMWARE_TYPE_ESX = 0 # VMware type is Server 1.x VMWARE_TYPE_SERVER1 = 1 # VMware type is Server 2.x and/or ESX 3.5 up2, ESXi 3.5 up2, VC 2.5 up2 VMWARE_TYPE_SERVER2 = 2 # Minimum required version of vmrun command VMRUN_MINIMUM_REQUIRED_VERSION = 2 # Default path to vmhelper command VMHELPER_COMMAND = "fence_vmware_helper" # Default path to vmrun command VMRUN_COMMAND = "/usr/bin/vmrun" # Default type of vmware VMWARE_DEFAULT_TYPE = "esx" #### GLOBAL VARIABLES #### # Internal type. One of VMWARE_TYPE_, set by #vmware_check_vmware_type vmware_internal_type = VMWARE_TYPE_ESX # If ESX is disconnected, say, that VM is off (don't return previous state) vmware_disconnected_hack = False ### FUNCTIONS #### #Split string in simplified DSV format to array of items def dsv_split(dsv_str): delimiter_c = ':' escape_c = '\\' res = [] status = 0 tmp_str = "" for x in dsv_str: if (status==0): if (x==delimiter_c): res.append(tmp_str) tmp_str = "" elif (x==escape_c): status = 1 else: tmp_str += x elif (status==1): if (x==delimiter_c): tmp_str += delimiter_c elif (x==escape_c): tmp_str += escape_c else: tmp_str += escape_c+x status = 0 if (tmp_str != ""): res.append(tmp_str) return res # Quote string for proper existence in quoted string used for pexpect.run function # Ex. test'this will return test'\''this. So pexpect run will really pass ' to argument def quote_for_run(str): dstr = '' for c in str: if c == r"'": dstr += "'\\''" else: dstr += c return dstr # Return string with command and additional parameters (something like vmrun -h 'host' def vmware_prepare_command(options, add_login_params, additional_params): - res = options["-e"] + res = options["--exec"] if (add_login_params): if (vmware_internal_type==VMWARE_TYPE_ESX): - res += " --server '%s' --username '%s' --password '%s' "% (quote_for_run(options["-a"]), - quote_for_run(options["-l"]), - quote_for_run(options["-p"])) + res += " --server '%s' --username '%s' --password '%s' "% (quote_for_run(options["--ip"]), + quote_for_run(options["--username"]), + quote_for_run(options["--password"])) elif (vmware_internal_type==VMWARE_TYPE_SERVER2): - res += " -h 'https://%s/sdk' -u '%s' -p '%s' -T server "% (quote_for_run(options["-a"]), - quote_for_run(options["-l"]), - quote_for_run(options["-p"])) + res += " -h 'https://%s/sdk' -u '%s' -p '%s' -T server "% (quote_for_run(options["--ip"]), + quote_for_run(options["--username"]), + quote_for_run(options["--password"])) elif (vmware_internal_type==VMWARE_TYPE_SERVER1): - host_name_array = options["-a"].split(':') + host_name_array = options["--ip"].split(':') res += " -h '%s' -u '%s' -p '%s' -T server1 "% (quote_for_run(host_name_array[0]), - quote_for_run(options["-l"]), - quote_for_run(options["-p"])) + quote_for_run(options["--username"]), + quote_for_run(options["--password"])) if (len(host_name_array)>1): res += "-P '%s' "% (quote_for_run(host_name_array[1])) - if ((options.has_key("-s")) and (vmware_internal_type==VMWARE_TYPE_ESX)): - res += "--datacenter '%s' "% (quote_for_run(options["-s"])) + if ((options.has_key("--vmware-datacenter")) and (vmware_internal_type==VMWARE_TYPE_ESX)): + res += "--datacenter '%s' "% (quote_for_run(options["--vmware-datacenter"])) if (additional_params != ""): res += additional_params return res # Log message if user set verbose option def vmware_log(options, message): if options["log"] >= LOG_MODE_VERBOSE: options["debug_fh"].write(message+"\n") # Run command with timeout and parameters. Internaly uses vmware_prepare_command. Returns string # with output from vmrun command. If something fails (command not found, exit code is not 0), fail_usage # function is called (and never return). def vmware_run_command(options, add_login_params, additional_params, additional_timeout): command = vmware_prepare_command(options, add_login_params, additional_params) try: vmware_log(options, command) - (res_output, res_code) = pexpect.run(command, int(options["-Y"])+int(options["-y"])+additional_timeout, True) + (res_output, res_code) = pexpect.run(command, int(options["--shell-timeout"])+int(options["--login-timeout"])+additional_timeout, True) if (res_code==None): fail(EC_TIMED_OUT) if ((res_code!=0) and (add_login_params)): vmware_log(options, res_output) - fail_usage("%s returned %s"% (options["-e"], res_output)) + fail_usage("%s returned %s"% (options["--exec"], res_output)) else: vmware_log(options, res_output) except pexpect.ExceptionPexpect: - fail_usage("Cannot run command %s"% (options["-e"])) + fail_usage("Cannot run command %s"% (options["--exec"])) return res_output # Get outlet list with status as hash table. If you will use add_vm_name, only VM with vmname is # returned. This is used in get_status function def vmware_get_outlets_vi(conn, options, add_vm_name): outlets = {} if (add_vm_name): - all_machines = vmware_run_command(options, True, ("--operation status --vmname '%s'"% (quote_for_run(options["-n"]))), 0) + all_machines = vmware_run_command(options, True, ("--operation status --vmname '%s'"% (quote_for_run(options["--plug"]))), 0) else: - all_machines = vmware_run_command(options, True, "--operation list", int(options["-g"])) + all_machines = vmware_run_command(options, True, "--operation list", int(options["--power-timeout"])) all_machines_array = all_machines.splitlines() for machine in all_machines_array: machine_array = dsv_split(machine) if (len(machine_array) == 4): if (machine_array[0] in outlets): fail_usage("Failed. More machines with same name %s found!"%(machine_array[0])) if (vmware_disconnected_hack): outlets[machine_array[0]] = ("", ( ((machine_array[2].lower() in ["poweredon"]) and (machine_array[3].lower()=="connected")) and "on" or "off")) else: outlets[machine_array[0]] = ("", ((machine_array[2].lower() in ["poweredon"]) and "on" or "off")) return outlets # Get outlet list with status as hash table. def vmware_get_outlets_vix(conn, options): outlets = {} running_machines = vmware_run_command(options, True, "list", 0) running_machines_array = running_machines.splitlines()[1:] if (vmware_internal_type==VMWARE_TYPE_SERVER2): all_machines = vmware_run_command(options, True, "listRegisteredVM", 0) all_machines_array = all_machines.splitlines()[1:] elif (vmware_internal_type==VMWARE_TYPE_SERVER1): all_machines_array = running_machines_array for machine in all_machines_array: if (machine!=""): outlets[machine] = ("", ((machine in running_machines_array) and "on" or "off")) return outlets def get_outlets_status(conn, options): if (vmware_internal_type==VMWARE_TYPE_ESX): return vmware_get_outlets_vi(conn, options, False) if ((vmware_internal_type==VMWARE_TYPE_SERVER1) or (vmware_internal_type==VMWARE_TYPE_SERVER2)): return vmware_get_outlets_vix(conn, options) def get_power_status(conn, options): if (vmware_internal_type==VMWARE_TYPE_ESX): outlets = vmware_get_outlets_vi(conn, options, True) else: outlets = get_outlets_status(conn, options) if ((vmware_internal_type==VMWARE_TYPE_SERVER2) or (vmware_internal_type==VMWARE_TYPE_ESX)): - if (not (options["-n"] in outlets)): + if (not (options["--plug"] in outlets)): fail_usage("Failed: You have to enter existing name of virtual machine!") else: - return outlets[options["-n"]][1] + return outlets[options["--plug"]][1] elif (vmware_internal_type==VMWARE_TYPE_SERVER1): - return ((options["-n"] in outlets) and "on" or "off") + return ((options["--plug"] in outlets) and "on" or "off") def set_power_status(conn, options): if (vmware_internal_type==VMWARE_TYPE_ESX): - additional_params = "--operation %s --vmname '%s'"% ((options["-o"]=="on" and "on" or "off"), quote_for_run(options["-n"])) + additional_params = "--operation %s --vmname '%s'"% ((options["--action"]=="on" and "on" or "off"), quote_for_run(options["--plug"])) elif ((vmware_internal_type==VMWARE_TYPE_SERVER1) or (vmware_internal_type==VMWARE_TYPE_SERVER2)): - additional_params = "%s '%s'"% ((options["-o"]=="on" and "start" or "stop"), quote_for_run(options["-n"])) - if (options["-o"]=="off"): + additional_params = "%s '%s'"% ((options["--action"]=="on" and "start" or "stop"), quote_for_run(options["--plug"])) + if (options["--action"]=="off"): additional_params += " hard" - vmware_run_command(options, True, additional_params, int(options["-g"])) + vmware_run_command(options, True, additional_params, int(options["--power-timeout"])) # Returns True, if user uses supported vmrun version (currently >=2.0.0) otherwise False. def vmware_is_supported_vmrun_version(options): vmware_help_str = vmware_run_command(options, False, "", 0) version_re = re.search("vmrun version (\d\.(\d[\.]*)*)", vmware_help_str.lower()) if (version_re==None): return False # Looks like this "vmrun" is not real vmrun version_array = version_re.group(1).split(".") try: if (int(version_array[0]) < VMRUN_MINIMUM_REQUIRED_VERSION): return False except Exception: return False return True # Check vmware type, set vmware_internal_type to one of VMWARE_TYPE_ value and -# options["-e"] to path (if not specified) +# options["--exec"] to path (if not specified) def vmware_check_vmware_type(options): global vmware_internal_type - options["-d"] = options["-d"].lower() + options["--vmware-type"] = options["--vmware-type"].lower() - if (options["-d"]=="esx"): + if (options["--vmware-type"]=="esx"): vmware_internal_type = VMWARE_TYPE_ESX - if (not options.has_key("-e")): - options["-e"] = VMHELPER_COMMAND - elif (options["-d"]=="server2"): + if (not options.has_key("--exec")): + options["--exec"] = VMHELPER_COMMAND + elif (options["--vmware-type"]=="server2"): vmware_internal_type = VMWARE_TYPE_SERVER2 - if (not options.has_key("-e")): - options["-e"] = VMRUN_COMMAND - elif (options["-d"]=="server1"): + if (not options.has_key("--exec")): + options["--exec"] = VMRUN_COMMAND + elif (options["--vmware-type"]=="server1"): vmware_internal_type = VMWARE_TYPE_SERVER1 - if (not options.has_key("-e")): - options["-e"] = VMRUN_COMMAND + if (not options.has_key("--exec")): + options["--exec"] = VMRUN_COMMAND else: fail_usage("vmware_type can be esx,server2 or server1!") # Main agent method def main(): device_opt = [ "ipaddr", "login", "passwd", "passwd_script", "test", "port", "separator", "exec", "vmware_type", "vmware_datacenter", "secure", "identity_file" ] atexit.register(atexit_handler) all_opt["secure"]["default"] = "1" all_opt["vmware_type"]["default"] = VMWARE_DEFAULT_TYPE options = check_input(device_opt, process_input(device_opt)) docs = { } docs["shortdesc"] = "Fence agent for VMWare" docs["longdesc"] = "fence_vmware is an I/O Fencing agent \ which can be used with the VMware ESX, VMware ESXi or VMware Server \ to fence virtual machines.\ \n.P\n\ Before you can use this agent, it must be installed VI Perl Toolkit or \ vmrun command on every node you want to make fencing.\ \n.P\n\ VI Perl Toolkit is preferred for VMware ESX/ESXi and Virtual Center. Vmrun \ command is only solution for VMware Server 1/2 (this command will works against \ ESX/ESXi 3.5 up2 and VC up2 too, but not cluster aware!) and is available as part \ of VMware VIX API SDK package. VI Perl and VIX API SDK are both available from \ VMware web pages (not int RHEL repository!). \ \n.P\n\ You can specify type of VMware you are connecting to with \\fB-d\\fP switch \ (or \\fIvmware_type\\fR for stdin). Possible values are esx, server2 and server1.\ Default value is esx, which will use VI Perl. With server1 and server2, vmrun \ command is used.\ \n.P\n\ After you have successfully installed VI Perl Toolkit or VIX API, you should \ be able to run fence_vmware_helper (part of this agent) or vmrun command. \ This agent supports only vmrun from version 2.0.0 (VIX API 1.6.0)." docs["vendorurl"] = "http://www.vmware.com" show_docs(options, docs) # Check vmware type and set path vmware_check_vmware_type(options) # Test user vmrun command version if ((vmware_internal_type==VMWARE_TYPE_SERVER1) or (vmware_internal_type==VMWARE_TYPE_SERVER2)): if (not (vmware_is_supported_vmrun_version(options))): fail_usage("Unsupported version of vmrun command! You must use at least version %d!"%(VMRUN_MINIMUM_REQUIRED_VERSION)) # Operate the fencing device result = fence_action(None, options, set_power_status, get_power_status, get_outlets_status) sys.exit(result) if __name__ == "__main__": main() diff --git a/fence/agents/vmware_soap/fence_vmware_soap.py b/fence/agents/vmware_soap/fence_vmware_soap.py index 2710603f..4ef03f0c 100644 --- a/fence/agents/vmware_soap/fence_vmware_soap.py +++ b/fence/agents/vmware_soap/fence_vmware_soap.py @@ -1,200 +1,200 @@ #!/usr/bin/python import sys, exceptions sys.path.append("@FENCEAGENTSLIBDIR@") from suds.client import Client from suds.sudsobject import Property from fencing import * #BEGIN_VERSION_GENERATION RELEASE_VERSION="New VMWare Agent - test release on steroids" REDHAT_COPYRIGHT="" BUILD_DATE="April, 2011" #END_VERSION_GENERATION def soap_login(options): - if options.has_key("-z"): + if options.has_key("--ssl"): url = "https://" else: url = "http://" - url += options["-a"] + ":" + str(options["-u"]) + "/sdk" + url += options["--ip"] + ":" + str(options["-u"]) + "/sdk" conn = Client(url + "/vimService.wsdl") conn.set_options(location = url) mo_ServiceInstance = Property('ServiceInstance') mo_ServiceInstance._type = 'ServiceInstance' ServiceContent = conn.service.RetrieveServiceContent(mo_ServiceInstance) mo_SessionManager = Property(ServiceContent.sessionManager.value) mo_SessionManager._type = 'SessionManager' try: - SessionManager = conn.service.Login(mo_SessionManager, options["-l"], options["-p"]) + SessionManager = conn.service.Login(mo_SessionManager, options["--username"], options["--password"]) except Exception, ex: fail(EC_LOGIN_DENIED) options["ServiceContent"] = ServiceContent options["mo_SessionManager"] = mo_SessionManager return conn def process_results(results, machines, uuid, mappingToUUID): for m in results.objects: info = {} for i in m.propSet: info[i.name] = i.val # Prevent error KeyError: 'config.uuid' when reaching systems which P2V failed, # since these systems don't have a valid UUID if info.has_key("config.uuid"): machines[info["name"]] = (info["config.uuid"], info["summary.runtime.powerState"]) uuid[info["config.uuid"]] = info["summary.runtime.powerState"] mappingToUUID[m.obj.value] = info["config.uuid"] return (machines, uuid, mappingToUUID) def get_power_status(conn, options): mo_ViewManager = Property(options["ServiceContent"].viewManager.value) mo_ViewManager._type = "ViewManager" mo_RootFolder = Property(options["ServiceContent"].rootFolder.value) mo_RootFolder._type = "Folder" mo_PropertyCollector = Property(options["ServiceContent"].propertyCollector.value) mo_PropertyCollector._type = 'PropertyCollector' ContainerView = conn.service.CreateContainerView(mo_ViewManager, recursive = 1, container = mo_RootFolder, type = ['VirtualMachine']) mo_ContainerView = Property(ContainerView.value) mo_ContainerView._type = "ContainerView" FolderTraversalSpec = conn.factory.create('ns0:TraversalSpec') FolderTraversalSpec.name = "traverseEntities" FolderTraversalSpec.path = "view" FolderTraversalSpec.skip = False FolderTraversalSpec.type = "ContainerView" objSpec = conn.factory.create('ns0:ObjectSpec') objSpec.obj = mo_ContainerView objSpec.selectSet = [ FolderTraversalSpec ] objSpec.skip = True propSpec = conn.factory.create('ns0:PropertySpec') propSpec.all = False propSpec.pathSet = ["name", "summary.runtime.powerState", "config.uuid"] propSpec.type = "VirtualMachine" propFilterSpec = conn.factory.create('ns0:PropertyFilterSpec') propFilterSpec.propSet = [ propSpec ] propFilterSpec.objectSet = [ objSpec ] try: raw_machines = conn.service.RetrievePropertiesEx(mo_PropertyCollector, propFilterSpec) except Exception, ex: fail(EC_STATUS) (machines, uuid, mappingToUUID) = process_results(raw_machines, {}, {}, {}) # Probably need to loop over the ContinueRetreive if there are more results after 1 iteration. while (hasattr(raw_machines, 'token') == True): try: raw_machines = conn.service.ContinueRetrievePropertiesEx(mo_PropertyCollector, raw_machines.token) except Exception, ex: fail(EC_STATUS) (more_machines, more_uuid, more_mappingToUUID) = process_results(raw_machines, {}, {}, {}) machines.update(more_machines) uuid.update(more_uuid) mappingToUUID.update(more_mappingToUUID) # Do not run unnecessary SOAP requests - if options.has_key("-U") and options["-U"] in uuid: + if options.has_key("--uuid") and options["--uuid"] in uuid: break - if ["list", "monitor"].count(options["-o"]) == 1: + if ["list", "monitor"].count(options["--action"]) == 1: return machines else: - if options.has_key("-U") == False: - if options["-n"].startswith('/'): + if options.has_key("--uuid") == False: + if options["--plug"].startswith('/'): ## Transform InventoryPath to UUID mo_SearchIndex = Property(options["ServiceContent"].searchIndex.value) mo_SearchIndex._type = "SearchIndex" - vm = conn.service.FindByInventoryPath(mo_SearchIndex, options["-n"]) + vm = conn.service.FindByInventoryPath(mo_SearchIndex, options["--plug"]) try: - options["-U"] = mappingToUUID[vm.value] + options["--uuid"] = mappingToUUID[vm.value] except KeyError, ex: fail(EC_STATUS) except AttributeError, ex: fail(EC_STATUS) else: ## Name of virtual machine instead of path ## warning: if you have same names of machines this won't work correctly try: - (options["-U"], _) = machines[options["-n"]] + (options["--uuid"], _) = machines[options["--plug"]] except KeyError, ex: fail(EC_STATUS) except AttributeError, ex: fail(EC_STATUS) try: - if uuid[options["-U"]] == "poweredOn": + if uuid[options["--uuid"]] == "poweredOn": return "on" else: return "off" except KeyError, ex: fail(EC_STATUS) def set_power_status(conn, options): mo_SearchIndex = Property(options["ServiceContent"].searchIndex.value) mo_SearchIndex._type = "SearchIndex" - vm = conn.service.FindByUuid(mo_SearchIndex, vmSearch = 1, uuid = options["-U"]) + vm = conn.service.FindByUuid(mo_SearchIndex, vmSearch = 1, uuid = options["--uuid"]) mo_machine = Property(vm.value) mo_machine._type = "VirtualMachine" - if options["-o"] == "on": + if options["--action"] == "on": conn.service.PowerOnVM_Task(mo_machine) else: conn.service.PowerOffVM_Task(mo_machine) def main(): device_opt = [ "ipaddr", "login", "passwd", "passwd_script", "ssl", "port", "uuid", "separator", "ipport" ] atexit.register(atexit_handler) options = check_input(device_opt, process_input(device_opt)) ## ## Fence agent specific defaults ##### docs = { } docs["shortdesc"] = "Fence agent for VMWare over SOAP API" docs["longdesc"] = "fence_vmware_soap is an I/O Fencing agent \ which can be used with the virtual machines managed by VMWare products \ that have SOAP API v4.1+. \ \n.P\n\ Name of virtual machine (-n / port) has to be used in inventory path \ format (e.g. /datacenter/vm/Discovered virtual machine/myMachine). \ In the cases when name of yours VM is unique you can use it instead. \ Alternatively you can always use UUID (-U / uuid) to access virtual machine." docs["vendorurl"] = "http://www.vmware.com" show_docs(options, docs) ## ## Operate the fencing device #### conn = soap_login(options) result = fence_action(conn, options, set_power_status, get_power_status, get_power_status) ## ## Logout from system ##### try: conn.service.Logout(options["mo_SessionManager"]) except Exception, ex: 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 2337e105..80b5e968 100644 --- a/fence/agents/wti/fence_wti.py +++ b/fence/agents/wti/fence_wti.py @@ -1,162 +1,162 @@ #!/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["-c"], list): - re_all = list(options["-c"]) + if isinstance(options["--command-prompt"], list): + re_all = list(options["--command-prompt"]) else: - re_all = [options["-c"]] + 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["-Y"])) + 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["-c"], int(options["-Y"])) + 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["-o"]) == 0 and options["-n"].lower() == plug_line[plug_index]: + 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["-o"]) == 1: + if ["list", "monitor"].count(options["--action"]) == 1: return outlets else: return "PROBLEM" def set_power_status(conn, options): action = { 'on' : "/on", 'off': "/off" - }[options["-o"]] + }[options["--action"]] - conn.send(action + " " + options["-n"] + ",y\r\n") - conn.log_expect(options, options["-c"], int(options["-g"])) + 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("-x"): + 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["-a"], options["-u"])) + 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["-c"])), 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["-Y"])) + result = conn.log_expect(options, [ re_login, "Password: ", re_prompt ], int(options["--shell-timeout"])) if result == 0: - if options.has_key("-l"): - conn.send(options["-l"]+"\r\n") - result = conn.log_expect(options, [ re_login, "Password: ", re_prompt ], int(options["-Y"])) + 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("-p"): - conn.send(options["-p"]+"\r\n") - conn.log_expect(options, options["-c"], int(options["-Y"])) + 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: pass sys.exit(result) if __name__ == "__main__": main()