Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
List overview
Download
cluster-commits
October 2009
----- 2024 -----
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
cluster-commits@lists.fedorahosted.org
9 participants
151 discussions
Start a n
N
ew thread
cluster: STABLE3 - fencing: Timeout options added
by Marek Grác
09 Oct '09
09 Oct '09
Gitweb:
http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=83…
Commit: 830d6fdf94593513d8c569afbb3f097ef73a1d98 Parent: 9de7fcd3dbefbfe56a317dc6fe94836fae9850da Author: Marek 'marx' Grac <mgrac(a)redhat.com> AuthorDate: Fri Oct 9 13:42:39 2009 +0200 Committer: Marek 'marx' Grac <mgrac(a)redhat.com> CommitterDate: Fri Oct 9 13:42:39 2009 +0200 fencing: Timeout options added Fencing agents based on fencing library have new set of timeout options. Please read
http://sources.redhat.com/cluster/wiki/FenceTiming
for more information. --- fence/agents/alom/fence_alom.py | 9 ++-- fence/agents/apc/fence_apc.py | 37 +++++++------- fence/agents/apc_snmp/fence_apc_snmp.py | 3 +- fence/agents/bladecenter/fence_bladecenter.py | 28 +++++------ fence/agents/cisco_mds/fence_cisco_mds.py | 3 +- fence/agents/drac5/fence_drac5.py | 9 ++-- fence/agents/ibmblade/fence_ibmblade.py | 3 +- fence/agents/ifmib/fence_ifmib.py | 3 +- fence/agents/ilo/fence_ilo.py | 13 +++-- fence/agents/ilo_mp/fence_ilo_mp.py | 5 +- fence/agents/intelmodular/fence_intelmodular.py | 3 +- fence/agents/ldom/fence_ldom.py | 11 ++-- fence/agents/lib/fencing.py.py | 60 ++++++++++++++++------- fence/agents/lib/fencing_snmp.py.py | 2 +- fence/agents/lpar/fence_lpar.py | 15 +++--- fence/agents/rsa/fence_rsa.py | 7 ++- fence/agents/sanbox2/fence_sanbox2.py | 13 +++-- fence/agents/virsh/fence_virsh.py | 7 ++- fence/agents/vmware/fence_vmware.py | 9 ++-- fence/agents/wti/fence_wti.py | 13 +++-- 20 files changed, 147 insertions(+), 106 deletions(-) diff --git a/fence/agents/alom/fence_alom.py b/fence/agents/alom/fence_alom.py index d88f718..4fffa0a 100644 --- a/fence/agents/alom/fence_alom.py +++ b/fence/agents/alom/fence_alom.py @@ -19,7 +19,7 @@ def get_power_status(conn, options): result = "" try: conn.sendline("showplatform") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + 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: @@ -33,9 +33,9 @@ def set_power_status(conn, options): try: cmd_line=(options["-o"]=="on" and "poweron" or "poweroff -f -y") conn.sendline(cmd_line) - conn.log_expect(options, options["-c"],POWER_TIMEOUT) + conn.log_expect(options, options["-c"],int(options["-g"])) #Get the machine some time between poweron and poweroff - time.sleep(POWER_TIMEOUT) + time.sleep(int(options["-g"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) @@ -45,7 +45,8 @@ def set_power_status(conn, options): def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", - "secure", "test", "inet4_only", "inet6_only", "ipport" ] + "secure", "test", "inet4_only", "inet6_only", "ipport", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/apc/fence_apc.py b/fence/agents/apc/fence_apc.py index a48877e..685a154 100755 --- a/fence/agents/apc/fence_apc.py +++ b/fence/agents/apc/fence_apc.py @@ -29,7 +29,7 @@ def get_power_status(conn, options): outlets = {} try: conn.send("1\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) version = 0 admin = 0 @@ -62,13 +62,13 @@ def get_power_status(conn, options): conn.send("3\r\n") else: conn.send("2\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) conn.send("1\r\n") else: conn.send(options["-s"]+"\r\n") while True: - exp_result = conn.log_expect(options, [ options["-c"], "Press <ENTER>" ], SHELL_TIMEOUT) + exp_result = conn.log_expect(options, [ options["-c"], "Press <ENTER>" ], int(options["-Y"])) lines = conn.before.split("\n"); show_re = re.compile('^\s*(\d+)- (.*?)\s+(ON|OFF)\s*') for x in lines: @@ -79,8 +79,8 @@ def get_power_status(conn, options): if exp_result == 0: break conn.send(chr(03)) - conn.log_expect(options, "- Logout", SHELL_TIMEOUT) - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + 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: @@ -103,7 +103,7 @@ def set_power_status(conn, options): try: conn.send("1\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) version = 0 admin2 = 0 @@ -142,7 +142,7 @@ def set_power_status(conn, options): conn.send("3\r\n") else: conn.send("2\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + 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: @@ -151,31 +151,31 @@ def set_power_status(conn, options): else: conn.send(options["-s"] + "\r\n") - while 1 == conn.log_expect(options, [ options["-c"], "Press <ENTER>" ], SHELL_TIMEOUT): + while 1 == conn.log_expect(options, [ options["-c"], "Press <ENTER>" ], int(options["-Y"])): conn.send("\r\n") conn.send(options["-n"]+"\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) if switch == 0: if admin2 == 1: conn.send("1\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) if admin3 == 1: conn.send("1\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) else: conn.send("1\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) conn.send(action+"\r\n") - conn.log_expect(options, "Enter 'YES' to continue or <ENTER> to cancel :", SHELL_TIMEOUT) + conn.log_expect(options, "Enter 'YES' to continue or <ENTER> to cancel :", int(options["-Y"])) conn.send("YES\r\n") - conn.log_expect(options, "Press <ENTER> to continue...", SHELL_TIMEOUT) + conn.log_expect(options, "Press <ENTER> to continue...", int(options["-Y"])) conn.send("\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) conn.send(chr(03)) - conn.log_expect(options, "- Logout", SHELL_TIMEOUT) - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + 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: @@ -185,7 +185,8 @@ def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", "secure", "port", "switch", "test", "separator", - "inet4_only", "inet6_only", "ipport" ] + "inet4_only", "inet6_only", "ipport", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/apc_snmp/fence_apc_snmp.py b/fence/agents/apc_snmp/fence_apc_snmp.py index e66a6b0..7e8118e 100644 --- a/fence/agents/apc_snmp/fence_apc_snmp.py +++ b/fence/agents/apc_snmp/fence_apc_snmp.py @@ -169,7 +169,8 @@ def main(): "test", "port", "separator", "no_login", "no_password", "snmp_version", "community", "snmp_auth_prot", "snmp_sec_level", "snmp_priv_prot", "snmp_priv_passwd", "snmp_priv_passwd_script", - "udpport","inet4_only","inet6_only"] + "udpport","inet4_only","inet6_only", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/bladecenter/fence_bladecenter.py b/fence/agents/bladecenter/fence_bladecenter.py index eacac33..87819e4 100644 --- a/fence/agents/bladecenter/fence_bladecenter.py +++ b/fence/agents/bladecenter/fence_bladecenter.py @@ -27,15 +27,15 @@ def get_power_status(conn, options): node_cmd = "system:blade\[" + options["-n"] + "\]>" conn.send("env -T system:blade[" + options["-n"] + "]\r\n") - i = conn.log_expect(options, [ node_cmd, "system>" ] , SHELL_TIMEOUT) + i = conn.log_expect(options, [ node_cmd, "system>" ] , int(options["-Y"])) if i == 1: ## Given blade number does not exist fail(EC_STATUS) conn.send("power -state\r\n") - conn.log_expect(options, node_cmd, SHELL_TIMEOUT) + conn.log_expect(options, node_cmd, int(options["-Y"])) status = conn.before.splitlines()[-1] conn.send("env -T system\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -53,11 +53,11 @@ def set_power_status(conn, options): node_cmd = "system:blade\[" + options["-n"] + "\]>" conn.send("env -T system:blade[" + options["-n"] + "]\r\n") - conn.log_expect(options, node_cmd, SHELL_TIMEOUT) + conn.log_expect(options, node_cmd, int(options["-Y"])) conn.send("power -"+options["-o"]+"\r\n") - conn.log_expect(options, node_cmd, SHELL_TIMEOUT) + conn.log_expect(options, node_cmd, int(options["-Y"])) conn.send("env -T system\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -69,9 +69,9 @@ def get_blades_list(conn, options): node_cmd = "system>" conn.send("env -T system\r\n") - conn.log_expect(options, node_cmd, SHELL_TIMEOUT) + conn.log_expect(options, node_cmd, int(options["-Y"])) conn.send("list -l 2\r\n") - conn.log_expect(options, node_cmd, SHELL_TIMEOUT) + conn.log_expect(options, node_cmd, int(options["-Y"])) lines = conn.before.split("\r\n") filter_re = re.compile("^\s*blade\[(\d+)\]\s+(.*?)\s*$") @@ -91,17 +91,15 @@ def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", "cmd_prompt", "secure", "port", "identity_file", "separator", - "inet4_only", "inet6_only", "ipport" ] + "inet4_only", "inet6_only", "ipport", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) - options = check_input(device_opt, process_input(device_opt)) + all_opt["power_wait"]["default"] = "5" + all_opt["cmd_prompt"]["default"] = "system>" - ## - ## Fence agent specific defaults - ##### - if 0 == options.has_key("-c"): - options["-c"] = "system>" + options = check_input(device_opt, process_input(device_opt)) show_docs(options) diff --git a/fence/agents/cisco_mds/fence_cisco_mds.py b/fence/agents/cisco_mds/fence_cisco_mds.py index 944e593..d007b72 100644 --- a/fence/agents/cisco_mds/fence_cisco_mds.py +++ b/fence/agents/cisco_mds/fence_cisco_mds.py @@ -86,7 +86,8 @@ def main(): "test", "port", "separator", "no_login", "no_password", "snmp_version", "community", "snmp_auth_prot", "snmp_sec_level", "snmp_priv_prot", "snmp_priv_passwd", "snmp_priv_passwd_script", - "udpport","inet4_only","inet6_only"] + "udpport","inet4_only","inet6_only", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/drac5/fence_drac5.py b/fence/agents/drac5/fence_drac5.py index 231fd06..d7fbdaa 100755 --- a/fence/agents/drac5/fence_drac5.py +++ b/fence/agents/drac5/fence_drac5.py @@ -29,7 +29,7 @@ def get_power_status(conn, options): elif options["model"] == "DRAC 5": conn.sendline("racadm serveraction powerstatus") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -52,7 +52,7 @@ def set_power_status(conn, options): conn.sendline("racadm serveraction " + action + " -m " + options["-m"]) elif options["model"] == "DRAC 5": conn.sendline("racadm serveraction " + action) - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -69,7 +69,7 @@ def get_list_devices(conn, options): for line in conn.before.splitlines(): if (list_re.search(line)): outlets[list_re.search(line).group(1)] = ("", list_re.search(line).group(2)) - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) elif options["model"] == "DRAC 5": ## DRAC 5 can be used only for one computer pass @@ -84,7 +84,8 @@ def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", "cmd_prompt", "secure", "drac_version", "module_name", - "separator", "inet4_only", "inet6_only", "ipport" ] + "separator", "inet4_only", "inet6_only", "ipport", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/ibmblade/fence_ibmblade.py b/fence/agents/ibmblade/fence_ibmblade.py index 700437d..4ff334e 100644 --- a/fence/agents/ibmblade/fence_ibmblade.py +++ b/fence/agents/ibmblade/fence_ibmblade.py @@ -61,7 +61,8 @@ def main(): "test", "port", "separator", "no_login", "no_password", "snmp_version", "community", "snmp_auth_prot", "snmp_sec_level", "snmp_priv_prot", "snmp_priv_passwd", "snmp_priv_passwd_script", - "udpport","inet4_only","inet6_only"] + "udpport","inet4_only","inet6_only", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/ifmib/fence_ifmib.py b/fence/agents/ifmib/fence_ifmib.py index 544d236..7645afa 100644 --- a/fence/agents/ifmib/fence_ifmib.py +++ b/fence/agents/ifmib/fence_ifmib.py @@ -106,7 +106,8 @@ def main(): "test", "port", "separator", "no_login", "no_password", "snmp_version", "community", "snmp_auth_prot", "snmp_sec_level", "snmp_priv_prot", "snmp_priv_passwd", "snmp_priv_passwd_script", - "udpport","inet4_only","inet6_only"] + "udpport","inet4_only","inet6_only", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/ilo/fence_ilo.py b/fence/agents/ilo/fence_ilo.py index 7483780..574f944 100755 --- a/fence/agents/ilo/fence_ilo.py +++ b/fence/agents/ilo/fence_ilo.py @@ -27,7 +27,7 @@ def get_power_status(conn, options): " PASSWORD = \"" + options["-p"] + "\">\r\n") conn.send("<SERVER_INFO MODE = \"read\"><GET_HOST_POWER_STATUS/>\r\n") conn.send("</SERVER_INFO></LOGIN>\r\n") - conn.log_expect(options, "HOST_POWER=\"(.*?)\"", POWER_TIMEOUT) + conn.log_expect(options, "HOST_POWER=\"(.*?)\"", int(options["-g"])) status = conn.match.group(1) return status.lower().strip() @@ -56,10 +56,13 @@ def set_power_status(conn, options): def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", - "ssl", "ribcl", "inet4_only", "inet6_only", "ipport" ] + "ssl", "ribcl", "inet4_only", "inet6_only", "ipport", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) + all_opt["login_timeout"]["default"] = "10" + pinput = process_input(device_opt) pinput["-z"] = 1 options = check_input(device_opt, pinput) @@ -74,7 +77,7 @@ def main(): conn = fence_login(options) try: conn.send("<?xml version=\"1.0\"?>\r\n") - conn.log_expect(options, [ "</RIBCL>", "<END_RIBCL/>" ], LOGIN_TIMEOUT) + conn.log_expect(options, [ "</RIBCL>", "<END_RIBCL/>" ], int(options["-y"])) version = re.compile("<RIBCL VERSION=\"(.*?)\"", re.IGNORECASE).search(conn.before).group(1) if options.has_key("-r") == 0: options["-r"] = float(version) @@ -89,8 +92,8 @@ def main(): if options["-r"] >= 2: conn.send("<RIB_INFO MODE=\"read\"><GET_FW_VERSION />\r\n") conn.send("</RIB_INFO>\r\n") - conn.log_expect(options, "<GET_FW_VERSION\s*\n", SHELL_TIMEOUT) - conn.log_expect(options, "/>", SHELL_TIMEOUT) + conn.log_expect(options, "<GET_FW_VERSION\s*\n", int(options["-Y"])) + 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("</LOGIN>\r\n") diff --git a/fence/agents/ilo_mp/fence_ilo_mp.py b/fence/agents/ilo_mp/fence_ilo_mp.py index baaf076..a676fb8 100644 --- a/fence/agents/ilo_mp/fence_ilo_mp.py +++ b/fence/agents/ilo_mp/fence_ilo_mp.py @@ -12,7 +12,7 @@ BUILD_DATE="" def get_power_status(conn, options): conn.send("show /system1\n") - conn.log_expect(options, "EnabledState=(.*)", POWER_TIMEOUT) + conn.log_expect(options, "EnabledState=(.*)", int(options["-Y"])) status = conn.match.group(1) @@ -32,7 +32,8 @@ def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", "secure", "cmd_prompt", "ipport", "login_eol_lf", - "separator", "inet4_only", "inet6_only" ] + "separator", "inet4_only", "inet6_only", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/intelmodular/fence_intelmodular.py b/fence/agents/intelmodular/fence_intelmodular.py index 4969772..a03e4a6 100644 --- a/fence/agents/intelmodular/fence_intelmodular.py +++ b/fence/agents/intelmodular/fence_intelmodular.py @@ -68,7 +68,8 @@ def main(): "test", "port", "separator", "no_login", "no_password", "snmp_version", "community", "snmp_auth_prot", "snmp_sec_level", "snmp_priv_prot", "snmp_priv_passwd", "snmp_priv_passwd_script", - "udpport","inet4_only","inet6_only"] + "udpport","inet4_only","inet6_only", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/ldom/fence_ldom.py b/fence/agents/ldom/fence_ldom.py index d5e7285..4806982 100644 --- a/fence/agents/ldom/fence_ldom.py +++ b/fence/agents/ldom/fence_ldom.py @@ -23,11 +23,11 @@ COMMAND_PROMPT_NEW="[PEXPECT]" # Start comunicating after login. Prepare good environment. def start_communication(conn, options): conn.sendline ("PS1='"+COMMAND_PROMPT_NEW+"'") - res=conn.expect([pexpect.TIMEOUT, COMMAND_PROMPT_REG],SHELL_TIMEOUT) + res=conn.expect([pexpect.TIMEOUT, COMMAND_PROMPT_REG],int(options["-Y"])) if res==0: #CSH stuff conn.sendline("set prompt='"+COMMAND_PROMPT_NEW+"'") - conn.log_expect(options, COMMAND_PROMPT_REG,SHELL_TIMEOUT) + conn.log_expect(options, COMMAND_PROMPT_REG,int(options["-Y"])) def get_power_status(conn, options): @@ -36,7 +36,7 @@ def get_power_status(conn, options): conn.sendline("ldm ls") - conn.log_expect(options,COMMAND_PROMPT_REG,SHELL_TIMEOUT) + conn.log_expect(options,COMMAND_PROMPT_REG,int(options["-Y"])) result={} @@ -73,7 +73,7 @@ def set_power_status(conn, options): conn.sendline(cmd_line) - conn.log_expect(options,COMMAND_PROMPT_REG,POWER_TIMEOUT) + conn.log_expect(options,COMMAND_PROMPT_REG,int(options["-g"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) @@ -84,7 +84,8 @@ def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", "secure", "identity_file", "test" , "port", "cmd_prompt", - "separator", "inet4_only", "inet6_only", "ipport" ] + "separator", "inet4_only", "inet6_only", "ipport", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py index 96f25e0..fe83a3f 100644 --- a/fence/agents/lib/fencing.py.py +++ b/fence/agents/lib/fencing.py.py @@ -12,10 +12,6 @@ REDHAT_COPYRIGHT = "" BUILD_DATE = "March, 2008" #END_VERSION_GENERATION -POWER_TIMEOUT = 20 -SHELL_TIMEOUT = 3 -LOGIN_TIMEOUT = 5 - LOG_MODE_VERBOSE = 100 LOG_MODE_QUIET = 0 @@ -322,7 +318,31 @@ all_opt = { "default" : ",", "required" : "0", "shortdesc" : "Separator for CSV created by operation list", - "order" : 100 } + "order" : 100 }, + "login_timeout" : { + "getopt" : "y:", + "longopt" : "login-timeout", + "help" : "--login-timeout <seconds> Wait X seconds for cmd prompt after login", + "default" : "5", + "order" : 200 }, + "shell_timeout" : { + "getopt" : "Y:", + "longopt" : "shell-timeout", + "help" : "--shell-timeout <seconds> Wait X seconds for cmd prompt after issuing command", + "default" : "3", + "order" : 200 }, + "power_timeout" : { + "getopt" : "g:", + "longopt" : "power-timeout", + "help" : "--power-timeout <seconds> Test X seconds for status change after ON/OFF", + "default" : "20", + "order" : 200 }, + "power_wait" : { + "getopt" : "G:", + "longopt" : "power-wait", + "help" : "--power-wait <seconds> Wait X seconds after issuing ON/OFF", + "default" : "0", + "order" : 200 } } class fspawn(pexpect.spawn): @@ -621,7 +641,7 @@ def check_input(device_opt, opt): return options def wait_power_status(tn, options, get_power_fn): - for dummy in xrange(POWER_TIMEOUT): + for dummy in xrange(int(options["-g"])): if get_power_fn(tn, options) != options["-o"]: time.sleep(1) else: @@ -688,6 +708,7 @@ def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None print "Success: Already ON" else: set_power_fn(tn, options) + time.sleep(int(options["-G"])) if wait_power_status(tn, options, get_power_fn): print "Success: Powered ON" else: @@ -697,6 +718,7 @@ def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None print "Success: Already OFF" else: set_power_fn(tn, options) + time.sleep(int(options["-G"])) if wait_power_status(tn, options, get_power_fn): print "Success: Powered OFF" else: @@ -705,10 +727,12 @@ def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None if status != "off": options["-o"] = "off" set_power_fn(tn, options) + time.sleep(int(options["-G"])) if wait_power_status(tn, options, get_power_fn) == 0: fail(EC_WAITING_OFF) options["-o"] = "on" set_power_fn(tn, options) + time.sleep(int(options["-G"])) if wait_power_status(tn, options, get_power_fn) == 0: sys.stderr.write('Timed out waiting to power ON\n') print "Success: Rebooted" @@ -757,21 +781,21 @@ def fence_login(options): if options.has_key("telnet_over_ssh"): #This is for stupid ssh servers (like ALOM) which behave more like telnet (ignore name and display login prompt) - result = conn.log_expect(options, [ re_login, "Are you sure you want to continue connecting (yes/no)?" ], LOGIN_TIMEOUT) + result = conn.log_expect(options, [ re_login, "Are you sure you want to continue connecting (yes/no)?" ], int(options["-y"])) if result == 1: conn.sendline("yes") # Host identity confirm - conn.log_expect(options, re_login, LOGIN_TIMEOUT) + conn.log_expect(options, re_login, int(options["-y"])) conn.sendline(options["-l"]) - conn.log_expect(options, re_pass, LOGIN_TIMEOUT) + conn.log_expect(options, re_pass, int(options["-y"])) else: - result = conn.log_expect(options, [ "ssword:", "Are you sure you want to continue connecting (yes/no)?" ], LOGIN_TIMEOUT) + result = conn.log_expect(options, [ "ssword:", "Are you sure you want to continue connecting (yes/no)?" ], int(options["-y"])) if result == 1: conn.sendline("yes") - conn.log_expect(options, "ssword:", LOGIN_TIMEOUT) + conn.log_expect(options, "ssword:", int(options["-y"])) conn.sendline(options["-p"]) - conn.log_expect(options, options["-c"], LOGIN_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-y"])) elif options.has_key("-x") and 1 == options.has_key("-k"): command = '%s %s %s@%s -i %s -p %s' % (SSH_PATH, force_ipvx, options["-l"], options["-a"], options["-k"], options["-u"]) if options.has_key("ssh_options"): @@ -784,14 +808,14 @@ def fence_login(options): "are not in the spec file and must be installed separately." + "\n") sys.exit(EC_GENERIC_ERROR) - result = conn.log_expect(options, [ options["-c"], "Are you sure you want to continue connecting (yes/no)?", "Enter passphrase for key '"+options["-k"]+"':" ], LOGIN_TIMEOUT) + result = conn.log_expect(options, [ options["-c"], "Are you sure you want to continue connecting (yes/no)?", "Enter passphrase for key '"+options["-k"]+"':" ], int(options["-y"])) if result == 1: conn.sendline("yes") - conn.log_expect(options, [ options["-c"], "Enter passphrase for key '"+options["-k"]+"':"] , LOGIN_TIMEOUT) + conn.log_expect(options, [ options["-c"], "Enter passphrase for key '"+options["-k"]+"':"] , int(options["-y"])) if result != 0: if options.has_key("-p"): conn.sendline(options["-p"]) - conn.log_expect(options, options["-c"], LOGIN_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-y"])) else: fail_usage("Failed: You have to enter passphrase (-p) for identity file") else: @@ -805,11 +829,11 @@ def fence_login(options): "are not in the spec file and must be installed separately." + "\n") sys.exit(EC_GENERIC_ERROR) - conn.log_expect(options, re_login, LOGIN_TIMEOUT) + conn.log_expect(options, re_login, int(options["-y"])) conn.send(options["-l"] + login_eol) - conn.log_expect(options, re_pass, SHELL_TIMEOUT) + conn.log_expect(options, re_pass, int(options["-Y"])) conn.send(options["-p"] + login_eol) - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) except pexpect.EOF: fail(EC_LOGIN_DENIED) except pexpect.TIMEOUT: diff --git a/fence/agents/lib/fencing_snmp.py.py b/fence/agents/lib/fencing_snmp.py.py index 1292b5b..d6f6ab4 100644 --- a/fence/agents/lib/fencing_snmp.py.py +++ b/fence/agents/lib/fencing_snmp.py.py @@ -80,7 +80,7 @@ class FencingSnmp: try: self.log_command(command) - (res_output,res_code)=pexpect.run(command,SHELL_TIMEOUT+LOGIN_TIMEOUT+additional_timemout,True) + (res_output,res_code)=pexpect.run(command,int(options["-Y"])+int(options["-y"])+additional_timemout,True) if (res_code==None): fail(EC_TIMED_OUT) diff --git a/fence/agents/lpar/fence_lpar.py b/fence/agents/lpar/fence_lpar.py index 751ba7a..8a88121 100644 --- a/fence/agents/lpar/fence_lpar.py +++ b/fence/agents/lpar/fence_lpar.py @@ -24,7 +24,7 @@ def get_power_status(conn, options): if options["-H"] == "3": try: conn.send("lssyscfg -r lpar -m " + options["-s"] + " -n " + options["-n"] + " -F name,state\n") - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -37,7 +37,7 @@ def get_power_status(conn, options): elif options["-H"] == "4": try: conn.send("lssyscfg -r lpar -m "+ options["-s"] +" --filter 'lpar_names=" + options["-n"] + "'\n") - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -62,7 +62,7 @@ def set_power_status(conn, options): try: conn.send("chsysstate -o " + options["-o"] + " -r lpar -m " + options["-s"] + " -n " + options["-n"] + "\n") - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -78,7 +78,7 @@ def set_power_status(conn, options): else: conn.send("chsysstate -o shutdown -r lpar --immed" + " -m " + options["-s"] + " -n " + options["-n"] + "\n") - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -89,7 +89,7 @@ def get_lpar_list(conn, options): if options["-H"] == "3": try: conn.send("query_partition_names -m " + options["-s"] + "\n") - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) ## We have to remove first 3 lines (command + header) and last line (part of new prompt) #### @@ -109,7 +109,7 @@ def get_lpar_list(conn, options): try: conn.send("lssyscfg -r lpar -m " + options["-s"] + " -F name:state\n") - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) ## We have to remove first line (command) and last line (part of new prompt) #### @@ -133,7 +133,8 @@ def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", "secure", "partition", "managed", "hmc_version", "cmd_prompt", - "separator", "inet4_only", "inet6_only", "ipport" ] + "separator", "inet4_only", "inet6_only", "ipport", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/rsa/fence_rsa.py b/fence/agents/rsa/fence_rsa.py index dec626c..91dd5fd 100644 --- a/fence/agents/rsa/fence_rsa.py +++ b/fence/agents/rsa/fence_rsa.py @@ -20,7 +20,7 @@ BUILD_DATE="March, 2009" def get_power_status(conn, options): try: conn.send("power state\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -32,7 +32,7 @@ def get_power_status(conn, options): def set_power_status(conn, options): try: conn.send("power " + options["-o"] + "\r\n") - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -41,7 +41,8 @@ def set_power_status(conn, options): def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", - "cmd_prompt", "secure", "ipport" ] + "cmd_prompt", "secure", "ipport", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/sanbox2/fence_sanbox2.py b/fence/agents/sanbox2/fence_sanbox2.py index 0b048a3..d1e65cf 100644 --- a/fence/agents/sanbox2/fence_sanbox2.py +++ b/fence/agents/sanbox2/fence_sanbox2.py @@ -25,7 +25,7 @@ def get_power_status(conn, options): } try: conn.send("show port " + options["-n"] + "\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -52,7 +52,7 @@ def set_power_status(conn, options): try: conn.send("set port " + options["-n"] + " state " + action + "\n") - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -66,7 +66,7 @@ def set_power_status(conn, options): try: conn.send("set port " + options["-n"] + " state " + action + "\n") - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -83,7 +83,7 @@ def get_list_devices(conn, options): try: conn.send("show port" + "\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) list_re = re.compile("^\s+(\d+?)\s+(Online|Offline)\s+", re.IGNORECASE) for line in conn.before.splitlines(): @@ -110,7 +110,8 @@ def get_list_devices(conn, options): def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "io_fencing", "ipaddr", "login", "passwd", "passwd_script", - "cmd_prompt", "port", "ipport", "login_eol_lf", "separator" ] + "cmd_prompt", "port", "ipport", "login_eol_lf", "separator", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) @@ -130,7 +131,7 @@ def main(): conn = fence_login(options) conn.send("admin start\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) if (re.search("\(admin\)", conn.before, re.MULTILINE) == None): ## Someone else is in admin section, we can't enable/disable diff --git a/fence/agents/virsh/fence_virsh.py b/fence/agents/virsh/fence_virsh.py index eae7405..7ef71a3 100644 --- a/fence/agents/virsh/fence_virsh.py +++ b/fence/agents/virsh/fence_virsh.py @@ -18,7 +18,7 @@ BUILD_DATE="" def get_outlets_status(conn, options): try: conn.sendline("virsh list --all") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -51,7 +51,7 @@ def set_power_status(conn, options): try: conn.sendline("virsh %s "%(options["-o"] == "on" and "start" or "destroy")+options["-n"]) - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) time.sleep(1) except pexpect.EOF: @@ -63,7 +63,8 @@ def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", "secure", "identity_file", "test", "port", "separator", - "inet4_only", "inet6_only", "ipport" ] + "inet4_only", "inet6_only", "ipport", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/vmware/fence_vmware.py b/fence/agents/vmware/fence_vmware.py index 070c2c4..63e9360 100644 --- a/fence/agents/vmware/fence_vmware.py +++ b/fence/agents/vmware/fence_vmware.py @@ -148,7 +148,7 @@ def vmware_run_command(options,add_login_params,additional_params,additional_tim try: vmware_log(options,command) - (res_output,res_code)=pexpect.run(command,SHELL_TIMEOUT+LOGIN_TIMEOUT+additional_timeout,True) + (res_output,res_code)=pexpect.run(command,int(options["-Y"])+int(options["-y"])+additional_timeout,True) if (res_code==None): fail(EC_TIMED_OUT) @@ -171,7 +171,7 @@ def vmware_get_outlets_vi(conn, options, add_vm_name): if (add_vm_name): all_machines=vmware_run_command(options,True,("--operation status --vmname '%s'"%(quote_for_run(options["-n"]))),0) else: - all_machines=vmware_run_command(options,True,"--operation list",POWER_TIMEOUT) + all_machines=vmware_run_command(options,True,"--operation list",int(options["-g"])) all_machines_array=all_machines.splitlines() @@ -237,7 +237,7 @@ def set_power_status(conn, options): if (options["-o"]=="off"): additional_params+=" hard" - vmware_run_command(options,True,additional_params,POWER_TIMEOUT) + vmware_run_command(options,True,additional_params,int(options["-g"])) # Returns True, if user uses supported vmrun version (currently >=2.0.0) otherwise False. def vmware_is_supported_vmrun_version(options): @@ -287,7 +287,8 @@ def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", "test", "port", "separator", "exec", "vmware_type", - "vmware_datacenter", "secure" ] + "vmware_datacenter", "secure", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/wti/fence_wti.py b/fence/agents/wti/fence_wti.py index 25cbccc..514bc9d 100644 --- a/fence/agents/wti/fence_wti.py +++ b/fence/agents/wti/fence_wti.py @@ -24,7 +24,7 @@ BUILD_DATE="March, 2008" def get_power_status(conn, options): try: conn.send("/S"+"\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -66,7 +66,7 @@ def set_power_status(conn, options): try: conn.send(action + " " + options["-n"] + ",y\r\n") - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -76,7 +76,8 @@ def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", "cmd_prompt", "secure", "port", "no_login", "no_password", - "test", "separator", "inet4_only", "inet6_only", "ipport" ] + "test", "separator", "inet4_only", "inet6_only", "ipport", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) @@ -108,18 +109,18 @@ def main(): 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) - result = conn.log_expect(options, [ re_login, "Password: ", re_prompt ], SHELL_TIMEOUT) + result = conn.log_expect(options, [ re_login, "Password: ", re_prompt ], int(options["-Y"])) if result == 0: if options.has_key("-l"): conn.send(options["-l"]+"\r\n") - result = conn.log_expect(options, [ re_login, "Password: ", re_prompt ], SHELL_TIMEOUT) + result = conn.log_expect(options, [ re_login, "Password: ", re_prompt ], int(options["-Y"])) 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"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) else: fail_usage("Failed: You have to enter password or password script") except pexpect.EOF:
1
0
0
0
fence-agents: master - fencing: Timeout options added
by Marek Grác
09 Oct '09
09 Oct '09
Gitweb:
http://git.fedorahosted.org/git/fence-agents.git?p=fence-agents.git;a=commi…
Commit: 43872d098d9406fd09afd81e972188a728e1c7a3 Parent: 6a34bd9d7f3f68f26f06f8d57eea6135b6c6b6d6 Author: Marek 'marx' Grac <mgrac(a)redhat.com> AuthorDate: Fri Oct 9 13:36:25 2009 +0200 Committer: Marek 'marx' Grac <mgrac(a)redhat.com> CommitterDate: Fri Oct 9 13:36:25 2009 +0200 fencing: Timeout options added Fencing agents based on fencing library have new set of timeout options. They are highly advanced so read documentation at
http://sources.redhat.com/cluster/wiki/FenceTiming
--- fence/agents/alom/fence_alom.py | 9 ++-- fence/agents/apc/fence_apc.py | 37 +++++++------- fence/agents/apc_snmp/fence_apc_snmp.py | 3 +- fence/agents/bladecenter/fence_bladecenter.py | 28 +++++------ fence/agents/cisco_mds/fence_cisco_mds.py | 3 +- fence/agents/drac5/fence_drac5.py | 9 ++-- fence/agents/ibmblade/fence_ibmblade.py | 3 +- fence/agents/ifmib/fence_ifmib.py | 3 +- fence/agents/ilo/fence_ilo.py | 13 +++-- fence/agents/ilo_mp/fence_ilo_mp.py | 5 +- fence/agents/intelmodular/fence_intelmodular.py | 3 +- fence/agents/ldom/fence_ldom.py | 11 ++-- fence/agents/lib/fencing.py.py | 60 ++++++++++++++++------- fence/agents/lib/fencing_snmp.py.py | 2 +- fence/agents/lpar/fence_lpar.py | 15 +++--- fence/agents/rsa/fence_rsa.py | 7 ++- fence/agents/sanbox2/fence_sanbox2.py | 13 +++-- fence/agents/virsh/fence_virsh.py | 7 ++- fence/agents/vmware/fence_vmware.py | 9 ++-- fence/agents/wti/fence_wti.py | 13 +++-- 20 files changed, 147 insertions(+), 106 deletions(-) diff --git a/fence/agents/alom/fence_alom.py b/fence/agents/alom/fence_alom.py index d88f718..4fffa0a 100644 --- a/fence/agents/alom/fence_alom.py +++ b/fence/agents/alom/fence_alom.py @@ -19,7 +19,7 @@ def get_power_status(conn, options): result = "" try: conn.sendline("showplatform") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + 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: @@ -33,9 +33,9 @@ def set_power_status(conn, options): try: cmd_line=(options["-o"]=="on" and "poweron" or "poweroff -f -y") conn.sendline(cmd_line) - conn.log_expect(options, options["-c"],POWER_TIMEOUT) + conn.log_expect(options, options["-c"],int(options["-g"])) #Get the machine some time between poweron and poweroff - time.sleep(POWER_TIMEOUT) + time.sleep(int(options["-g"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) @@ -45,7 +45,8 @@ def set_power_status(conn, options): def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", - "secure", "test", "inet4_only", "inet6_only", "ipport" ] + "secure", "test", "inet4_only", "inet6_only", "ipport", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/apc/fence_apc.py b/fence/agents/apc/fence_apc.py index a48877e..685a154 100755 --- a/fence/agents/apc/fence_apc.py +++ b/fence/agents/apc/fence_apc.py @@ -29,7 +29,7 @@ def get_power_status(conn, options): outlets = {} try: conn.send("1\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) version = 0 admin = 0 @@ -62,13 +62,13 @@ def get_power_status(conn, options): conn.send("3\r\n") else: conn.send("2\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) conn.send("1\r\n") else: conn.send(options["-s"]+"\r\n") while True: - exp_result = conn.log_expect(options, [ options["-c"], "Press <ENTER>" ], SHELL_TIMEOUT) + exp_result = conn.log_expect(options, [ options["-c"], "Press <ENTER>" ], int(options["-Y"])) lines = conn.before.split("\n"); show_re = re.compile('^\s*(\d+)- (.*?)\s+(ON|OFF)\s*') for x in lines: @@ -79,8 +79,8 @@ def get_power_status(conn, options): if exp_result == 0: break conn.send(chr(03)) - conn.log_expect(options, "- Logout", SHELL_TIMEOUT) - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + 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: @@ -103,7 +103,7 @@ def set_power_status(conn, options): try: conn.send("1\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) version = 0 admin2 = 0 @@ -142,7 +142,7 @@ def set_power_status(conn, options): conn.send("3\r\n") else: conn.send("2\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + 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: @@ -151,31 +151,31 @@ def set_power_status(conn, options): else: conn.send(options["-s"] + "\r\n") - while 1 == conn.log_expect(options, [ options["-c"], "Press <ENTER>" ], SHELL_TIMEOUT): + while 1 == conn.log_expect(options, [ options["-c"], "Press <ENTER>" ], int(options["-Y"])): conn.send("\r\n") conn.send(options["-n"]+"\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) if switch == 0: if admin2 == 1: conn.send("1\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) if admin3 == 1: conn.send("1\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) else: conn.send("1\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) conn.send(action+"\r\n") - conn.log_expect(options, "Enter 'YES' to continue or <ENTER> to cancel :", SHELL_TIMEOUT) + conn.log_expect(options, "Enter 'YES' to continue or <ENTER> to cancel :", int(options["-Y"])) conn.send("YES\r\n") - conn.log_expect(options, "Press <ENTER> to continue...", SHELL_TIMEOUT) + conn.log_expect(options, "Press <ENTER> to continue...", int(options["-Y"])) conn.send("\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) conn.send(chr(03)) - conn.log_expect(options, "- Logout", SHELL_TIMEOUT) - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + 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: @@ -185,7 +185,8 @@ def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", "secure", "port", "switch", "test", "separator", - "inet4_only", "inet6_only", "ipport" ] + "inet4_only", "inet6_only", "ipport", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/apc_snmp/fence_apc_snmp.py b/fence/agents/apc_snmp/fence_apc_snmp.py index e66a6b0..7e8118e 100644 --- a/fence/agents/apc_snmp/fence_apc_snmp.py +++ b/fence/agents/apc_snmp/fence_apc_snmp.py @@ -169,7 +169,8 @@ def main(): "test", "port", "separator", "no_login", "no_password", "snmp_version", "community", "snmp_auth_prot", "snmp_sec_level", "snmp_priv_prot", "snmp_priv_passwd", "snmp_priv_passwd_script", - "udpport","inet4_only","inet6_only"] + "udpport","inet4_only","inet6_only", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/bladecenter/fence_bladecenter.py b/fence/agents/bladecenter/fence_bladecenter.py index eacac33..87819e4 100644 --- a/fence/agents/bladecenter/fence_bladecenter.py +++ b/fence/agents/bladecenter/fence_bladecenter.py @@ -27,15 +27,15 @@ def get_power_status(conn, options): node_cmd = "system:blade\[" + options["-n"] + "\]>" conn.send("env -T system:blade[" + options["-n"] + "]\r\n") - i = conn.log_expect(options, [ node_cmd, "system>" ] , SHELL_TIMEOUT) + i = conn.log_expect(options, [ node_cmd, "system>" ] , int(options["-Y"])) if i == 1: ## Given blade number does not exist fail(EC_STATUS) conn.send("power -state\r\n") - conn.log_expect(options, node_cmd, SHELL_TIMEOUT) + conn.log_expect(options, node_cmd, int(options["-Y"])) status = conn.before.splitlines()[-1] conn.send("env -T system\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -53,11 +53,11 @@ def set_power_status(conn, options): node_cmd = "system:blade\[" + options["-n"] + "\]>" conn.send("env -T system:blade[" + options["-n"] + "]\r\n") - conn.log_expect(options, node_cmd, SHELL_TIMEOUT) + conn.log_expect(options, node_cmd, int(options["-Y"])) conn.send("power -"+options["-o"]+"\r\n") - conn.log_expect(options, node_cmd, SHELL_TIMEOUT) + conn.log_expect(options, node_cmd, int(options["-Y"])) conn.send("env -T system\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -69,9 +69,9 @@ def get_blades_list(conn, options): node_cmd = "system>" conn.send("env -T system\r\n") - conn.log_expect(options, node_cmd, SHELL_TIMEOUT) + conn.log_expect(options, node_cmd, int(options["-Y"])) conn.send("list -l 2\r\n") - conn.log_expect(options, node_cmd, SHELL_TIMEOUT) + conn.log_expect(options, node_cmd, int(options["-Y"])) lines = conn.before.split("\r\n") filter_re = re.compile("^\s*blade\[(\d+)\]\s+(.*?)\s*$") @@ -91,17 +91,15 @@ def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", "cmd_prompt", "secure", "port", "identity_file", "separator", - "inet4_only", "inet6_only", "ipport" ] + "inet4_only", "inet6_only", "ipport", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) - options = check_input(device_opt, process_input(device_opt)) + all_opt["power_wait"]["default"] = "5" + all_opt["cmd_prompt"]["default"] = "system>" - ## - ## Fence agent specific defaults - ##### - if 0 == options.has_key("-c"): - options["-c"] = "system>" + options = check_input(device_opt, process_input(device_opt)) show_docs(options) diff --git a/fence/agents/cisco_mds/fence_cisco_mds.py b/fence/agents/cisco_mds/fence_cisco_mds.py index 944e593..d007b72 100644 --- a/fence/agents/cisco_mds/fence_cisco_mds.py +++ b/fence/agents/cisco_mds/fence_cisco_mds.py @@ -86,7 +86,8 @@ def main(): "test", "port", "separator", "no_login", "no_password", "snmp_version", "community", "snmp_auth_prot", "snmp_sec_level", "snmp_priv_prot", "snmp_priv_passwd", "snmp_priv_passwd_script", - "udpport","inet4_only","inet6_only"] + "udpport","inet4_only","inet6_only", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/drac5/fence_drac5.py b/fence/agents/drac5/fence_drac5.py index 231fd06..d7fbdaa 100644 --- a/fence/agents/drac5/fence_drac5.py +++ b/fence/agents/drac5/fence_drac5.py @@ -29,7 +29,7 @@ def get_power_status(conn, options): elif options["model"] == "DRAC 5": conn.sendline("racadm serveraction powerstatus") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -52,7 +52,7 @@ def set_power_status(conn, options): conn.sendline("racadm serveraction " + action + " -m " + options["-m"]) elif options["model"] == "DRAC 5": conn.sendline("racadm serveraction " + action) - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -69,7 +69,7 @@ def get_list_devices(conn, options): for line in conn.before.splitlines(): if (list_re.search(line)): outlets[list_re.search(line).group(1)] = ("", list_re.search(line).group(2)) - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) elif options["model"] == "DRAC 5": ## DRAC 5 can be used only for one computer pass @@ -84,7 +84,8 @@ def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", "cmd_prompt", "secure", "drac_version", "module_name", - "separator", "inet4_only", "inet6_only", "ipport" ] + "separator", "inet4_only", "inet6_only", "ipport", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/ibmblade/fence_ibmblade.py b/fence/agents/ibmblade/fence_ibmblade.py index 700437d..4ff334e 100644 --- a/fence/agents/ibmblade/fence_ibmblade.py +++ b/fence/agents/ibmblade/fence_ibmblade.py @@ -61,7 +61,8 @@ def main(): "test", "port", "separator", "no_login", "no_password", "snmp_version", "community", "snmp_auth_prot", "snmp_sec_level", "snmp_priv_prot", "snmp_priv_passwd", "snmp_priv_passwd_script", - "udpport","inet4_only","inet6_only"] + "udpport","inet4_only","inet6_only", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/ifmib/fence_ifmib.py b/fence/agents/ifmib/fence_ifmib.py index 544d236..7645afa 100644 --- a/fence/agents/ifmib/fence_ifmib.py +++ b/fence/agents/ifmib/fence_ifmib.py @@ -106,7 +106,8 @@ def main(): "test", "port", "separator", "no_login", "no_password", "snmp_version", "community", "snmp_auth_prot", "snmp_sec_level", "snmp_priv_prot", "snmp_priv_passwd", "snmp_priv_passwd_script", - "udpport","inet4_only","inet6_only"] + "udpport","inet4_only","inet6_only", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/ilo/fence_ilo.py b/fence/agents/ilo/fence_ilo.py index 7483780..574f944 100755 --- a/fence/agents/ilo/fence_ilo.py +++ b/fence/agents/ilo/fence_ilo.py @@ -27,7 +27,7 @@ def get_power_status(conn, options): " PASSWORD = \"" + options["-p"] + "\">\r\n") conn.send("<SERVER_INFO MODE = \"read\"><GET_HOST_POWER_STATUS/>\r\n") conn.send("</SERVER_INFO></LOGIN>\r\n") - conn.log_expect(options, "HOST_POWER=\"(.*?)\"", POWER_TIMEOUT) + conn.log_expect(options, "HOST_POWER=\"(.*?)\"", int(options["-g"])) status = conn.match.group(1) return status.lower().strip() @@ -56,10 +56,13 @@ def set_power_status(conn, options): def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", - "ssl", "ribcl", "inet4_only", "inet6_only", "ipport" ] + "ssl", "ribcl", "inet4_only", "inet6_only", "ipport", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) + all_opt["login_timeout"]["default"] = "10" + pinput = process_input(device_opt) pinput["-z"] = 1 options = check_input(device_opt, pinput) @@ -74,7 +77,7 @@ def main(): conn = fence_login(options) try: conn.send("<?xml version=\"1.0\"?>\r\n") - conn.log_expect(options, [ "</RIBCL>", "<END_RIBCL/>" ], LOGIN_TIMEOUT) + conn.log_expect(options, [ "</RIBCL>", "<END_RIBCL/>" ], int(options["-y"])) version = re.compile("<RIBCL VERSION=\"(.*?)\"", re.IGNORECASE).search(conn.before).group(1) if options.has_key("-r") == 0: options["-r"] = float(version) @@ -89,8 +92,8 @@ def main(): if options["-r"] >= 2: conn.send("<RIB_INFO MODE=\"read\"><GET_FW_VERSION />\r\n") conn.send("</RIB_INFO>\r\n") - conn.log_expect(options, "<GET_FW_VERSION\s*\n", SHELL_TIMEOUT) - conn.log_expect(options, "/>", SHELL_TIMEOUT) + conn.log_expect(options, "<GET_FW_VERSION\s*\n", int(options["-Y"])) + 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("</LOGIN>\r\n") diff --git a/fence/agents/ilo_mp/fence_ilo_mp.py b/fence/agents/ilo_mp/fence_ilo_mp.py index baaf076..a676fb8 100644 --- a/fence/agents/ilo_mp/fence_ilo_mp.py +++ b/fence/agents/ilo_mp/fence_ilo_mp.py @@ -12,7 +12,7 @@ BUILD_DATE="" def get_power_status(conn, options): conn.send("show /system1\n") - conn.log_expect(options, "EnabledState=(.*)", POWER_TIMEOUT) + conn.log_expect(options, "EnabledState=(.*)", int(options["-Y"])) status = conn.match.group(1) @@ -32,7 +32,8 @@ def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", "secure", "cmd_prompt", "ipport", "login_eol_lf", - "separator", "inet4_only", "inet6_only" ] + "separator", "inet4_only", "inet6_only", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/intelmodular/fence_intelmodular.py b/fence/agents/intelmodular/fence_intelmodular.py index 4969772..a03e4a6 100644 --- a/fence/agents/intelmodular/fence_intelmodular.py +++ b/fence/agents/intelmodular/fence_intelmodular.py @@ -68,7 +68,8 @@ def main(): "test", "port", "separator", "no_login", "no_password", "snmp_version", "community", "snmp_auth_prot", "snmp_sec_level", "snmp_priv_prot", "snmp_priv_passwd", "snmp_priv_passwd_script", - "udpport","inet4_only","inet6_only"] + "udpport","inet4_only","inet6_only", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/ldom/fence_ldom.py b/fence/agents/ldom/fence_ldom.py index d5e7285..4806982 100644 --- a/fence/agents/ldom/fence_ldom.py +++ b/fence/agents/ldom/fence_ldom.py @@ -23,11 +23,11 @@ COMMAND_PROMPT_NEW="[PEXPECT]" # Start comunicating after login. Prepare good environment. def start_communication(conn, options): conn.sendline ("PS1='"+COMMAND_PROMPT_NEW+"'") - res=conn.expect([pexpect.TIMEOUT, COMMAND_PROMPT_REG],SHELL_TIMEOUT) + res=conn.expect([pexpect.TIMEOUT, COMMAND_PROMPT_REG],int(options["-Y"])) if res==0: #CSH stuff conn.sendline("set prompt='"+COMMAND_PROMPT_NEW+"'") - conn.log_expect(options, COMMAND_PROMPT_REG,SHELL_TIMEOUT) + conn.log_expect(options, COMMAND_PROMPT_REG,int(options["-Y"])) def get_power_status(conn, options): @@ -36,7 +36,7 @@ def get_power_status(conn, options): conn.sendline("ldm ls") - conn.log_expect(options,COMMAND_PROMPT_REG,SHELL_TIMEOUT) + conn.log_expect(options,COMMAND_PROMPT_REG,int(options["-Y"])) result={} @@ -73,7 +73,7 @@ def set_power_status(conn, options): conn.sendline(cmd_line) - conn.log_expect(options,COMMAND_PROMPT_REG,POWER_TIMEOUT) + conn.log_expect(options,COMMAND_PROMPT_REG,int(options["-g"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) @@ -84,7 +84,8 @@ def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", "secure", "identity_file", "test" , "port", "cmd_prompt", - "separator", "inet4_only", "inet6_only", "ipport" ] + "separator", "inet4_only", "inet6_only", "ipport", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py index 96f25e0..fe83a3f 100644 --- a/fence/agents/lib/fencing.py.py +++ b/fence/agents/lib/fencing.py.py @@ -12,10 +12,6 @@ REDHAT_COPYRIGHT = "" BUILD_DATE = "March, 2008" #END_VERSION_GENERATION -POWER_TIMEOUT = 20 -SHELL_TIMEOUT = 3 -LOGIN_TIMEOUT = 5 - LOG_MODE_VERBOSE = 100 LOG_MODE_QUIET = 0 @@ -322,7 +318,31 @@ all_opt = { "default" : ",", "required" : "0", "shortdesc" : "Separator for CSV created by operation list", - "order" : 100 } + "order" : 100 }, + "login_timeout" : { + "getopt" : "y:", + "longopt" : "login-timeout", + "help" : "--login-timeout <seconds> Wait X seconds for cmd prompt after login", + "default" : "5", + "order" : 200 }, + "shell_timeout" : { + "getopt" : "Y:", + "longopt" : "shell-timeout", + "help" : "--shell-timeout <seconds> Wait X seconds for cmd prompt after issuing command", + "default" : "3", + "order" : 200 }, + "power_timeout" : { + "getopt" : "g:", + "longopt" : "power-timeout", + "help" : "--power-timeout <seconds> Test X seconds for status change after ON/OFF", + "default" : "20", + "order" : 200 }, + "power_wait" : { + "getopt" : "G:", + "longopt" : "power-wait", + "help" : "--power-wait <seconds> Wait X seconds after issuing ON/OFF", + "default" : "0", + "order" : 200 } } class fspawn(pexpect.spawn): @@ -621,7 +641,7 @@ def check_input(device_opt, opt): return options def wait_power_status(tn, options, get_power_fn): - for dummy in xrange(POWER_TIMEOUT): + for dummy in xrange(int(options["-g"])): if get_power_fn(tn, options) != options["-o"]: time.sleep(1) else: @@ -688,6 +708,7 @@ def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None print "Success: Already ON" else: set_power_fn(tn, options) + time.sleep(int(options["-G"])) if wait_power_status(tn, options, get_power_fn): print "Success: Powered ON" else: @@ -697,6 +718,7 @@ def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None print "Success: Already OFF" else: set_power_fn(tn, options) + time.sleep(int(options["-G"])) if wait_power_status(tn, options, get_power_fn): print "Success: Powered OFF" else: @@ -705,10 +727,12 @@ def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None if status != "off": options["-o"] = "off" set_power_fn(tn, options) + time.sleep(int(options["-G"])) if wait_power_status(tn, options, get_power_fn) == 0: fail(EC_WAITING_OFF) options["-o"] = "on" set_power_fn(tn, options) + time.sleep(int(options["-G"])) if wait_power_status(tn, options, get_power_fn) == 0: sys.stderr.write('Timed out waiting to power ON\n') print "Success: Rebooted" @@ -757,21 +781,21 @@ def fence_login(options): if options.has_key("telnet_over_ssh"): #This is for stupid ssh servers (like ALOM) which behave more like telnet (ignore name and display login prompt) - result = conn.log_expect(options, [ re_login, "Are you sure you want to continue connecting (yes/no)?" ], LOGIN_TIMEOUT) + result = conn.log_expect(options, [ re_login, "Are you sure you want to continue connecting (yes/no)?" ], int(options["-y"])) if result == 1: conn.sendline("yes") # Host identity confirm - conn.log_expect(options, re_login, LOGIN_TIMEOUT) + conn.log_expect(options, re_login, int(options["-y"])) conn.sendline(options["-l"]) - conn.log_expect(options, re_pass, LOGIN_TIMEOUT) + conn.log_expect(options, re_pass, int(options["-y"])) else: - result = conn.log_expect(options, [ "ssword:", "Are you sure you want to continue connecting (yes/no)?" ], LOGIN_TIMEOUT) + result = conn.log_expect(options, [ "ssword:", "Are you sure you want to continue connecting (yes/no)?" ], int(options["-y"])) if result == 1: conn.sendline("yes") - conn.log_expect(options, "ssword:", LOGIN_TIMEOUT) + conn.log_expect(options, "ssword:", int(options["-y"])) conn.sendline(options["-p"]) - conn.log_expect(options, options["-c"], LOGIN_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-y"])) elif options.has_key("-x") and 1 == options.has_key("-k"): command = '%s %s %s@%s -i %s -p %s' % (SSH_PATH, force_ipvx, options["-l"], options["-a"], options["-k"], options["-u"]) if options.has_key("ssh_options"): @@ -784,14 +808,14 @@ def fence_login(options): "are not in the spec file and must be installed separately." + "\n") sys.exit(EC_GENERIC_ERROR) - result = conn.log_expect(options, [ options["-c"], "Are you sure you want to continue connecting (yes/no)?", "Enter passphrase for key '"+options["-k"]+"':" ], LOGIN_TIMEOUT) + result = conn.log_expect(options, [ options["-c"], "Are you sure you want to continue connecting (yes/no)?", "Enter passphrase for key '"+options["-k"]+"':" ], int(options["-y"])) if result == 1: conn.sendline("yes") - conn.log_expect(options, [ options["-c"], "Enter passphrase for key '"+options["-k"]+"':"] , LOGIN_TIMEOUT) + conn.log_expect(options, [ options["-c"], "Enter passphrase for key '"+options["-k"]+"':"] , int(options["-y"])) if result != 0: if options.has_key("-p"): conn.sendline(options["-p"]) - conn.log_expect(options, options["-c"], LOGIN_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-y"])) else: fail_usage("Failed: You have to enter passphrase (-p) for identity file") else: @@ -805,11 +829,11 @@ def fence_login(options): "are not in the spec file and must be installed separately." + "\n") sys.exit(EC_GENERIC_ERROR) - conn.log_expect(options, re_login, LOGIN_TIMEOUT) + conn.log_expect(options, re_login, int(options["-y"])) conn.send(options["-l"] + login_eol) - conn.log_expect(options, re_pass, SHELL_TIMEOUT) + conn.log_expect(options, re_pass, int(options["-Y"])) conn.send(options["-p"] + login_eol) - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) except pexpect.EOF: fail(EC_LOGIN_DENIED) except pexpect.TIMEOUT: diff --git a/fence/agents/lib/fencing_snmp.py.py b/fence/agents/lib/fencing_snmp.py.py index 1292b5b..d6f6ab4 100644 --- a/fence/agents/lib/fencing_snmp.py.py +++ b/fence/agents/lib/fencing_snmp.py.py @@ -80,7 +80,7 @@ class FencingSnmp: try: self.log_command(command) - (res_output,res_code)=pexpect.run(command,SHELL_TIMEOUT+LOGIN_TIMEOUT+additional_timemout,True) + (res_output,res_code)=pexpect.run(command,int(options["-Y"])+int(options["-y"])+additional_timemout,True) if (res_code==None): fail(EC_TIMED_OUT) diff --git a/fence/agents/lpar/fence_lpar.py b/fence/agents/lpar/fence_lpar.py index 9a8e636..451ca93 100644 --- a/fence/agents/lpar/fence_lpar.py +++ b/fence/agents/lpar/fence_lpar.py @@ -24,7 +24,7 @@ def get_power_status(conn, options): if options["-H"] == "3": try: conn.send("lssyscfg -r lpar -m " + options["-s"] + " -n " + options["-n"] + " -F name,state\n") - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -37,7 +37,7 @@ def get_power_status(conn, options): elif options["-H"] == "4": try: conn.send("lssyscfg -r lpar -m "+ options["-s"] +" --filter 'lpar_names=" + options["-n"] + "'\n") - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -62,7 +62,7 @@ def set_power_status(conn, options): try: conn.send("chsysstate -o " + options["-o"] + " -r lpar -m " + options["-s"] + " -n " + options["-n"] + "\n") - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -78,7 +78,7 @@ def set_power_status(conn, options): else: conn.send("chsysstate -o shutdown -r lpar --immed" + " -m " + options["-s"] + " -n " + options["-n"] + "\n") - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -89,7 +89,7 @@ def get_lpar_list(conn, options): if options["-H"] == "3": try: conn.send("query_partition_names -m " + options["-s"] + "\n") - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) ## We have to remove first 3 lines (command + header) and last line (part of new prompt) #### @@ -109,7 +109,7 @@ def get_lpar_list(conn, options): try: conn.send("lssyscfg -r lpar -m " + options["-s"] + " -F name:state\n") - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) ## We have to remove first line (command) and last line (part of new prompt) #### @@ -133,7 +133,8 @@ def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", "secure", "partition", "managed", "hmc_version", "cmd_prompt", - "separator", "inet4_only", "inet6_only", "ipport" ] + "separator", "inet4_only", "inet6_only", "ipport", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/rsa/fence_rsa.py b/fence/agents/rsa/fence_rsa.py index 0a1335a..16457a9 100644 --- a/fence/agents/rsa/fence_rsa.py +++ b/fence/agents/rsa/fence_rsa.py @@ -19,7 +19,7 @@ BUILD_DATE="March, 2009" def get_power_status(conn, options): try: conn.send("power state\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -31,7 +31,7 @@ def get_power_status(conn, options): def set_power_status(conn, options): try: conn.send("power " + options["-o"] + "\r\n") - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -40,7 +40,8 @@ def set_power_status(conn, options): def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", - "cmd_prompt", "secure", "ipport" ] + "cmd_prompt", "secure", "ipport", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/sanbox2/fence_sanbox2.py b/fence/agents/sanbox2/fence_sanbox2.py index 0b048a3..d1e65cf 100644 --- a/fence/agents/sanbox2/fence_sanbox2.py +++ b/fence/agents/sanbox2/fence_sanbox2.py @@ -25,7 +25,7 @@ def get_power_status(conn, options): } try: conn.send("show port " + options["-n"] + "\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -52,7 +52,7 @@ def set_power_status(conn, options): try: conn.send("set port " + options["-n"] + " state " + action + "\n") - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -66,7 +66,7 @@ def set_power_status(conn, options): try: conn.send("set port " + options["-n"] + " state " + action + "\n") - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -83,7 +83,7 @@ def get_list_devices(conn, options): try: conn.send("show port" + "\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) list_re = re.compile("^\s+(\d+?)\s+(Online|Offline)\s+", re.IGNORECASE) for line in conn.before.splitlines(): @@ -110,7 +110,8 @@ def get_list_devices(conn, options): def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "io_fencing", "ipaddr", "login", "passwd", "passwd_script", - "cmd_prompt", "port", "ipport", "login_eol_lf", "separator" ] + "cmd_prompt", "port", "ipport", "login_eol_lf", "separator", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) @@ -130,7 +131,7 @@ def main(): conn = fence_login(options) conn.send("admin start\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) if (re.search("\(admin\)", conn.before, re.MULTILINE) == None): ## Someone else is in admin section, we can't enable/disable diff --git a/fence/agents/virsh/fence_virsh.py b/fence/agents/virsh/fence_virsh.py index eae7405..7ef71a3 100644 --- a/fence/agents/virsh/fence_virsh.py +++ b/fence/agents/virsh/fence_virsh.py @@ -18,7 +18,7 @@ BUILD_DATE="" def get_outlets_status(conn, options): try: conn.sendline("virsh list --all") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -51,7 +51,7 @@ def set_power_status(conn, options): try: conn.sendline("virsh %s "%(options["-o"] == "on" and "start" or "destroy")+options["-n"]) - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) time.sleep(1) except pexpect.EOF: @@ -63,7 +63,8 @@ def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", "secure", "identity_file", "test", "port", "separator", - "inet4_only", "inet6_only", "ipport" ] + "inet4_only", "inet6_only", "ipport", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/vmware/fence_vmware.py b/fence/agents/vmware/fence_vmware.py index 070c2c4..63e9360 100644 --- a/fence/agents/vmware/fence_vmware.py +++ b/fence/agents/vmware/fence_vmware.py @@ -148,7 +148,7 @@ def vmware_run_command(options,add_login_params,additional_params,additional_tim try: vmware_log(options,command) - (res_output,res_code)=pexpect.run(command,SHELL_TIMEOUT+LOGIN_TIMEOUT+additional_timeout,True) + (res_output,res_code)=pexpect.run(command,int(options["-Y"])+int(options["-y"])+additional_timeout,True) if (res_code==None): fail(EC_TIMED_OUT) @@ -171,7 +171,7 @@ def vmware_get_outlets_vi(conn, options, add_vm_name): if (add_vm_name): all_machines=vmware_run_command(options,True,("--operation status --vmname '%s'"%(quote_for_run(options["-n"]))),0) else: - all_machines=vmware_run_command(options,True,"--operation list",POWER_TIMEOUT) + all_machines=vmware_run_command(options,True,"--operation list",int(options["-g"])) all_machines_array=all_machines.splitlines() @@ -237,7 +237,7 @@ def set_power_status(conn, options): if (options["-o"]=="off"): additional_params+=" hard" - vmware_run_command(options,True,additional_params,POWER_TIMEOUT) + vmware_run_command(options,True,additional_params,int(options["-g"])) # Returns True, if user uses supported vmrun version (currently >=2.0.0) otherwise False. def vmware_is_supported_vmrun_version(options): @@ -287,7 +287,8 @@ def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", "test", "port", "separator", "exec", "vmware_type", - "vmware_datacenter", "secure" ] + "vmware_datacenter", "secure", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) diff --git a/fence/agents/wti/fence_wti.py b/fence/agents/wti/fence_wti.py index 25cbccc..514bc9d 100644 --- a/fence/agents/wti/fence_wti.py +++ b/fence/agents/wti/fence_wti.py @@ -24,7 +24,7 @@ BUILD_DATE="March, 2008" def get_power_status(conn, options): try: conn.send("/S"+"\r\n") - conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -66,7 +66,7 @@ def set_power_status(conn, options): try: conn.send(action + " " + options["-n"] + ",y\r\n") - conn.log_expect(options, options["-c"], POWER_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-g"])) except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -76,7 +76,8 @@ def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", "cmd_prompt", "secure", "port", "no_login", "no_password", - "test", "separator", "inet4_only", "inet6_only", "ipport" ] + "test", "separator", "inet4_only", "inet6_only", "ipport", + "power_timeout", "shell_timeout", "login_timeout", "power_wait" ] atexit.register(atexit_handler) @@ -108,18 +109,18 @@ def main(): 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) - result = conn.log_expect(options, [ re_login, "Password: ", re_prompt ], SHELL_TIMEOUT) + result = conn.log_expect(options, [ re_login, "Password: ", re_prompt ], int(options["-Y"])) if result == 0: if options.has_key("-l"): conn.send(options["-l"]+"\r\n") - result = conn.log_expect(options, [ re_login, "Password: ", re_prompt ], SHELL_TIMEOUT) + result = conn.log_expect(options, [ re_login, "Password: ", re_prompt ], int(options["-Y"])) 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"], SHELL_TIMEOUT) + conn.log_expect(options, options["-c"], int(options["-Y"])) else: fail_usage("Failed: You have to enter password or password script") except pexpect.EOF:
1
0
0
0
cluster: RHEL4 - fence_sanbox2: Re-implementation of fence agent + new option login_eol_lf
by Marek Grác
09 Oct '09
09 Oct '09
Gitweb:
http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=63…
Commit: 6397a742c02d186ac97d55dc9ea9d50dbbce2493 Parent: a9b72c1a181c640f1a469eeb13fe479fc9758cc9 Author: Marek 'marx' Grac <mgrac(a)redhat.com> AuthorDate: Fri Oct 9 12:56:58 2009 +0200 Committer: Marek 'marx' Grac <mgrac(a)redhat.com> CommitterDate: Fri Oct 9 12:59:34 2009 +0200 fence_sanbox2: Re-implementation of fence agent + new option login_eol_lf Reimplementation of fence agent for SANbox2 This option is used for login method using telnet. By default most of the fence agents work with username\r\n but on some devices (e.g. HP iLO MP, sanbox2) it is interpreted as there is empty password. [from STABLE3 - 819956029c9328a3169ba6cb378b4be16088854b] Resolves: bz#510279 --- fence/agents/lib/fencing.py.py | 44 +++++- fence/agents/sanbox2/Makefile | 2 +- fence/agents/sanbox2/fence_sanbox2.pl | 261 --------------------------------- fence/agents/sanbox2/fence_sanbox2.py | 123 ++++++++++++++++ 4 files changed, 162 insertions(+), 268 deletions(-) diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py index 3e9bfd4..1b9221a 100644 --- a/fence/agents/lib/fencing.py.py +++ b/fence/agents/lib/fencing.py.py @@ -65,6 +65,14 @@ all_opt = { "getopt" : "o:", "help" : "-o <action> Action: status, reboot (default), off or on", "order" : 1 }, + "io_fencing" : { + "getopt" : "o:", + "longopt" : "action", + "help" : "-o, --action=<action> Action: status, enable or disable", + "required" : "1", + "shortdesc" : "Fencing Action", + "default" : "disable", + "order" : 1 }, "ipaddr" : { "getopt" : "a:", "help" : "-a <ip> IP address or hostname of fencing device", @@ -255,6 +263,8 @@ def process_input(avail_opt): name = "ipaddr" elif name == "modulename": name = "module_name" + elif name == "action" and 1 == avail_opt.count("io_fencing"): + name = "io_fencing" ## ###### @@ -274,7 +284,8 @@ def process_input(avail_opt): ###### def check_input(device_opt, opt): options = dict(opt) - + options["device_opt"] = device_opt + if options.has_key("-h"): usage(device_opt) sys.exit(0) @@ -289,12 +300,20 @@ def check_input(device_opt, opt): else: options["log"] = LOG_MODE_QUIET - if 0 == options.has_key("-o"): - options["-o"] = "reboot" - - if 0 == ["on", "off", "reboot", "status"].count(options["-o"].lower()): - fail_usage("Failed: Unrecognised action '" + options["-o"] + "'") + # Convert action to lowercase + options["-o"]=options["-o"].lower() + if 0 == device_opt.count("io_fencing"): + if 0 == options.has_key("-o"): + options["-o"] = "reboot" + if 0 == ["on", "off", "reboot", "status"].count(options["-o"].lower()): + fail_usage("Failed: Unrecognised action '" + options["-o"] + "'") + else: + if 0 == options.has_key("-o"): + options["-o"] = "disable" + if 0 == ["enable", "disable", "status"].count(options["-o"].lower()): + fail_usage("Failed: Unrecognised action '" + options["-o"] + "'") + if (0 == options.has_key("-l")) and device_opt.count("login") and (device_opt.count("no_login") == 0): fail_usage("Failed: You have to set login name") @@ -344,6 +363,14 @@ def wait_power_status(tn, options, get_power_fn): def fence_action(tn, options, set_power_fn, get_power_fn): status = get_power_fn(tn, options) + if status != "on" and status != "off": + fail(EC_STATUS) + + if options["-o"] == "enable": + options["-o"] = "on" + if options["-o"] == "disable": + options["-o"] = "off" + if options["-o"] == "on": if status == "on": print "Success: Already ON" @@ -382,6 +409,11 @@ def fence_login(options): else: login_eol = "\r\n" + if (options["device_opt"].count("login_eol_lf")): + login_eol = "\n" + else: + login_eol = "\r\n" + try: re_login = re.compile("(login: )|(Login Name: )|(username: )|(User Name :)", re.IGNORECASE) re_pass = re.compile("password", re.IGNORECASE) diff --git a/fence/agents/sanbox2/Makefile b/fence/agents/sanbox2/Makefile index a387600..489c64f 100644 --- a/fence/agents/sanbox2/Makefile +++ b/fence/agents/sanbox2/Makefile @@ -11,7 +11,7 @@ ############################################################################### ############################################################################### -SOURCE= fence_sanbox2.pl +SOURCE= fence_sanbox2.py TARGET= fence_sanbox2 top_srcdir=../.. diff --git a/fence/agents/sanbox2/fence_sanbox2.pl b/fence/agents/sanbox2/fence_sanbox2.pl deleted file mode 100644 index 86a34cf..0000000 --- a/fence/agents/sanbox2/fence_sanbox2.pl +++ /dev/null @@ -1,261 +0,0 @@ -#!/usr/bin/perl - -############################################################################### -############################################################################### -## -## Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. -## Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. -## -## This copyrighted material is made available to anyone wishing to use, -## modify, copy, or redistribute it subject to the terms and conditions -## of the GNU General Public License v.2. -## -############################################################################### -############################################################################### - -use Getopt::Std; -use Net::Telnet (); - -# Get the program name from $0 and strip directory names -$_=$0; -s/.*\///; -my $pname = $_; - -$opt_o = 'disable'; # Default fence action - -# WARNING!! Do not add code bewteen "#BEGIN_VERSION_GENERATION" and -# "#END_VERSION_GENERATION" It is generated by the Makefile - -#BEGIN_VERSION_GENERATION -$FENCE_RELEASE_NAME=""; -$REDHAT_COPYRIGHT=""; -$BUILD_DATE=""; -#END_VERSION_GENERATION - - -sub usage -{ - print "Usage:\n"; - print "\n"; - print "$pname [options]\n"; - print "\n"; - print "Options:\n"; - print " -a <ip> IP address or hostname of switch\n"; - print " -h usage\n"; - print " -l <name> Login name\n"; - print " -n <num> Port number to disable\n"; - print " -o <string> Action: disable (default) or enable\n"; - print " -p <string> Password for login\n"; - print " -S <path> Script to run to retrieve login password\n"; - print " -q quiet mode\n"; - print " -V version\n"; - - exit 0; -} - -sub fail -{ - ($msg) = @_; - print $msg."\n" unless defined $opt_q; - $t->close if defined $t; - exit 1; -} - -sub fail_usage -{ - ($msg)=@_; - print STDERR $msg."\n" if $msg; - print STDERR "Please use '-h' for usage.\n"; - exit 1; -} - -sub version -{ - print "$pname $FENCE_RELEASE_NAME $BUILD_DATE\n"; - print "$REDHAT_COPYRIGHT\n" if ( $REDHAT_COPYRIGHT ); - - exit 0; -} - - -if (@ARGV > 0) { - getopts("a:hl:n:o:p:S:qV") || fail_usage ; - - usage if defined $opt_h; - version if defined $opt_V; - - fail_usage "Unknown parameter." if (@ARGV > 0); - - fail_usage "No '-a' flag specified." unless defined $opt_a; - fail_usage "No '-n' flag specified." unless defined $opt_n; - fail_usage "No '-l' flag specified." unless defined $opt_l; - - if (defined $opt_S) { - $pwd_script_out = `$opt_S`; - chomp($pwd_script_out); - if ($pwd_script_out) { - $opt_p = $pwd_script_out; - } - } - - fail_usage "No '-p' or '-S' flag specified." unless defined $opt_p; - fail_usage "Unrecognised action '$opt_o' for '-o' flag" - unless $opt_o =~ /^(disable|enable)$/i; - -} else { - get_options_stdin(); - - fail "failed: no IP address" unless defined $opt_a; - fail "failed: no plug number" unless defined $opt_n; - fail "failed: no login name" unless defined $opt_l; - - if (defined $opt_S) { - $pwd_script_out = `$opt_S`; - chomp($pwd_script_out); - if ($pwd_script_out) { - $opt_p = $pwd_script_out; - } - } - - fail "failed: no password" unless defined $opt_p; - fail "failed: unrecognised action: $opt_o" - unless $opt_o =~ /^(disable|enable)$/i; -} - - if ( $opt_o =~ /^disable$/i ) -{ - $command = "set port $opt_n state offline"; -} -elsif ( $opt_o =~ /^enable$/i ) -{ - $command = "set port $opt_n state online"; -} - -# -# Set up and log in -# - -$t = new Net::Telnet; - -$t->open($opt_a); - -$t->waitfor('/login:/'); - -$t->print($opt_l); - -$t->waitfor('/assword:/'); - -$t->print($opt_p); - -$t->waitfor('/\>/'); - -# -# Go to admin mode and check if we're really in it -# -$t->print ("admin start"); -($text, $match) = $t->waitfor('/\>/'); -if ($text =~ /Switch is already in Admin Mode/i) { - fail "failed: parallel telnet session\n"; -}; - -# -# Do the command -# -$t->print($command); -print "$command \n"; - -# -# Assume here that the word "error" will appear after errors (bad assumption! see next check) -# - -($text, $match) = $t->waitfor('/\>/'); - -# -# Do a portshow on the port and look for the DISABLED string to verify success -# - -$t->print("show port $opt_n"); -($text, $match) = $t->waitfor('/\>/'); - -if (!((($opt_o =~ /disable/i) && ($text =~ /AdminState\ *Offline/i)) || - (($opt_o =~ /enable/i) && ($text =~ /AdminState\ *Online/i)))) -{ - # Get out of admin mode before failing - $t->print("admin end"); - $t->waitfor('/\>/'); - fail "failed: could not change state to $opt_o\n"; -} - - -print "success: $opt_o $opt_n\n" unless defined $opt_q; -$t->print("admin end"); -$t->waitfor('/\>/'); -$t->print("quit"); - -exit 0; - -sub get_options_stdin -{ - my $opt; - my $line = 0; - while( defined($in = <>) ) - { - $_ = $in; - chomp; - - # strip leading and trailing whitespace - s/^\s*//; - s/\s*$//; - - # skip comments - next if /^#/; - - $line+=1; - $opt=$_; - next unless $opt; - - ($name,$val)=split /\s*=\s*/, $opt; - - if ( $name eq "" ) - { - print STDERR "parse error: illegal name in option $line\n"; - exit 2; - } - - # DO NOTHING -- this field is used by fenced - elsif ($name eq "agent" ) { } - - elsif ($name eq "ipaddr" ) - { - $opt_a = $val; - } - elsif ($name eq "login" ) - { - $opt_l = $val; - } - - elsif ($name eq "option" ) - { - $opt_o = $val; - } - elsif ($name eq "passwd" ) - { - $opt_p = $val; - } - elsif ($name eq "passwd_script" ) - { - $opt_S = $val; - } - elsif ($name eq "port" ) - { - $opt_n = $val; - } - - # FIXME should we do more error checking? - # Excess name/vals will be eaten for now - else - { - fail "parse error: unknown option \"$opt\""; - } - } -} diff --git a/fence/agents/sanbox2/fence_sanbox2.py b/fence/agents/sanbox2/fence_sanbox2.py new file mode 100644 index 0000000..7e7c9b3 --- /dev/null +++ b/fence/agents/sanbox2/fence_sanbox2.py @@ -0,0 +1,123 @@ +#!/usr/bin/python + +##### +## +## The Following Agent Has Been Tested On: +## +## Version Firmware +## +-----------------+---------------------------+ +##### + +import sys, re, pexpect +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("show port " + options["-n"] + "\n") + conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + except pexpect.EOF: + fail(EC_CONNECTION_LOST) + except pexpect.TIMEOUT: + try: + conn.send("admin end\n") + conn.send("exit\n") + 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"]] + + try: + conn.send("set port " + options["-n"] + " state " + action + "\n") + conn.log_expect(options, options["-c"], POWER_TIMEOUT) + except pexpect.EOF: + fail(EC_CONNECTION_LOST) + except pexpect.TIMEOUT: + try: + conn.send("admin end\n") + conn.send("exit\n") + conn.close() + except: + pass + fail(EC_TIMED_OUT) + + try: + conn.send("set port " + options["-n"] + " state " + action + "\n") + conn.log_expect(options, options["-c"], POWER_TIMEOUT) + except pexpect.EOF: + fail(EC_CONNECTION_LOST) + except pexpect.TIMEOUT: + try: + conn.send("admin end\n") + conn.send("exit\n") + conn.close() + except: + pass + fail(EC_TIMED_OUT) + +def main(): + device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", + "io_fencing", "ipaddr", "login", "passwd", "passwd_script", + "cmd_prompt", "port", "login_eol_lf" ] + + options = check_input(device_opt, process_input(device_opt)) + + ## + ## Fence agent specific defaults + ##### + if 0 == options.has_key("-c"): + options["-c"] = [ " #> " ] + + ## + ## Operate the fencing device + ## + conn = fence_login(options) + + conn.send("admin start\n") + conn.log_expect(options, options["-c"], 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) + + fence_action(conn, options, set_power_status, get_power_status) + + ## + ## Logout from system + ###### + try: + conn.send("admin end\n") + conn.send("exit\n") + conn.close() + except exceptions.OSError: + pass + except pexpect.ExceptionPexpect: + pass + +if __name__ == "__main__": + main()
1
0
0
0
cluster: RHEL55 - fence_sanbox2: Really add new fence agent + new option login_eol_lf
by Marek Grác
09 Oct '09
09 Oct '09
Gitweb:
http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=a8…
Commit: a8b3ef06aedef9e05c3aef62448233ac993e617a Parent: 819956029c9328a3169ba6cb378b4be16088854b Author: Marek 'marx' Grac <mgrac(a)redhat.com> AuthorDate: Fri Oct 9 12:38:01 2009 +0200 Committer: Marek 'marx' Grac <mgrac(a)redhat.com> CommitterDate: Fri Oct 9 12:38:01 2009 +0200 fence_sanbox2: Really add new fence agent + new option login_eol_lf I forgot to add fence agent in previous patch :( This option is used for login method using telnet. By default most of the fence agents work with username\r\n but on some devices (e.g. HP iLO MP, sanbox2) it is interpreted as there is empty password. [from STABLE3 - 819956029c9328a3169ba6cb378b4be16088854b] --- fence/agents/lib/fencing.py.py | 14 +++- fence/agents/sanbox2/fence_sanbox2.py | 154 +++++++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+), 2 deletions(-) diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py index ca9fb4b..471e7e2 100644 --- a/fence/agents/lib/fencing.py.py +++ b/fence/agents/lib/fencing.py.py @@ -138,6 +138,11 @@ all_opt = { "longopt" : "ribcl-version", "help" : "-r, --ribcl-version=<version> Force ribcl version to use", "order" : 1 }, + "login_eol_lf" : { + "getopt" : "", + "help" : "", + "order" : 1 + }, "cmd_prompt" : { "getopt" : "c:", "longopt" : "command-prompt", @@ -575,6 +580,11 @@ def fence_login(options): if (options.has_key("-4")): force_ipvx="-4 " + if (options["device_opt"].count("login_eol_lf")): + login_eol = "\n" + else: + login_eol = "\r\n" + try: re_login = re.compile("(login: )|(Login Name: )|(username: )|(User Name :)", re.IGNORECASE) re_pass = re.compile("password", re.IGNORECASE) @@ -614,9 +624,9 @@ def fence_login(options): conn.send("set binary\n") conn.send("open %s -%s\n"%(options["-a"], options["-u"])) conn.log_expect(options, re_login, LOGIN_TIMEOUT) - conn.send(options["-l"]+"\r\n") + conn.send(options["-l"] + login_eol) conn.log_expect(options, re_pass, SHELL_TIMEOUT) - conn.send(options["-p"]+"\r\n") + conn.send(options["-p"] + login_eol) conn.log_expect(options, options["-c"], SHELL_TIMEOUT) except pexpect.EOF: fail(EC_LOGIN_DENIED) diff --git a/fence/agents/sanbox2/fence_sanbox2.py b/fence/agents/sanbox2/fence_sanbox2.py new file mode 100644 index 0000000..54122a5 --- /dev/null +++ b/fence/agents/sanbox2/fence_sanbox2.py @@ -0,0 +1,154 @@ +#!/usr/bin/python + +##### +## +## The Following Agent Has Been Tested On: +## +## Version Firmware +## +-----------------+---------------------------+ +##### + +import sys, re, pexpect +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("show port " + options["-n"] + "\n") + conn.log_expect(options, options["-c"], SHELL_TIMEOUT) + except pexpect.EOF: + fail(EC_CONNECTION_LOST) + except pexpect.TIMEOUT: + try: + conn.send("admin end\n") + conn.send("exit\n") + 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"]] + + try: + conn.send("set port " + options["-n"] + " state " + action + "\n") + conn.log_expect(options, options["-c"], POWER_TIMEOUT) + except pexpect.EOF: + fail(EC_CONNECTION_LOST) + except pexpect.TIMEOUT: + try: + conn.send("admin end\n") + conn.send("exit\n") + conn.close() + except: + pass + fail(EC_TIMED_OUT) + + try: + conn.send("set port " + options["-n"] + " state " + action + "\n") + conn.log_expect(options, options["-c"], POWER_TIMEOUT) + except pexpect.EOF: + fail(EC_CONNECTION_LOST) + except pexpect.TIMEOUT: + try: + conn.send("admin end\n") + conn.send("exit\n") + conn.close() + except: + pass + fail(EC_TIMED_OUT) + +def get_list_devices(conn, options): + outlets = { } + + try: + conn.send("show port" + "\n") + conn.log_expect(options, options["-c"], 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.EOF: + fail(EC_CONNECTION_LOST) + except pexpect.TIMEOUT: + try: + conn.send("admin end\n") + conn.send("exit\n") + conn.close() + except: + pass + fail(EC_TIMED_OUT) + + return outlets + +def main(): + device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", + "io_fencing", "ipaddr", "login", "passwd", "passwd_script", + "cmd_prompt", "port", "ipport", "login_eol_lf", "separator" ] + + atexit.register(atexit_handler) + + options = check_input(device_opt, process_input(device_opt)) + + ## + ## Fence agent specific defaults + ##### + if 0 == options.has_key("-c"): + options["-c"] = [ " #> " ] + + ## + ## Operate the fencing device + ## + conn = fence_login(options) + + conn.send("admin start\n") + conn.log_expect(options, options["-c"], 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) + + fence_action(conn, options, set_power_status, get_power_status, get_list_devices) + + ## + ## Logout from system + ###### + try: + conn.send("admin end\n") + conn.send("exit\n") + conn.close() + except exceptions.OSError: + pass + except pexpect.ExceptionPexpect: + pass + +if __name__ == "__main__": + main()
1
0
0
0
fence-agents: master - fence_sanbox2: Typo correction
by Marek Grác
09 Oct '09
09 Oct '09
Gitweb:
http://git.fedorahosted.org/git/fence-agents.git?p=fence-agents.git;a=commi…
Commit: 6a34bd9d7f3f68f26f06f8d57eea6135b6c6b6d6 Parent: a456efcf471711f20dd80db5150da7f0ecf937c7 Author: Marek 'marx' Grac <mgrac(a)redhat.com> AuthorDate: Fri Oct 9 12:34:53 2009 +0200 Committer: Marek 'marx' Grac <mgrac(a)redhat.com> CommitterDate: Fri Oct 9 12:34:53 2009 +0200 fence_sanbox2: Typo correction --- fence/agents/sanbox2/fence_sanbox2.py | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/fence/agents/sanbox2/fence_sanbox2.py b/fence/agents/sanbox2/fence_sanbox2.py index d7b5335..0b048a3 100644 --- a/fence/agents/sanbox2/fence_sanbox2.py +++ b/fence/agents/sanbox2/fence_sanbox2.py @@ -75,6 +75,7 @@ def set_power_status(conn, options): conn.send("exit\n") conn.close() except: + pass fail(EC_TIMED_OUT) def get_list_devices(conn, options):
1
0
0
0
cluster: STABLE3 - fence_sanbox2: Typo correction
by Marek Grác
09 Oct '09
09 Oct '09
Gitweb:
http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=9d…
Commit: 9de7fcd3dbefbfe56a317dc6fe94836fae9850da Parent: 799af64234c8b4ac6858442abbec3b5ed9a8ad65 Author: Marek 'marx' Grac <mgrac(a)redhat.com> AuthorDate: Fri Oct 9 12:32:44 2009 +0200 Committer: Marek 'marx' Grac <mgrac(a)redhat.com> CommitterDate: Fri Oct 9 12:32:44 2009 +0200 fence_sanbox2: Typo correction --- fence/agents/sanbox2/fence_sanbox2.py | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/fence/agents/sanbox2/fence_sanbox2.py b/fence/agents/sanbox2/fence_sanbox2.py index d7b5335..0b048a3 100644 --- a/fence/agents/sanbox2/fence_sanbox2.py +++ b/fence/agents/sanbox2/fence_sanbox2.py @@ -75,6 +75,7 @@ def set_power_status(conn, options): conn.send("exit\n") conn.close() except: + pass fail(EC_TIMED_OUT) def get_list_devices(conn, options):
1
0
0
0
cluster: RHEL55 - fence_sanbox2: Re-implementation based on fencing library
by Marek Grác
09 Oct '09
09 Oct '09
Gitweb:
http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=81…
Commit: 819956029c9328a3169ba6cb378b4be16088854b Parent: ec11819220efbdb9e0bf395a92ea50294b5b21bc Author: Marek 'marx' Grac <mgrac(a)redhat.com> AuthorDate: Fri Oct 9 12:12:04 2009 +0200 Committer: Marek 'marx' Grac <mgrac(a)redhat.com> CommitterDate: Fri Oct 9 12:12:04 2009 +0200 fence_sanbox2: Re-implementation based on fencing library Fence agent is based on fencing library, operatio 'list' is supported too Resolves: bz#512947 --- fence/agents/lib/fencing.py.py | 33 ++++- fence/agents/sanbox2/Makefile | 2 +- fence/agents/sanbox2/fence_sanbox2.pl | 263 --------------------------------- 3 files changed, 28 insertions(+), 270 deletions(-) diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py index 79cf7e9..ca9fb4b 100644 --- a/fence/agents/lib/fencing.py.py +++ b/fence/agents/lib/fencing.py.py @@ -70,6 +70,14 @@ all_opt = { "longopt" : "action", "help" : "-o, --action=<action> Action: status, reboot (default), off or on", "order" : 1 }, + "io_fencing" : { + "getopt" : "o:", + "longopt" : "action", + "help" : "-o, --action=<action> Action: status, enable or disable", + "required" : "1", + "shortdesc" : "Fencing Action", + "default" : "disable", + "order" : 1 }, "ipaddr" : { "getopt" : "a:", "longopt" : "ip", @@ -369,6 +377,8 @@ def process_input(avail_opt): name = "ipaddr" elif name == "modulename": name = "module_name" + elif name == "action" and 1 == avail_opt.count("io_fencing"): + name = "io_fencing" ## ###### @@ -404,15 +414,20 @@ def check_input(device_opt, opt): else: options["log"] = LOG_MODE_QUIET - if 0 == options.has_key("-o"): - options["-o"] = "reboot" - # Convert action to lowercase options["-o"]=options["-o"].lower() - if 0 == ["on", "off", "reboot", "status", "list", "monitor"].count(options["-o"].lower()): - fail_usage("Failed: Unrecognised action '" + options["-o"] + "'") - + if 0 == device_opt.count("io_fencing"): + if 0 == options.has_key("-o"): + options["-o"] = "reboot" + if 0 == ["on", "off", "reboot", "status", "list", "monitor"].count(options["-o"].lower()): + fail_usage("Failed: Unrecognised action '" + options["-o"] + "'") + else: + if 0 == options.has_key("-o"): + options["-o"] = "disable" + if 0 == ["enable", "disable", "status", "list", "monitor"].count(options["-o"].lower()): + fail_usage("Failed: Unrecognised action '" + options["-o"] + "'") + if (0 == options.has_key("-l")) and device_opt.count("login") and (device_opt.count("no_login") == 0): fail_usage("Failed: You have to set login name") @@ -511,6 +526,12 @@ def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None if status != "on" and status != "off": fail(EC_STATUS) + + if options["-o"] == "enable": + options["-o"] = "on" + if options["-o"] == "disable": + options["-o"] = "off" + if options["-o"] == "on": if status == "on": print "Success: Already ON" diff --git a/fence/agents/sanbox2/Makefile b/fence/agents/sanbox2/Makefile index 31b4677..9428344 100644 --- a/fence/agents/sanbox2/Makefile +++ b/fence/agents/sanbox2/Makefile @@ -11,7 +11,7 @@ ############################################################################### ############################################################################### -SOURCE= fence_sanbox2.pl +SOURCE= fence_sanbox2.py TARGET= fence_sanbox2 top_srcdir=../.. diff --git a/fence/agents/sanbox2/fence_sanbox2.pl b/fence/agents/sanbox2/fence_sanbox2.pl deleted file mode 100644 index b93f8da..0000000 --- a/fence/agents/sanbox2/fence_sanbox2.pl +++ /dev/null @@ -1,263 +0,0 @@ -#!/usr/bin/perl - -############################################################################### -############################################################################### -## -## Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. -## Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. -## -## This copyrighted material is made available to anyone wishing to use, -## modify, copy, or redistribute it subject to the terms and conditions -## of the GNU General Public License v.2. -## -############################################################################### -############################################################################### - -use Getopt::Std; -use Net::Telnet (); - -my $ME = $0; - -END { - defined fileno STDOUT or return; - close STDOUT and return; - warn "$ME: failed to close standard output: $!\n"; - $? ||= 1; -} - -# Get the program name from $0 and strip directory names -$_=$0; -s/.*\///; -my $pname = $_; - -$opt_o = 'disable'; # Default fence action - -# WARNING!! Do not add code bewteen "#BEGIN_VERSION_GENERATION" and -# "#END_VERSION_GENERATION" It is generated by the Makefile - -#BEGIN_VERSION_GENERATION -$FENCE_RELEASE_NAME=""; -$REDHAT_COPYRIGHT=""; -$BUILD_DATE=""; -#END_VERSION_GENERATION - - -sub usage -{ - print "Usage:\n"; - print "\n"; - print "$pname [options]\n"; - print "\n"; - print "Options:\n"; - print " -a <ip> IP address or hostname of switch\n"; - print " -h usage\n"; - print " -l <name> Login name\n"; - print " -n <num> Port number to disable\n"; - print " -o <string> Action: disable (default) or enable\n"; - print " -p <string> Password for login\n"; - print " -S <path> Script to run to retrieve login password\n"; - print " -q quiet mode\n"; - print " -V version\n"; - - exit 0; -} - -sub fail -{ - ($msg) = @_; - print $msg."\n" unless defined $opt_q; - $t->close if defined $t; - exit 1; -} - -sub fail_usage -{ - ($msg)=@_; - print STDERR $msg."\n" if $msg; - print STDERR "Please use '-h' for usage.\n"; - exit 1; -} - -sub version -{ - print "$pname $FENCE_RELEASE_NAME $BUILD_DATE\n"; - print "$REDHAT_COPYRIGHT\n" if ( $REDHAT_COPYRIGHT ); - - exit 0; -} - - -if (@ARGV > 0) { - getopts("a:hl:n:o:p:S:qV") || fail_usage ; - - usage if defined $opt_h; - version if defined $opt_V; - - fail_usage "Unknown parameter." if (@ARGV > 0); - - fail_usage "No '-a' flag specified." unless defined $opt_a; - fail_usage "No '-n' flag specified." unless defined $opt_n; - fail_usage "No '-l' flag specified." unless defined $opt_l; - - if (defined $opt_S) { - $pwd_script_out = `$opt_S`; - chomp($pwd_script_out); - if ($pwd_script_out) { - $opt_p = $pwd_script_out; - } - } - - fail_usage "No '-p' or '-S' flag specified." unless defined $opt_p; - fail_usage "Unrecognised action '$opt_o' for '-o' flag" - unless $opt_o =~ /^(disable|enable)$/i; - -} else { - get_options_stdin(); - - fail "failed: no IP address" unless defined $opt_a; - fail "failed: no plug number" unless defined $opt_n; - fail "failed: no login name" unless defined $opt_l; - - if (defined $opt_S) { - $pwd_script_out = `$opt_S`; - chomp($pwd_script_out); - if ($pwd_script_out) { - $opt_p = $pwd_script_out; - } - } - - fail "failed: no password" unless defined $opt_p; - fail "failed: unrecognised action: $opt_o" - unless $opt_o =~ /^(disable|enable)$/i; -} - - if ( $opt_o =~ /^disable$/i ) -{ - $command = "set port $opt_n state offline"; -} -elsif ( $opt_o =~ /^enable$/i ) -{ - $command = "set port $opt_n state online"; -} - -# -# Set up and log in -# - -$t = new Net::Telnet; - -$t->open($opt_a); - -$t->waitfor('/login:/'); - -$t->print($opt_l); - -$t->waitfor('/assword:/'); - -$t->print($opt_p); - -$t->waitfor('/\>/'); - -# -# Go to admin mode and check if we're really in it -# -$t->print ("admin start"); -($text, $match) = $t->waitfor('/\>/'); -if ($text =~ /Switch is already in Admin Mode/i) { - fail "failed: parallel telnet session\n"; -}; - -# -# Do the command -# -$t->print($command); -print "$command \n"; - -# -# Assume here that the word "error" will appear after errors (bad assumption! see next check) -# - -($text, $match) = $t->waitfor('/\>/'); - -# -# Do a portshow on the port and look for the DISABLED string to verify success -# - -$t->print("show port $opt_n"); -($text, $match) = $t->waitfor('/\>/'); - -if (!((($opt_o =~ /disable/i) && ($text =~ /AdminState\ *Offline/i)) || - (($opt_o =~ /enable/i) && ($text =~ /AdminState\ *Online/i)))) -{ - # Get out of admin mode before failing - $t->print("admin end"); - $t->waitfor('/\>/'); - fail "failed: could not change state to $opt_o\n"; -} - - -print "success: $opt_o $opt_n\n" unless defined $opt_q; -$t->print("admin end"); -$t->waitfor('/\>/'); -$t->print("quit"); - -exit 0; - -sub get_options_stdin -{ - my $opt; - my $line = 0; - while( defined($in = <>) ) - { - $_ = $in; - chomp; - - # strip leading and trailing whitespace - s/^\s*//; - s/\s*$//; - - # skip comments - next if /^#/; - - $line+=1; - $opt=$_; - next unless $opt; - - ($name,$val)=split /\s*=\s*/, $opt; - - if ( $name eq "" ) - { - print STDERR "parse error: illegal name in option $line\n"; - exit 2; - } - - # DO NOTHING -- this field is used by fenced - elsif ($name eq "agent" ) { } - - elsif ($name eq "ipaddr" ) - { - $opt_a = $val; - } - elsif ($name eq "login" ) - { - $opt_l = $val; - } - - elsif ($name eq "option" ) - { - $opt_o = $val; - } - elsif ($name eq "passwd" ) - { - $opt_p = $val; - } - elsif ($name eq "passwd_script" ) - { - $opt_S = $val; - } - elsif ($name eq "port" ) - { - $opt_n = $val; - } - } -}
1
0
0
0
cluster: STABLE3 - fence_sanbox2: Support operation 'list' for sanbox2
by Marek Grác
09 Oct '09
09 Oct '09
Gitweb:
http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=79…
Commit: 799af64234c8b4ac6858442abbec3b5ed9a8ad65 Parent: ad607942dbb7634567bef6d8ce4c69aeb2603e2a Author: Marek 'marx' Grac <mgrac(a)redhat.com> AuthorDate: Fri Oct 9 11:55:00 2009 +0200 Committer: Marek 'marx' Grac <mgrac(a)redhat.com> CommitterDate: Fri Oct 9 11:55:00 2009 +0200 fence_sanbox2: Support operation 'list' for sanbox2 --- fence/agents/sanbox2/fence_sanbox2.py | 50 +++++++++++++++++++++++++++++++- 1 files changed, 48 insertions(+), 2 deletions(-) diff --git a/fence/agents/sanbox2/fence_sanbox2.py b/fence/agents/sanbox2/fence_sanbox2.py index 79d1f02..d7b5335 100644 --- a/fence/agents/sanbox2/fence_sanbox2.py +++ b/fence/agents/sanbox2/fence_sanbox2.py @@ -29,6 +29,12 @@ def get_power_status(conn, options): except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: + try: + conn.send("admin end\n") + conn.send("exit\n") + 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) @@ -50,6 +56,12 @@ def set_power_status(conn, options): except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: + try: + conn.send("admin end\n") + conn.send("exit\n") + conn.close() + except: + pass fail(EC_TIMED_OUT) try: @@ -58,12 +70,46 @@ def set_power_status(conn, options): except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: + try: + conn.send("admin end\n") + conn.send("exit\n") + conn.close() + except: fail(EC_TIMED_OUT) +def get_list_devices(conn, options): + outlets = { } + + try: + conn.send("show port" + "\n") + conn.log_expect(options, options["-c"], 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.EOF: + fail(EC_CONNECTION_LOST) + except pexpect.TIMEOUT: + try: + conn.send("admin end\n") + conn.send("exit\n") + conn.close() + except: + pass + fail(EC_TIMED_OUT) + + return outlets + def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "io_fencing", "ipaddr", "login", "passwd", "passwd_script", - "cmd_prompt", "port", "ipport", "login_eol_lf" ] + "cmd_prompt", "port", "ipport", "login_eol_lf", "separator" ] atexit.register(atexit_handler) @@ -91,7 +137,7 @@ def main(): sys.stderr.write("Failed: Unable to switch to admin section\n") sys.exit(EC_GENERIC_ERROR) - fence_action(conn, options, set_power_status, get_power_status) + fence_action(conn, options, set_power_status, get_power_status, get_list_devices) ## ## Logout from system
1
0
0
0
fence-agents: master - fence_sanbox2: Support operation 'list' for sanbox2
by Marek Grác
09 Oct '09
09 Oct '09
Gitweb:
http://git.fedorahosted.org/git/fence-agents.git?p=fence-agents.git;a=commi…
Commit: a456efcf471711f20dd80db5150da7f0ecf937c7 Parent: f534acd99ad0bacdb85a1580d5c3c25997927957 Author: Marek 'marx' Grac <mgrac(a)redhat.com> AuthorDate: Fri Oct 9 11:46:33 2009 +0200 Committer: Marek 'marx' Grac <mgrac(a)redhat.com> CommitterDate: Fri Oct 9 11:48:41 2009 +0200 fence_sanbox2: Support operation 'list' for sanbox2 --- fence/agents/sanbox2/fence_sanbox2.py | 50 +++++++++++++++++++++++++++++++- 1 files changed, 48 insertions(+), 2 deletions(-) diff --git a/fence/agents/sanbox2/fence_sanbox2.py b/fence/agents/sanbox2/fence_sanbox2.py index 79d1f02..d7b5335 100644 --- a/fence/agents/sanbox2/fence_sanbox2.py +++ b/fence/agents/sanbox2/fence_sanbox2.py @@ -29,6 +29,12 @@ def get_power_status(conn, options): except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: + try: + conn.send("admin end\n") + conn.send("exit\n") + 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) @@ -50,6 +56,12 @@ def set_power_status(conn, options): except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: + try: + conn.send("admin end\n") + conn.send("exit\n") + conn.close() + except: + pass fail(EC_TIMED_OUT) try: @@ -58,12 +70,46 @@ def set_power_status(conn, options): except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: + try: + conn.send("admin end\n") + conn.send("exit\n") + conn.close() + except: fail(EC_TIMED_OUT) +def get_list_devices(conn, options): + outlets = { } + + try: + conn.send("show port" + "\n") + conn.log_expect(options, options["-c"], 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.EOF: + fail(EC_CONNECTION_LOST) + except pexpect.TIMEOUT: + try: + conn.send("admin end\n") + conn.send("exit\n") + conn.close() + except: + pass + fail(EC_TIMED_OUT) + + return outlets + def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "io_fencing", "ipaddr", "login", "passwd", "passwd_script", - "cmd_prompt", "port", "ipport", "login_eol_lf" ] + "cmd_prompt", "port", "ipport", "login_eol_lf", "separator" ] atexit.register(atexit_handler) @@ -91,7 +137,7 @@ def main(): sys.stderr.write("Failed: Unable to switch to admin section\n") sys.exit(EC_GENERIC_ERROR) - fence_action(conn, options, set_power_status, get_power_status) + fence_action(conn, options, set_power_status, get_power_status, get_list_devices) ## ## Logout from system
1
0
0
0
cluster: STABLE3 - fencing_snmp: Fix exception caused by older commit
by Jan Friesse
09 Oct '09
09 Oct '09
Gitweb:
http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=ad…
Commit: ad607942dbb7634567bef6d8ce4c69aeb2603e2a Parent: 31b667749ef522d8d17472365231f223951474c6 Author: Jan Friesse <jfriesse(a)redhat.com> AuthorDate: Fri Oct 9 10:41:52 2009 +0200 Committer: Jan Friesse <jfriesse(a)redhat.com> CommitterDate: Fri Oct 9 11:13:15 2009 +0200 fencing_snmp: Fix exception caused by older commit This patch fixes exception in FA caused by change in fencing library: "fence agents: Option for setting port for telnet/ssh/ssl used by fence agent" RHBZ#527844 --- fence/agents/apc_snmp/fence_apc_snmp.py | 1 + fence/agents/cisco_mds/fence_cisco_mds.py | 1 + fence/agents/ibmblade/fence_ibmblade.py | 1 + fence/agents/ifmib/fence_ifmib.py | 2 ++ fence/agents/intelmodular/fence_intelmodular.py | 2 ++ fence/agents/lib/fencing_snmp.py.py | 7 ++++++- 6 files changed, 13 insertions(+), 1 deletions(-) diff --git a/fence/agents/apc_snmp/fence_apc_snmp.py b/fence/agents/apc_snmp/fence_apc_snmp.py index 91331b5..e66a6b0 100644 --- a/fence/agents/apc_snmp/fence_apc_snmp.py +++ b/fence/agents/apc_snmp/fence_apc_snmp.py @@ -173,6 +173,7 @@ def main(): atexit.register(atexit_handler) + snmp_define_defaults () apc_snmp_define_defaults() options=check_input(device_opt,process_input(device_opt)) diff --git a/fence/agents/cisco_mds/fence_cisco_mds.py b/fence/agents/cisco_mds/fence_cisco_mds.py index 67948e6..944e593 100644 --- a/fence/agents/cisco_mds/fence_cisco_mds.py +++ b/fence/agents/cisco_mds/fence_cisco_mds.py @@ -90,6 +90,7 @@ def main(): atexit.register(atexit_handler) + snmp_define_defaults () options=process_input(device_opt) # Emulate enable/disable functionality diff --git a/fence/agents/ibmblade/fence_ibmblade.py b/fence/agents/ibmblade/fence_ibmblade.py index 7532221..700437d 100644 --- a/fence/agents/ibmblade/fence_ibmblade.py +++ b/fence/agents/ibmblade/fence_ibmblade.py @@ -65,6 +65,7 @@ def main(): atexit.register(atexit_handler) + snmp_define_defaults () ibmblade_define_defaults() options=check_input(device_opt,process_input(device_opt)) diff --git a/fence/agents/ifmib/fence_ifmib.py b/fence/agents/ifmib/fence_ifmib.py index a6c452d..544d236 100644 --- a/fence/agents/ifmib/fence_ifmib.py +++ b/fence/agents/ifmib/fence_ifmib.py @@ -110,6 +110,8 @@ def main(): atexit.register(atexit_handler) + snmp_define_defaults () + options=process_input(device_opt) # Emulate enable/disable functionality diff --git a/fence/agents/intelmodular/fence_intelmodular.py b/fence/agents/intelmodular/fence_intelmodular.py index 492bbc5..4969772 100644 --- a/fence/agents/intelmodular/fence_intelmodular.py +++ b/fence/agents/intelmodular/fence_intelmodular.py @@ -72,6 +72,8 @@ def main(): atexit.register(atexit_handler) + snmp_define_defaults () + options=check_input(device_opt,process_input(device_opt)) show_docs(options) diff --git a/fence/agents/lib/fencing_snmp.py.py b/fence/agents/lib/fencing_snmp.py.py index 146f304..1292b5b 100644 --- a/fence/agents/lib/fencing_snmp.py.py +++ b/fence/agents/lib/fencing_snmp.py.py @@ -12,6 +12,11 @@ REDHAT_COPYRIGHT = "" BUILD_DATE = "" #END_VERSION_GENERATION +# Fix for RHBZ#527844 +def snmp_define_defaults (): + all_opt["udpport"]["default"]="161" + all_opt["ipport"]["default"]="161" + class FencingSnmp: def __init__(self,options): self.options=options @@ -68,7 +73,7 @@ class FencingSnmp: force_ipvx="udp:" cmd+=" '%s%s%s'"%(force_ipvx, self.quote_for_run(self.options["-a"]), - self.options.has_key("-u") and self.quote_for_run(":"+self.options["-u"]) or "") + self.options.has_key("-u") and self.quote_for_run(":" + str (self.options["-u"])) or "") return cmd def run_command(self,command,additional_timemout=0):
1
0
0
0
← Newer
1
...
8
9
10
11
12
13
14
15
16
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Results per page:
10
25
50
100
200