if (0 == options.has_key("-l")) and device_opt.count("login") and (device_opt.count("no_login") == 0):
fail_usage("Failed: You have to set login name")
if 0 == options.has_key("-a") and 0 == options.has_key("-s"):
fail_usage("Failed: You have to enter fence address")
if (device_opt.count("no_password") == 0):
if 0 == device_opt.count("identity_file"):
if 0 == (options.has_key("-p") or options.has_key("-S")):
fail_usage("Failed: You have to enter password or password script")
else:
if 0 == (options.has_key("-p") or options.has_key("-S") or options.has_key("-k")):
fail_usage("Failed: You have to enter password, password script or identity file")
if 0 == options.has_key("-x") and 1 == options.has_key("-k"):
fail_usage("Failed: You have to use identity file together with ssh connection (-x)")
if 1 == options.has_key("-k"):
if 0 == os.path.isfile(options["-k"]):
fail_usage("Failed: Identity file " + options["-k"] + " does not exist")
- if (0 == ["list", "monitor"].count(options["-o"].lower())) and (0 == options.has_key("-n") and 0 == options.has_key("-U")) and (device_opt.count("port")):
+ if (0 == ["list", "monitor"].count(options["-o"].lower())) and \
+ (0 == options.has_key("-n") and 0 == options.has_key("-U")) and (device_opt.count("port")):
fail_usage("Failed: You have to enter plug number")
- if (options["-o"] == "list") and (0 == options["device_opt"].count("port")) and (0 == options["device_opt"].count("partition") and 0 == options["device_opt"].count("uuid") and 0 == options["device_opt"].count("module_name")):
+ if (options["-o"] == "list") and \
+ 0 == options["device_opt"].count("port") and 0 == options["device_opt"].count("partition") and \
+ 0 == options["device_opt"].count("uuid") and 0 == options["device_opt"].count("module_name"):
print "N/A"
return
elif (options["-o"] == "list" and get_outlet_list == None):
## @todo: exception?
## This is just temporal solution, we will remove default value
## None as soon as all existing agent will support this operation
print "NOTICE: List option is not working on this device yet"
return
elif (options["-o"] == "list") or ((options["-o"] == "monitor") and 1 == options["device_opt"].count("port")):
outlets = get_outlet_list(tn, options)
## keys can be numbers (port numbers) or strings (names of VM)
for o in outlets.keys():
(alias, status) = outlets[o]
if options["-o"] != "monitor":
print o + options["-C"] + alias
return
status = get_power_fn(tn, options)
if status != "on" and status != "off":
fail(EC_STATUS)
if options["-o"] == "on":
if status == "on":
print "Success: Already ON"
else:
power_on = False
- for i in range(1, 1 + int(options["-F"])):
+ for _ in range(1, 1 + int(options["-F"])):
set_power_fn(tn, options)
time.sleep(int(options["-G"]))
if wait_power_status(tn, options, get_power_fn):
power_on = True
break
if power_on:
print "Success: Powered ON"
else:
fail(EC_WAITING_ON)
elif options["-o"] == "off":
if status == "off":
print "Success: Already OFF"
else:
set_power_fn(tn, options)
time.sleep(int(options["-G"]))
if wait_power_status(tn, options, get_power_fn):
print "Success: Powered OFF"
else:
fail(EC_WAITING_OFF)
elif options["-o"] == "reboot":
if status != "off":
options["-o"] = "off"
set_power_fn(tn, options)
time.sleep(int(options["-G"]))
if wait_power_status(tn, options, get_power_fn) == 0:
fail(EC_WAITING_OFF)
options["-o"] = "on"
power_on = False
- for i in range(1, 1 + int(options["-F"])):
+ for _ in range(1, 1 + int(options["-F"])):
set_power_fn(tn, options)
time.sleep(int(options["-G"]))
if wait_power_status(tn, options, get_power_fn) == 1:
power_on = True
break
if power_on == False:
- # this should not fail as not was fenced succesfully
+ # this should not fail as node was fenced succesfully
sys.stderr.write('Timed out waiting to power ON\n')
print "Success: Rebooted"
elif options["-o"] == "status":
print "Status: " + status.upper()
if status.upper() == "OFF":
result = 2
elif options["-o"] == "monitor":
- 1
+ pass
return result
def fence_login(options):
force_ipvx = ""
if (options.has_key("-6")):
force_ipvx = "-6 "
if (options.has_key("-4")):
force_ipvx = "-4 "
if (options.has_key("eol") == False):
options["eol"] = "\r\n"
## Do the delay of the fence device before logging in
## Delay is important for two-node clusters fencing but we do not need to delay 'status' operations
if options["-o"] in ["off", "reboot"]:
time.sleep(int(options["-f"]))
try:
re_login = re.compile("(login\s*: )|(Login Name: )|(username: )|(User Name :)", re.IGNORECASE)
sys.stderr.write("Due to limitations, binary dependencies on fence agents "
"are not in the spec file and must be installed separately." + "\n")
sys.exit(EC_GENERIC_ERROR)
- result = conn.log_expect(options, [ options["-c"], "Are you sure you want to continue connecting (yes/no)?", "Enter passphrase for key '"+options["-k"]+"':" ], int(options["-y"]))
+ result = conn.log_expect(options, [ options["-c"], \
+ "Are you sure you want to continue connecting (yes/no)?", \