|
|
d67cb5 |
commit 0b92cea4cb27f248834d77a72266ba5bf69c1d95
|
|
|
d67cb5 |
Author: Marek 'marx' Grac <mgrac@redhat.com>
|
|
|
d67cb5 |
Date: Mon Oct 21 13:50:06 2013 +0200
|
|
|
d67cb5 |
|
|
|
d67cb5 |
fence_wti: Add support for named groups
|
|
|
d67cb5 |
|
|
|
d67cb5 |
On some WTI devices it is possible to name a group of devices by single names (e.g. 1,2 -> server). These
|
|
|
d67cb5 |
groups can be used to operate all these plugs by single command.
|
|
|
d67cb5 |
|
|
|
d67cb5 |
Patch by: Thibat Pouzet
|
|
|
d67cb5 |
|
|
|
d67cb5 |
diff --git a/fence/agents/wti/fence_wti.py b/fence/agents/wti/fence_wti.py
|
|
|
d67cb5 |
index b315061..34967e1 100644
|
|
|
d67cb5 |
--- a/fence/agents/wti/fence_wti.py
|
|
|
d67cb5 |
+++ b/fence/agents/wti/fence_wti.py
|
|
|
d67cb5 |
@@ -21,10 +21,10 @@ REDHAT_COPYRIGHT=""
|
|
|
d67cb5 |
BUILD_DATE="March, 2008"
|
|
|
d67cb5 |
#END_VERSION_GENERATION
|
|
|
d67cb5 |
|
|
|
d67cb5 |
-def get_power_status(conn, options):
|
|
|
d67cb5 |
+def get_listing(conn, options, listing_command):
|
|
|
d67cb5 |
listing = ""
|
|
|
d67cb5 |
|
|
|
d67cb5 |
- conn.send("/S"+"\r\n")
|
|
|
d67cb5 |
+ conn.send(listing_command + "\r\n")
|
|
|
d67cb5 |
|
|
|
d67cb5 |
if isinstance(options["--command-prompt"], list):
|
|
|
d67cb5 |
re_all = list(options["--command-prompt"])
|
|
|
d67cb5 |
@@ -39,7 +39,12 @@ def get_power_status(conn, options):
|
|
|
d67cb5 |
conn.send("\r\n")
|
|
|
d67cb5 |
conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
|
|
|
d67cb5 |
listing += conn.before
|
|
|
d67cb5 |
-
|
|
|
d67cb5 |
+
|
|
|
d67cb5 |
+ return listing
|
|
|
d67cb5 |
+
|
|
|
d67cb5 |
+def get_plug_status(conn, options):
|
|
|
d67cb5 |
+ listing = get_listing(conn, options, "/S")
|
|
|
d67cb5 |
+
|
|
|
d67cb5 |
plug_section = 0
|
|
|
d67cb5 |
plug_index = -1
|
|
|
d67cb5 |
name_index = -1
|
|
|
d67cb5 |
@@ -72,6 +77,82 @@ def get_power_status(conn, options):
|
|
|
d67cb5 |
else:
|
|
|
d67cb5 |
return "PROBLEM"
|
|
|
d67cb5 |
|
|
|
d67cb5 |
+def get_plug_group_status_from_list(status_list):
|
|
|
d67cb5 |
+ for status in status_list:
|
|
|
d67cb5 |
+ if status == "on":
|
|
|
d67cb5 |
+ return status
|
|
|
d67cb5 |
+ return "off"
|
|
|
d67cb5 |
+
|
|
|
d67cb5 |
+def get_plug_group_status(conn, options):
|
|
|
d67cb5 |
+ listing = get_listing(conn, options, "/SG")
|
|
|
d67cb5 |
+
|
|
|
d67cb5 |
+ plug_section = 0
|
|
|
d67cb5 |
+ outlets = {}
|
|
|
d67cb5 |
+ current_outlet = ""
|
|
|
d67cb5 |
+ line_index = 0
|
|
|
d67cb5 |
+ lines = listing.splitlines()
|
|
|
d67cb5 |
+ while line_index < len(lines) and line_index >= 0:
|
|
|
d67cb5 |
+ line = lines[line_index]
|
|
|
d67cb5 |
+ if (line.find("|") >= 0 and line.lstrip().startswith("GROUP NAME") == False):
|
|
|
d67cb5 |
+ plug_line = [x.strip().lower() for x in line.split("|")]
|
|
|
d67cb5 |
+ if ["list", "monitor"].count(options["--action"]) == 0 and options["--plug"].lower() == plug_line[name_index]:
|
|
|
d67cb5 |
+ line_index += 1
|
|
|
d67cb5 |
+ plug_status = []
|
|
|
d67cb5 |
+ while line_index < len(lines) and line_index >= 0:
|
|
|
d67cb5 |
+ plug_line = [x.strip().lower() for x in lines[line_index].split("|")]
|
|
|
d67cb5 |
+ if len(plug_line[plug_index]) > 0 and len(plug_line[name_index]) == 0:
|
|
|
d67cb5 |
+ plug_status.append(plug_line[status_index])
|
|
|
d67cb5 |
+ line_index += 1
|
|
|
d67cb5 |
+ else:
|
|
|
d67cb5 |
+ line_index = -1
|
|
|
d67cb5 |
+
|
|
|
d67cb5 |
+ return get_plug_group_status_from_list(plug_status)
|
|
|
d67cb5 |
+
|
|
|
d67cb5 |
+ else:
|
|
|
d67cb5 |
+ ## We already believe that first column contains plug number
|
|
|
d67cb5 |
+ if len(plug_line[0]) != 0:
|
|
|
d67cb5 |
+ group_name = plug_line[0]
|
|
|
d67cb5 |
+ plug_line_index = line_index + 1
|
|
|
d67cb5 |
+ plug_status = []
|
|
|
d67cb5 |
+ while plug_line_index < len(lines) and plug_line_index >= 0:
|
|
|
d67cb5 |
+ plug_line = [x.strip().lower() for x in lines[plug_line_index].split("|")]
|
|
|
d67cb5 |
+ if len(plug_line[name_index]) > 0:
|
|
|
d67cb5 |
+ plug_line_index = -1
|
|
|
d67cb5 |
+ break
|
|
|
d67cb5 |
+ if len(plug_line[plug_index]) > 0:
|
|
|
d67cb5 |
+ plug_status.append(plug_line[status_index])
|
|
|
d67cb5 |
+ plug_line_index += 1
|
|
|
d67cb5 |
+ else:
|
|
|
d67cb5 |
+ plug_line_index = -1
|
|
|
d67cb5 |
+ outlets[group_name] = (group_name, get_plug_group_status_from_list(plug_status))
|
|
|
d67cb5 |
+ line_index += 1
|
|
|
d67cb5 |
+
|
|
|
d67cb5 |
+ elif (line.upper().lstrip().startswith("GROUP NAME")):
|
|
|
d67cb5 |
+ plug_header = [x.strip().lower() for x in line.split("|")]
|
|
|
d67cb5 |
+ name_index = plug_header.index("group name")
|
|
|
d67cb5 |
+ plug_index = plug_header.index("plug")
|
|
|
d67cb5 |
+ status_index = plug_header.index("status")
|
|
|
d67cb5 |
+ line_index += 2
|
|
|
d67cb5 |
+ else:
|
|
|
d67cb5 |
+ line_index += 1
|
|
|
d67cb5 |
+
|
|
|
d67cb5 |
+
|
|
|
d67cb5 |
+ if ["list", "monitor"].count(options["--action"]) == 1:
|
|
|
d67cb5 |
+ for group, status in outlet_groups:
|
|
|
d67cb5 |
+ outlets[group] = (group, status[0])
|
|
|
d67cb5 |
+
|
|
|
d67cb5 |
+ return outlets
|
|
|
d67cb5 |
+ else:
|
|
|
d67cb5 |
+ return "PROBLEM"
|
|
|
d67cb5 |
+
|
|
|
d67cb5 |
+def get_power_status(conn, options):
|
|
|
d67cb5 |
+ ret = get_plug_status(conn, options)
|
|
|
d67cb5 |
+
|
|
|
d67cb5 |
+ if ret == "PROBLEM":
|
|
|
d67cb5 |
+ ret = get_plug_group_status(conn, options)
|
|
|
d67cb5 |
+
|
|
|
d67cb5 |
+ return ret
|
|
|
d67cb5 |
+
|
|
|
d67cb5 |
def set_power_status(conn, options):
|
|
|
d67cb5 |
action = {
|
|
|
d67cb5 |
'on' : "/on",
|