Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=8015ec16e... Commit: 8015ec16e254bdd43fac75c6f56fe4dc1ba8031d Parent: 2398c9b5741eb5e5191afda535b27f781ac263a1 Author: Marek 'marx' Grac mgrac@redhat.com AuthorDate: Thu Jun 27 13:05:26 2013 +0200 Committer: Marek 'marx' Grac mgrac@redhat.com CommitterDate: Thu Jun 27 13:05:26 2013 +0200
fence_apc: Add support for firmware 5.x
New major version of firmware is now supported.
Resolves: rhbz#886614 --- fence/agents/apc/fence_apc.py | 56 +++++++++++++++++++++++++++++++++++------ 1 files changed, 48 insertions(+), 8 deletions(-)
diff --git a/fence/agents/apc/fence_apc.py b/fence/agents/apc/fence_apc.py index 61463d0..d1c71b4 100644 --- a/fence/agents/apc/fence_apc.py +++ b/fence/agents/apc/fence_apc.py @@ -68,7 +68,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, [ "Press <ENTER>" ] + options["-c"], int(options["-Y"])) lines = conn.before.split("\n"); show_re = re.compile('(^|\x0D)\s*(\d+)- (.*?)\s+(ON|OFF)\s*') for x in lines: @@ -76,7 +76,7 @@ def get_power_status(conn, options): if (res != None): outlets[res.group(2)] = (res.group(3), res.group(4)) conn.send_eol("") - if exp_result == 0: + if exp_result != 0: break conn.send(chr(03)) conn.log_expect(options, "- Logout", int(options["-Y"])) @@ -151,7 +151,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 0 == conn.log_expect(options, [ "Press <ENTER>" ] + options["-c"], int(options["-Y"])): conn.send_eol("") conn.send_eol(options["-n"]+"") conn.log_expect(options, options["-c"], int(options["-Y"])) @@ -180,16 +180,50 @@ def set_power_status(conn, options): fail(EC_CONNECTION_LOST) 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["--command-prompt"], int(options["--shell-timeout"])) + 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["--action"]) == 1: + return outlets + else: + try: + (_, status) = outlets[options["--plug"]] + 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["--plug"]) + conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"]))
def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", "secure", "port", "identity_file", "switch", "test", "separator", - "inet4_only", "inet6_only", "ipport", + "inet4_only", "inet6_only", "ipport", "cmd_prompt", "power_timeout", "shell_timeout", "login_timeout", "power_wait" ]
atexit.register(atexit_handler)
+ all_opt["cmd_prompt"]["default"] = [ "\n>", "\napc>" ] options = check_input(device_opt, process_input(device_opt))
## @@ -197,9 +231,6 @@ def main(): ##### options["ssh_options"] = "-1 -c blowfish"
- if 0 == options.has_key("-c"): - options["-c"] = "\n>" - docs = { } docs["shortdesc"] = "Fence agent for APC over telnet/ssh" docs["longdesc"] = "fence_apc is an I/O Fencing agent \ @@ -220,7 +251,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