if options.has_key("--plug") and len(options["--plug"].split(",")) > 1 and options.has_key("--method") and options["--method"] == "cycle":
fail_usage("Failed: Cannot use --method cycle for more than 1 plug")
for opt in device_opt:
if all_opt[opt].has_key("choices"):
long = "--" + all_opt[opt]["longopt"]
possible_values_upper = map (lambda y : y.upper(), all_opt[opt]["choices"])
if options.has_key(long):
options[long] = options[long].upper()
if not options["--" + all_opt[opt]["longopt"]] in possible_values_upper:
fail_usage("Failed: You have to enter a valid choice for %s from the valid values: %s" % ("--" + all_opt[opt]["longopt"] , str(all_opt[opt]["choices"])))
return options
def wait_power_status(tn, options, get_power_fn):
for dummy in xrange(int(options["--power-timeout"])):
if get_multi_power_fn(tn, options, get_power_fn) != options["--action"]:
time.sleep(1)
else:
return 1
return 0
## Obtain a power status from possibly more than one plug
plug_header = [x.strip().lower() for x in line.split("|")]
plug_index = plug_header.index("plug")
name_index = plug_header.index("name")
status_index = plug_header.index("status")
if ["list", "monitor"].count(options["--action"]) == 1:
return outlets
else:
return "PROBLEM"
def get_plug_group_status_from_list(status_list):
for status in status_list:
if status == "on":
return status
return "off"
def get_plug_group_status(conn, options):
listing = get_listing(conn, options, "/SG")
- plug_section = 0
outlets = {}
- current_outlet = ""
line_index = 0
lines = listing.splitlines()
while line_index < len(lines) and line_index >= 0:
line = lines[line_index]
if (line.find("|") >= 0 and line.lstrip().startswith("GROUP NAME") == False):
plug_line = [x.strip().lower() for x in line.split("|")]
if ["list", "monitor"].count(options["--action"]) == 0 and options["--plug"].lower() == plug_line[name_index]:
plug_status = []
while line_index < len(lines) and line_index >= 0:
plug_line = [x.strip().lower() for x in lines[line_index].split("|")]
if len(plug_line) >= max(name_index, status_index) and len(plug_line[plug_index]) > 0 and (len(plug_line[name_index]) == 0 or options["--plug"].lower() == plug_line[name_index]):
## Firmware 1.43 does not have a valid value of plug on first line as only name is defined on that line