Gitweb: http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=be4ffa1bed2332... Commit: be4ffa1bed23328a36b182b69c1c355abb7e16af Parent: d45ceaa6e243733f801ce6aa8519d741a1801e34 Author: Marek 'marx' Grac mgrac@redhat.com AuthorDate: Mon May 13 14:35:30 2013 +0200 Committer: Marek 'marx' Grac mgrac@redhat.com CommitterDate: Mon May 13 14:35:30 2013 +0200
fencing: Add support for APC with firmware 5.x
Patch is based on a commit https://git.fedorahosted.org/cgit/fence-agents.git/commit/?id=dfff684d59a6c4...
Resolves: rhbz#886612 --- fence/agents/apc/fence_apc.py | 53 +++++++++++++++++++++++++++++++++++++--- fence/agents/lib/fencing.py.py | 15 ++++++++++- 2 files changed, 62 insertions(+), 6 deletions(-)
diff --git a/fence/agents/apc/fence_apc.py b/fence/agents/apc/fence_apc.py index 4125d39..a3a8f01 100755 --- a/fence/agents/apc/fence_apc.py +++ b/fence/agents/apc/fence_apc.py @@ -69,7 +69,7 @@ def get_power_status(conn, options): conn.send_eol(options["-s"]) while True: - exp_result = conn.log_expect(options, [ options["-c"], "Press <ENTER>" ], int(options["-Y"])) + exp_result = conn.log_expect(options, options["-c"] + ["Press <ENTER>" ], int(options["-Y"])) lines = conn.before.split("\n"); show_re = re.compile('(^|\x0D)\s*(\d+)- (.*?)\s+(ON|OFF)\s*') for x in lines: @@ -152,7 +152,7 @@ def set_power_status(conn, options): else: conn.send_eol(options["-s"])
- while 1 == conn.log_expect(options, [ options["-c"], "Press <ENTER>" ], int(options["-Y"])): + while 1 == conn.log_expect(options, options["-c"] + [ "Press <ENTER>" ], int(options["-Y"])): conn.send_eol("") conn.send_eol(options["-n"]+"") conn.log_expect(options, options["-c"], int(options["-Y"])) @@ -182,6 +182,40 @@ def set_power_status(conn, options): except pexpect.TIMEOUT: fail(EC_TIMED_OUT)
+def get_power_status5(conn, options): + exp_result = 0 + outlets = {} + + conn.send_eol("olStatus all") + + exp_result = conn.log_expect(options, options["-c"], int(options["-Y"])) + lines = conn.before.split("\n") + + show_re = re.compile('^\s*(\d+): (.*): (On|Off)\s*$', re.IGNORECASE) + + for x in lines: + res = show_re.search(x) + if (res != None): + outlets[res.group(1)] = (res.group(2), res.group(3)) + + if ["list", "monitor"].count(options["-o"]) == 1: + return outlets + else: + try: + (_, status) = outlets[options["-n"]] + return status.lower().strip() + except KeyError: + fail(EC_STATUS) + +def set_power_status5(conn, options): + action = { + 'on' : "olOn", + 'off': "olOff" + }[options["--action"]] + + conn.send_eol(action + " " + options["-n"]) + conn.log_expect(options, options["-c"], int(options["-g"])) + def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", @@ -199,7 +233,9 @@ def main(): options["ssh_options"] = "-1 -c blowfish"
if 0 == options.has_key("-c"): - options["-c"] = "\n>" + options["-c"] = [ "\n>", "\napc" ] + else: + options["-c"] = [ options["-c"] ]
docs = { } docs["shortdesc"] = "Fence agent for APC over telnet/ssh" @@ -221,7 +257,16 @@ will block any necessary fencing actions." ## Operate the fencing device #### conn = fence_login(options) - result = fence_action(conn, options, set_power_status, get_power_status, get_power_status) + + ## Detect firmware version (ASCII menu vs command-line interface) + ## and continue with proper action + #### + result = -1 + firmware_version = re.compile('\s*v(\d)*.').search(conn.before) + if (firmware_version != None) and (firmware_version.group(1) == "5"): + result = fence_action(conn, options, set_power_status5, get_power_status5, get_power_status5) + else: + result = fence_action(conn, options, set_power_status, get_power_status, get_power_status)
## ## Logout from system diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py index 25a0f7e..d1e43da 100644 --- a/fence/agents/lib/fencing.py.py +++ b/fence/agents/lib/fencing.py.py @@ -870,7 +870,8 @@ def fence_login(options): time.sleep(int(options["-f"]))
try: - re_login = re.compile("(login\s*: )|(Login Name: )|(username: )|(User Name :)", re.IGNORECASE) + re_login_string = "(login\s*: )|(Login Name: )|(username: )|(User Name :)" + re_login = re.compile(re_login_string, re.IGNORECASE) re_pass = re.compile("password", re.IGNORECASE)
if options.has_key("-z"): @@ -957,7 +958,17 @@ def fence_login(options):
try: conn.send_eol(options["-p"]) - conn.log_expect(options, options["-c"], int(options["-Y"])) + + valid_password = conn.log_expect(options, [ re_login_string ] + options["-c"], int(options["-Y"])) + if valid_password == 0: + ## password is invalid or we have to change EOL separator + options["eol"] = "\r" + conn.send_eol("") + conn.send_eol("") + conn.send_eol(options["-l"]) + conn.log_expect(options, re_pass, int(options["-y"])) + conn.send_eol(options["-p"]) + conn.log_expect(options, options["-c"], int(options["-y"])) except KeyError: fail(EC_PASSWORD_MISSING) except pexpect.EOF:
cluster-commits@lists.fedorahosted.org