fence-agents/0001-fence_brocade-Add-support-for-list-action.patch

79 lines
2.6 KiB
Diff
Raw Normal View History

2014-09-16 09:48:32 +02:00
From 98236c1c0f0f3b9d6def701e5e9cc67f35649441 Mon Sep 17 00:00:00 2001
From: Marek 'marx' Grac <mgrac@redhat.com>
Date: Tue, 1 Jul 2014 15:25:45 +0200
Subject: [PATCH 01/11] fence_brocade: Add support for 'list' action
---
fence/agents/brocade/fence_brocade.py | 41 +++++++++++++++++++----------------
1 file changed, 22 insertions(+), 19 deletions(-)
diff --git a/fence/agents/brocade/fence_brocade.py b/fence/agents/brocade/fence_brocade.py
index f935280..3e5dd93 100644
--- a/fence/agents/brocade/fence_brocade.py
+++ b/fence/agents/brocade/fence_brocade.py
@@ -12,24 +12,6 @@ REDHAT_COPYRIGHT=""
BUILD_DATE="March, 20013"
#END_VERSION_GENERATION
-def get_power_status(conn, options):
- conn.send_eol("portCfgShow " + options["--plug"])
-
- conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
-
- show_re = re.compile(r'^\s*Persistent Disable\s*(ON|OFF)\s*$', re.IGNORECASE)
- lines = conn.before.split("\n")
-
- for line in lines:
- res = show_re.search(line)
- if res != None:
- # We queried if it is disabled, so we have to negate answer
- if res.group(1) == "ON":
- return "off"
- else:
- return "on"
-
- fail(EC_STATUS)
def set_power_status(conn, options):
action = {
'on' : "portCfgPersistentEnable",
@@ -39,6 +21,27 @@ def set_power_status(conn, options):
conn.send_eol(action + " " + options["--plug"])
conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"]))
+def get_power_status(conn, options):
+ line_re = re.compile(r'=========', re.IGNORECASE)
+ outlets = {}
+ in_index = False
+
+ conn.send_eol("switchshow")
+ conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"]))
+ for line in str(conn.before).split("\n"):
+ if line_re.search(line):
+ in_index = True
+ elif in_index and line.lstrip()[0].isdigit():
+ tokens = line.lstrip().split()
+ status = "off" if len(tokens) > 7 and tokens[7] == "Disabled" else "on"
+ outlets[tokens[0]] = ("", status)
+
+ if options["--action"] == "status":
+ (_, status) = outlets[options["--plug"]]
+ return status
+ else:
+ return outlets
+
def main():
device_opt = ["ipaddr", "login", "passwd", "cmd_prompt", "secure", "port", "fabric_fencing"]
@@ -66,7 +69,7 @@ FC switch needs to be enabled. This can be done by running fence_brocade and spe
## Operate the fencing device
####
conn = fence_login(options)
- result = fence_action(conn, options, set_power_status, get_power_status, None)
+ result = fence_action(conn, options, set_power_status, get_power_status, get_power_status)
fence_logout(conn, "exit")
sys.exit(result)
--
1.8.4.5