Gitweb:
http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=848b80...
Commit: 848b801b36ccffa27fae19fe6fbcfb4a496d9d7a
Parent: a252b16a2aa7a337a6f3186c72c397f6bf1d4606
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Wed Apr 23 17:54:35 2014 +0200
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Mon May 5 12:02:08 2014 +0200
[cleanup] Simplify 'if' statements to use 'not' and 'get'
---
fence/agents/apc/fence_apc.py | 8 +++---
fence/agents/drac5/fence_drac5.py | 4 +-
fence/agents/dummy/fence_dummy.py | 6 ++--
fence/agents/ilo/fence_ilo.py | 4 +-
fence/agents/lib/fencing.py.py | 28 ++++++++++++------------
fence/agents/lpar/fence_lpar.py | 2 +-
fence/agents/netio/fence_netio.py | 2 +-
fence/agents/ovh/fence_ovh.py | 4 +-
fence/agents/rsb/fence_rsb.py | 2 +-
fence/agents/vmware_soap/fence_vmware_soap.py | 2 +-
fence/agents/wti/fence_wti.py | 2 +-
11 files changed, 32 insertions(+), 32 deletions(-)
diff --git a/fence/agents/apc/fence_apc.py b/fence/agents/apc/fence_apc.py
index c31a4b0..6047501 100644
--- a/fence/agents/apc/fence_apc.py
+++ b/fence/agents/apc/fence_apc.py
@@ -40,10 +40,10 @@ def get_power_status(conn, options):
if None != re.compile('.* MasterSwitch plus.*', re.IGNORECASE |
re.S).match(conn.before):
switch = 1
if None != re.compile('.* MasterSwitch plus 2', re.IGNORECASE |
re.S).match(conn.before):
- if 0 == options.has_key("--switch"):
+ if not options.has_key("--switch"):
fail_usage("Failed: You have to enter physical switch number")
else:
- if 0 == options.has_key("--switch"):
+ if not options.has_key("--switch"):
options["--switch"] = "1"
if None == re.compile('.*Outlet Management.*', re.IGNORECASE |
re.S).match(conn.before):
@@ -116,10 +116,10 @@ def set_power_status(conn, options):
'off': "3"
}[options["--action"]]
if None != re.compile('.* MasterSwitch plus 2', re.IGNORECASE |
re.S).match(conn.before):
- if 0 == options.has_key("--switch"):
+ if not options.has_key("--switch"):
fail_usage("Failed: You have to enter physical switch number")
else:
- if 0 == options.has_key("--switch"):
+ if not options.has_key("--switch"):
options["--switch"] = 1
if None == re.compile('.*Outlet Management.*', re.IGNORECASE |
re.S).match(conn.before):
diff --git a/fence/agents/drac5/fence_drac5.py b/fence/agents/drac5/fence_drac5.py
index 7687135..845c6ac 100644
--- a/fence/agents/drac5/fence_drac5.py
+++ b/fence/agents/drac5/fence_drac5.py
@@ -129,7 +129,7 @@ By default, the telnet interface is not enabled."
######
conn = fence_login(options)
- if options.has_key("--drac-version") == False:
+ if not options.has_key("--drac-version"):
## autodetect from text issued by fence device
if conn.before.find("CMC") >= 0:
options["--drac-version"] = "DRAC CMC"
@@ -142,7 +142,7 @@ By default, the telnet interface is not enabled."
options["--drac-version"] = "DRAC 5"
if options["--drac-version"] in ["DRAC MC", "DRAC CMC"]:
- if 0 == options.has_key("--plug") and 0 == ["monitor",
"list"].count(options["--action"].lower()):
+ if not options.has_key("--plug") and 0 == ["monitor",
"list"].count(options["--action"].lower()):
fail_usage("Failed: You have to enter module name (-n)")
result = fence_action(conn, options, set_power_status, get_power_status,
get_list_devices)
diff --git a/fence/agents/dummy/fence_dummy.py b/fence/agents/dummy/fence_dummy.py
index 5256aa8..3bd2b90 100644
--- a/fence/agents/dummy/fence_dummy.py
+++ b/fence/agents/dummy/fence_dummy.py
@@ -42,7 +42,7 @@ def set_power_status_file(conn, options):
def get_power_status_fail(conn, options):
outlets = get_outlets_fail(conn, options)
- if len(outlets) == 0 or options.has_key("--plug") == 0:
+ if len(outlets) == 0 or not options.has_key("--plug"):
fail_usage("Failed: You have to enter existing machine!")
else:
return outlets[options["--plug"]][0]
@@ -66,10 +66,10 @@ def get_outlets_fail(conn, options):
# This fake agent has no port data to list, so we have to make
# something up for the list action.
- if options.has_key("--action") and options["--action"] ==
"list":
+ if options.get("--action", None) == "list":
result["fake_port_1"] = [plug_status, "fake"]
result["fake_port_2"] = [plug_status, "fake"]
- elif options.has_key("--plug") == 0:
+ elif not options.has_key("--plug"):
fail_usage("Failed: You have to enter existing machine!")
else:
port = options["--plug"]
diff --git a/fence/agents/ilo/fence_ilo.py b/fence/agents/ilo/fence_ilo.py
index f45e749..766aba9 100644
--- a/fence/agents/ilo/fence_ilo.py
+++ b/fence/agents/ilo/fence_ilo.py
@@ -39,7 +39,7 @@ def set_power_status(conn, options):
" PASSWORD = " + quoteattr(options["--password"]) +
">\r\n")
conn.send("<SERVER_INFO MODE = \"write\">")
- if options.has_key("fw_processor") and options["fw_processor"] ==
"iLO2":
+ if options.get("fw_processor", None) == "iLO2":
if options["fw_version"] > 1.29:
conn.send("<HOLD_PWR_BTN TOGGLE=\"yes\" />\r\n")
else:
@@ -96,7 +96,7 @@ the iLO card through an XML stream."
conn.send("<?xml version=\"1.0\"?>\r\n")
conn.log_expect(options, [ "</RIBCL>", "<END_RIBCL/>"
], int(options["--login-timeout"]))
version = re.compile("<RIBCL VERSION=\"(.*?)\"",
re.IGNORECASE).search(conn.before).group(1)
- if options.has_key("--ribcl-version") == 0:
+ if not options.has_key("--ribcl-version"):
options["--ribcl-version"] = float(version)
if options["--ribcl-version"] >= 2:
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index 76c2cd1..b3afa0f 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -598,7 +598,7 @@ def process_input(avail_opt):
## Compatibility Layer
#####
z = dict(opt)
- if z.has_key("--plug") == 1:
+ if z.has_key("--plug"):
z["-m"] = z["--plug"]
opt = z
@@ -685,13 +685,13 @@ def check_input(device_opt, opt):
for opt in device_opt:
if all_opt[opt].has_key("default"):
getopt_long = "--" + all_opt[opt]["longopt"]
- if 0 == options.has_key(getopt_long):
+ if not options.has_key(getopt_long):
options[getopt_long] = all_opt[opt]["default"]
## In special cases (show help, metadata or version) we don't need to check
anything
#####
if options.has_key("--help") or options.has_key("--version") or \
- (options.has_key("--action") and options["--action"].lower() ==
"metadata"):
+ options.get("--action", "").lower() == "metadata":
return options
options["--action"] = options["--action"].lower()
@@ -721,31 +721,31 @@ def check_input(device_opt, opt):
options["--action"] = "off"
## automatic detection and set of valid UUID from --plug
- if (0 == options.has_key("--username")) and \
+ if not options.has_key("--username") and \
device_opt.count("login") and (device_opt.count("no_login") ==
0):
fail_usage("Failed: You have to set login name")
- if device_opt.count("ipaddr") and 0 == options.has_key("--ip") and 0
== options.has_key("--managed"):
+ if device_opt.count("ipaddr") and not options.has_key("--ip") and
not options.has_key("--managed"):
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("--password") or
options.has_key("--password-script")):
+ if not (options.has_key("--password") or
options.has_key("--password-script")):
fail_usage("Failed: You have to enter password or password script")
else:
- if 0 == (options.has_key("--password") or \
+ if not (options.has_key("--password") or \
options.has_key("--password-script") or
options.has_key("--identity-file")):
fail_usage("Failed: You have to enter password, password script or identity
file")
- if 0 == options.has_key("--ssh") and 1 ==
options.has_key("--identity-file"):
+ if not options.has_key("--ssh") and
options.has_key("--identity-file"):
fail_usage("Failed: You have to use identity file together with ssh connection
(-x)")
- if 1 == options.has_key("--identity-file"):
- if 0 == os.path.isfile(options["--identity-file"]):
+ if options.has_key("--identity-file"):
+ if not os.path.isfile(options["--identity-file"]):
fail_usage("Failed: Identity file " + options["--identity-file"] +
" does not exist")
if (0 == ["list",
"monitor"].count(options["--action"].lower())) and \
- 0 == options.has_key("--plug") and device_opt.count("port") and
device_opt.count("no_port") == 0:
+ not options.has_key("--plug") and device_opt.count("port") and
device_opt.count("no_port") == 0:
fail_usage("Failed: You have to enter plug number or machine
identification")
if options.has_key("--password-script"):
@@ -840,7 +840,7 @@ def show_docs(options, docs = None):
usage(device_opt)
sys.exit(0)
- if options.has_key("--action") and options["--action"].lower() ==
"metadata":
+ if options.get("--action", "").lower() == "metadata":
metadata(device_opt, options, docs)
sys.exit(0)
@@ -910,7 +910,7 @@ def fence_action(tn, options, set_power_fn, get_power_fn,
get_outlet_list = None
fail(EC_WAITING_OFF)
elif options["--action"] == "reboot":
power_on = False
- if options.has_key("--method") and options["--method"].lower() ==
"cycle" and reboot_cycle_fn is not None:
+ if options.get("--method", "").lower() == "cycle" and
reboot_cycle_fn is not None:
for _ in range(1, 1 + int(options["--retry-on"])):
if reboot_cycle_fn(tn, options):
power_on = True
@@ -999,7 +999,7 @@ def fence_login(options, re_login_string = r"(login\s*: )|(Login
Name: )|(usern
logging.error("%s\n", str(ex))
syslog.syslog(syslog.LOG_ERR, str(ex))
sys.exit(EC_GENERIC_ERROR)
- elif options.has_key("--ssh") and 0 ==
options.has_key("--identity-file"):
+ elif options.has_key("--ssh") and not
options.has_key("--identity-file"):
command = '%s %s %s@%s -p %s -o PubkeyAuthentication=no' % \
(SSH_PATH, force_ipvx, options["--username"], options["--ip"],
options["--ipport"])
if options.has_key("--ssh-options"):
diff --git a/fence/agents/lpar/fence_lpar.py b/fence/agents/lpar/fence_lpar.py
index 527b74b..da99073 100644
--- a/fence/agents/lpar/fence_lpar.py
+++ b/fence/agents/lpar/fence_lpar.py
@@ -141,7 +141,7 @@ def main():
docs["vendorurl"] = "http://www.ibm.com"
show_docs(options, docs)
- if 0 == options.has_key("--managed"):
+ if not options.has_key("--managed"):
fail_usage("Failed: You have to enter name of managed system")
##
diff --git a/fence/agents/netio/fence_netio.py b/fence/agents/netio/fence_netio.py
index 4f756f8..6e419a7 100755
--- a/fence/agents/netio/fence_netio.py
+++ b/fence/agents/netio/fence_netio.py
@@ -60,7 +60,7 @@ def main():
opt = process_input(device_opt)
# set default port for telnet only
- if 0 == opt.has_key("--ipport"):
+ if not opt.has_key("--ipport"):
opt["--ipport"] = "1234"
opt["eol"] = "\r\n"
diff --git a/fence/agents/ovh/fence_ovh.py b/fence/agents/ovh/fence_ovh.py
index 4cad818..50980f6 100644
--- a/fence/agents/ovh/fence_ovh.py
+++ b/fence/agents/ovh/fence_ovh.py
@@ -103,10 +103,10 @@ Poweroff is simulated with a reboot into rescue-pro mode."
if options["--action"] in [ "list", "status"]:
fail_usage("Action '" + options["--action"] + "' is
not supported in this fence agent")
- if options["--plug"].endswith(".ovh.net") == False:
+ if not options["--plug"].endswith(".ovh.net"):
options["--plug"] += ".ovh.net"
- if options.has_key("--email") == False:
+ if not options.has_key("--email"):
fail_usage("You have to enter e-mail address which is notified by fence
agent")
# Save datetime just before changing netboot
diff --git a/fence/agents/rsb/fence_rsb.py b/fence/agents/rsb/fence_rsb.py
index 32afc8f..415de10 100755
--- a/fence/agents/rsb/fence_rsb.py
+++ b/fence/agents/rsb/fence_rsb.py
@@ -47,7 +47,7 @@ def main():
opt = process_input(device_opt)
# set default port for telnet only
- if 0 == opt.has_key("--ssh") and 0 == opt.has_key("--ipport"):
+ if not opt.has_key("--ssh") and not opt.has_key("--ipport"):
opt["--ipport"] = "3172"
options = check_input(device_opt, opt)
diff --git a/fence/agents/vmware_soap/fence_vmware_soap.py
b/fence/agents/vmware_soap/fence_vmware_soap.py
index 66e7eb9..d9e5ff2 100644
--- a/fence/agents/vmware_soap/fence_vmware_soap.py
+++ b/fence/agents/vmware_soap/fence_vmware_soap.py
@@ -123,7 +123,7 @@ def get_power_status(conn, options):
if ["list", "monitor"].count(options["--action"]) == 1:
return machines
else:
- if options.has_key("--uuid") == False:
+ if not options.has_key("--uuid"):
if options["--plug"].startswith('/'):
## Transform InventoryPath to UUID
mo_SearchIndex = Property(options["ServiceContent"].searchIndex.value)
diff --git a/fence/agents/wti/fence_wti.py b/fence/agents/wti/fence_wti.py
index 0280e29..de692f0 100644
--- a/fence/agents/wti/fence_wti.py
+++ b/fence/agents/wti/fence_wti.py
@@ -202,7 +202,7 @@ is running because the connection will block any necessary fencing
actions."
##
## @note: if it possible that this device does not need either login, password or both
of them
#####
- if 0 == options.has_key("--ssh"):
+ if not options.has_key("--ssh"):
try:
if options["--action"] in ["off", "reboot"]:
time.sleep(int(options["--delay"]))