Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=40083240d... Commit: 40083240dfc96073905b7a42222111c7637a0feb Parent: 756796d3ab7a9a9933a7ebca2c6b0259a7a7ab9c Author: Marek 'marx' Grac mgrac@redhat.com AuthorDate: Mon Apr 14 15:44:22 2014 +0200 Committer: Marek 'marx' Grac mgrac@redhat.com CommitterDate: Wed Apr 16 14:50:40 2014 +0200
[cleanup] Remove additional parentheses
--- fence/agents/amt/fence_amt.py | 4 +- fence/agents/apc/fence_apc.py | 30 ++++---- fence/agents/apc_snmp/fence_apc_snmp.py | 28 ++++---- fence/agents/brocade/fence_brocade.py | 2 +- fence/agents/cisco_mds/fence_cisco_mds.py | 6 +- fence/agents/cisco_ucs/fence_cisco_ucs.py | 6 +- fence/agents/drac/fence_drac.py | 2 +- fence/agents/drac5/fence_drac5.py | 4 +- fence/agents/dummy/fence_dummy.py | 2 +- fence/agents/eaton_snmp/fence_eaton_snmp.py | 40 +++++----- fence/agents/eps/fence_eps.py | 12 ++-- fence/agents/hds_cb/fence_hds_cb.py | 6 +- fence/agents/ibmblade/fence_ibmblade.py | 2 +- fence/agents/ifmib/fence_ifmib.py | 12 ++-- fence/agents/intelmodular/fence_intelmodular.py | 2 +- fence/agents/ipdu/fence_ipdu.py | 22 +++--- fence/agents/ldom/fence_ldom.py | 10 ++-- fence/agents/lib/fencing.py.py | 24 +++--- fence/agents/lib/fencing_snmp.py.py | 16 ++-- fence/agents/ovh/fence_ovh.py | 6 +- fence/agents/rhevm/fence_rhevm.py | 8 +- fence/agents/rsa/fence_rsa.py | 2 +- fence/agents/rsb/fence_rsb.py | 2 +- fence/agents/sanbox2/fence_sanbox2.py | 4 +- fence/agents/virsh/fence_virsh.py | 6 +- fence/agents/vmware/fence_vmware.py | 86 +++++++++++----------- fence/agents/vmware_soap/fence_vmware_soap.py | 4 +- fence/agents/wti/fence_wti.py | 8 +- fence/agents/xenapi/fence_xenapi.py | 14 ++-- 29 files changed, 185 insertions(+), 185 deletions(-)
diff --git a/fence/agents/amt/fence_amt.py b/fence/agents/amt/fence_amt.py index edab61a..4a3f0e2 100644 --- a/fence/agents/amt/fence_amt.py +++ b/fence/agents/amt/fence_amt.py @@ -18,9 +18,9 @@ def get_power_status(_, options): match = re.search('Powerstate:[\s]*(..)', str(output)) status = match.group(1) if match else None
- if (status == None): + if status == None: return "fail" - elif (status == "S0"): # SO = on; S3 = sleep; S5 = off + elif status == "S0": # SO = on; S3 = sleep; S5 = off return "on" else: return "off" diff --git a/fence/agents/apc/fence_apc.py b/fence/agents/apc/fence_apc.py index f744583..4b4c2bc 100644 --- a/fence/agents/apc/fence_apc.py +++ b/fence/agents/apc/fence_apc.py @@ -37,21 +37,21 @@ def get_power_status(conn, options): admin = 0 switch = 0
- if (None != re.compile('.* MasterSwitch plus.*', re.IGNORECASE | re.S).match(conn.before)): + 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 None != re.compile('.* MasterSwitch plus 2', re.IGNORECASE | re.S).match(conn.before): + if 0 == options.has_key("--switch"): fail_usage("Failed: You have to enter physical switch number") else: - if (0 == options.has_key("--switch")): + if 0 == options.has_key("--switch"): options["--switch"] = "1"
- if (None == re.compile('.*Outlet Management.*', re.IGNORECASE | re.S).match(conn.before)): + if None == re.compile('.*Outlet Management.*', re.IGNORECASE | re.S).match(conn.before): version = 2 else: version = 3
- if (None == re.compile('.*Outlet Control/Configuration.*', re.IGNORECASE | re.S).match(conn.before)): + if None == re.compile('.*Outlet Control/Configuration.*', re.IGNORECASE | re.S).match(conn.before): admin = 0 else: admin = 1 @@ -76,7 +76,7 @@ def get_power_status(conn, options): show_re = re.compile(r'(^|\x0D)\s*(\d+)- (.*?)\s+(ON|OFF)\s*') for line in lines: res = show_re.search(line) - if (res != None): + if res != None: outlets[res.group(2)] = (res.group(3), res.group(4)) conn.send_eol("") if exp_result != 0: @@ -108,26 +108,26 @@ def set_power_status(conn, options): admin3 = 0 switch = 0
- if (None != re.compile('.* MasterSwitch plus.*', re.IGNORECASE | re.S).match(conn.before)): + if None != re.compile('.* MasterSwitch plus.*', re.IGNORECASE | re.S).match(conn.before): switch = 1 ## MasterSwitch has different schema for on/off actions action = { 'on' : "1", '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 None != re.compile('.* MasterSwitch plus 2', re.IGNORECASE | re.S).match(conn.before): + if 0 == options.has_key("--switch"): fail_usage("Failed: You have to enter physical switch number") else: - if (0 == options.has_key("--switch")): + if 0 == options.has_key("--switch"): options["--switch"] = 1
- if (None == re.compile('.*Outlet Management.*', re.IGNORECASE | re.S).match(conn.before)): + if None == re.compile('.*Outlet Management.*', re.IGNORECASE | re.S).match(conn.before): version = 2 else: version = 3
- if (None == re.compile('.*Outlet Control/Configuration.*', re.IGNORECASE | re.S).match(conn.before)): + if None == re.compile('.*Outlet Control/Configuration.*', re.IGNORECASE | re.S).match(conn.before): admin2 = 0 else: admin2 = 1 @@ -141,7 +141,7 @@ def set_power_status(conn, options): else: conn.send_eol("2") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) - if (None == re.compile('.*2- Outlet Restriction.*', re.IGNORECASE | re.S).match(conn.before)): + if None == re.compile('.*2- Outlet Restriction.*', re.IGNORECASE | re.S).match(conn.before): admin3 = 0 else: admin3 = 1 @@ -189,7 +189,7 @@ def get_power_status5(conn, options):
for line in lines: res = show_re.search(line) - if (res != None): + if res != None: outlets[res.group(1)] = (res.group(2), res.group(3))
if ["list", "monitor"].count(options["--action"]) == 1: diff --git a/fence/agents/apc_snmp/fence_apc_snmp.py b/fence/agents/apc_snmp/fence_apc_snmp.py index 0a0d409..33f152e 100644 --- a/fence/agents/apc_snmp/fence_apc_snmp.py +++ b/fence/agents/apc_snmp/fence_apc_snmp.py @@ -99,7 +99,7 @@ def apc_set_device(conn): # First resolve type of APC apc_type = conn.walk(OID_SYS_OBJECT_ID)
- if (not ((len(apc_type)==1) and (agents_dir.has_key(apc_type[0][1])))): + if not ((len(apc_type)==1) and (agents_dir.has_key(apc_type[0][1]))): apc_type = [[None, None]]
device = agents_dir[apc_type[0][1]] @@ -109,41 +109,41 @@ def apc_set_device(conn): def apc_resolv_port_id(conn, options): global port_id, switch_id
- if (device == None): + if device == None: apc_set_device(conn)
# Now we resolv port_id/switch_id - if ((options["--plug"].isdigit()) and ((not device.has_switches) or (options["--switch"].isdigit()))): + if (options["--plug"].isdigit()) and ((not device.has_switches) or (options["--switch"].isdigit())): port_id = int(options["--plug"])
- if (device.has_switches): + if device.has_switches: switch_id = int(options["--switch"]) else: table = conn.walk(device.outlet_table_oid, 30)
for x in table: - if (x[1].strip('"') == options["--plug"]): + if x[1].strip('"') == options["--plug"]: t = x[0].split('.') - if (device.has_switches): + if device.has_switches: port_id = int(t[len(t)-1]) switch_id = int(t[len(t)-3]) else: port_id = int(t[len(t)-1])
- if (port_id == None): + if port_id == None: fail_usage("Can't find port with name %s!"%(options["--plug"]))
def get_power_status(conn, options): - if (port_id == None): + if port_id == None: apc_resolv_port_id(conn, options)
oid = ((device.has_switches) and device.status_oid%(switch_id, port_id) or device.status_oid%(port_id))
(oid, status) = conn.get(oid) - return (status==str(device.state_on) and "on" or "off") + return status == str(device.state_on) and "on" or "off"
def set_power_status(conn, options): - if (port_id == None): + if port_id == None: apc_resolv_port_id(conn, options)
oid = ((device.has_switches) and device.control_oid%(switch_id, port_id) or device.control_oid%(port_id)) @@ -154,7 +154,7 @@ def set_power_status(conn, options): def get_outlets_status(conn, options): result = {}
- if (device == None): + if device == None: apc_set_device(conn)
res_ports = conn.walk(device.outlet_table_oid, 30) @@ -183,13 +183,13 @@ def main(): options = check_input(device_opt, process_input(device_opt))
## Support for -n [switch]:[plug] notation that was used before - if ((options.has_key("--plug")) and (-1 != options["--plug"].find(":"))): + if (options.has_key("--plug")) and (-1 != options["--plug"].find(":")): (switch, plug) = options["--plug"].split(":", 1) - if ((switch.isdigit()) and (plug.isdigit())): + if switch.isdigit() and plug.isdigit(): options["--switch"] = switch options["--plug"] = plug
- if (not (options.has_key("--switch"))): + if not options.has_key("--switch"): options["--switch"] = "1"
docs = { } diff --git a/fence/agents/brocade/fence_brocade.py b/fence/agents/brocade/fence_brocade.py index 35082ee..3bbb74c 100644 --- a/fence/agents/brocade/fence_brocade.py +++ b/fence/agents/brocade/fence_brocade.py @@ -22,7 +22,7 @@ def get_power_status(conn, options):
for line in lines: res = show_re.search(line) - if (res != None): + if res != None: # We queried if it is disabled, so we have to negate answer if res.group(1) == "ON": return "off" diff --git a/fence/agents/cisco_mds/fence_cisco_mds.py b/fence/agents/cisco_mds/fence_cisco_mds.py index 0508f90..82b28a0 100644 --- a/fence/agents/cisco_mds/fence_cisco_mds.py +++ b/fence/agents/cisco_mds/fence_cisco_mds.py @@ -39,14 +39,14 @@ def cisco_port2oid(port):
nums = re.match(r'^fc(\d+)/(\d+)$', port)
- if ((nums) and (len(nums.groups()))==2): + if nums and len(nums.groups()) == 2: return "%s.%d.%d"% (PORT_ADMIN_STATUS_OID, int(nums.group(1))+21, int(nums.group(2))-1) else: fail_usage("Mangled port number: %s"%(port))
def get_power_status(conn, options): (_, status) = conn.get(PORT_OID) - return (status=="1" and "on" or "off") + return status == "1" and "on" or "off"
def set_power_status(conn, options): conn.set(PORT_OID, (options["--action"]=="on" and 1 or 2)) @@ -93,7 +93,7 @@ which can be used with any Cisco MDS 9000 series with SNMP enabled device." docs["vendorurl"] = "http://www.cisco.com" show_docs(options, docs)
- if (not (options["--action"] in ["list","monitor"])): + if not options["--action"] in ["list","monitor"]: PORT_OID = cisco_port2oid(options["--plug"])
# Operate the fencing device diff --git a/fence/agents/cisco_ucs/fence_cisco_ucs.py b/fence/agents/cisco_ucs/fence_cisco_ucs.py index 2d4eaa8..0a4bff7 100644 --- a/fence/agents/cisco_ucs/fence_cisco_ucs.py +++ b/fence/agents/cisco_ucs/fence_cisco_ucs.py @@ -28,12 +28,12 @@ def get_power_status(conn, options): options["--plug"] + "/power"/>", int(options["--shell-timeout"]))
result = RE_STATUS.search(res) - if (result == None): + if result == None: fail(EC_STATUS) else: status = result.group(1)
- if (status == "up"): + if status == "up": return "on" else: return "off" @@ -137,7 +137,7 @@ used with Cisco UCS to fence machines." res = send_command(options, "<aaaLogin inName="" + options["--username"] + "" inPassword="" + options["--password"] + "" />", int(options["--login-timeout"])) result = RE_COOKIE.search(res) - if (result == None): + if result == None: ## Cookie is absenting in response fail(EC_LOGIN_DENIED) except: diff --git a/fence/agents/drac/fence_drac.py b/fence/agents/drac/fence_drac.py index b858d62..3cd7653 100644 --- a/fence/agents/drac/fence_drac.py +++ b/fence/agents/drac/fence_drac.py @@ -15,7 +15,7 @@ def get_power_status(conn, options): conn.send_eol("getmodinfo") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) status = re.compile(r"\s+(on|off)\s+", re.IGNORECASE).search(conn.before).group(1) - return (status.lower().strip()) + return status.lower().strip()
def set_power_status(conn, options): action = { diff --git a/fence/agents/drac5/fence_drac5.py b/fence/agents/drac5/fence_drac5.py index 7d8fe9a..6f70dad 100644 --- a/fence/agents/drac5/fence_drac5.py +++ b/fence/agents/drac5/fence_drac5.py @@ -73,7 +73,7 @@ def get_list_devices(conn, options): list_re = re.compile(r"^([^\s]*?)\s+Present\s*(ON|OFF)\s*.*$") conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"])) for line in conn.before.splitlines(): - if (list_re.search(line)): + if list_re.search(line): outlets[list_re.search(line).group(1)] = ("", list_re.search(line).group(2)) elif options["--drac-version"] == "DRAC MC": conn.send_eol("getmodinfo") @@ -81,7 +81,7 @@ def get_list_devices(conn, options): list_re = re.compile(r"^\s*([^\s]*)\s*---->\s*(.*?)\s+Present\s*(ON|OFF)\s*.*$") conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"])) for line in conn.before.splitlines(): - if (list_re.search(line)): + if list_re.search(line): outlets[list_re.search(line).group(2)] = ("", list_re.search(line).group(3)) elif options["--drac-version"] == "DRAC 5": ## DRAC 5 can be used only for one computer diff --git a/fence/agents/dummy/fence_dummy.py b/fence/agents/dummy/fence_dummy.py index aa1e5c2..9f0e950 100644 --- a/fence/agents/dummy/fence_dummy.py +++ b/fence/agents/dummy/fence_dummy.py @@ -69,7 +69,7 @@ def get_outlets_fail(conn, options): if options.has_key("--action") and options["--action"] == "list": result["fake_port_1"] = [plug_status, "fake"] result["fake_port_2"] = [plug_status, "fake"] - elif (options.has_key("--plug") == 0): + elif options.has_key("--plug") == 0: fail_usage("Failed: You have to enter existing machine!") else: port = options["--plug"] diff --git a/fence/agents/eaton_snmp/fence_eaton_snmp.py b/fence/agents/eaton_snmp/fence_eaton_snmp.py index 24dfd9e..884fd6d 100644 --- a/fence/agents/eaton_snmp/fence_eaton_snmp.py +++ b/fence/agents/eaton_snmp/fence_eaton_snmp.py @@ -76,7 +76,7 @@ def eaton_set_device(conn): # First resolve type of Eaton eaton_type = conn.walk(OID_SYS_OBJECT_ID)
- if (not ((len(eaton_type)==1) and (agents_dir.has_key(eaton_type[0][1])))): + if not ((len(eaton_type)==1) and (agents_dir.has_key(eaton_type[0][1]))): eaton_type = [[None, None]]
device = agents_dir[eaton_type[0][1]] @@ -86,48 +86,48 @@ def eaton_set_device(conn): def eaton_resolv_port_id(conn, options): global port_id, switch_id
- if (device==None): + if device == None: eaton_set_device(conn)
# Restore the increment, that was removed in main for ePDU Managed - if (device.ident_str == "Eaton Switched ePDU"): + if device.ident_str == "Eaton Switched ePDU": options["--plug"] = str(int(options["--plug"]) + 1)
# Now we resolv port_id/switch_id - if ((options["--plug"].isdigit()) and ((not device.has_switches) or (options["--switch"].isdigit()))): + if options["--plug"].isdigit() and ((not device.has_switches) or (options["--switch"].isdigit())): port_id = int(options["--plug"])
- if (device.has_switches): + if device.has_switches: switch_id = int(options["--switch"]) else: table = conn.walk(device.outlet_table_oid, 30)
for x in table: - if (x[1].strip('"')==options["--plug"]): + if x[1].strip('"') == options["--plug"]: t = x[0].split('.') - if (device.has_switches): + if device.has_switches: port_id = int(t[len(t)-1]) switch_id = int(t[len(t)-3]) else: - if (device.ident_str == "Eaton Switched ePDU"): + if device.ident_str == "Eaton Switched ePDU": port_id = int(t[len(t)-3]) else: port_id = int(t[len(t)-1])
- if (port_id==None): + if port_id == None: # Restore index offset, to provide a valid error output on Managed ePDU - if (device.ident_str != "Eaton Switched ePDU"): + if device.ident_str != "Eaton Switched ePDU": options["--plug"] = str(int(options["--plug"]) + 1) fail_usage("Can't find port with name %s!"%(options["--plug"]))
def get_power_status(conn, options): global port_id, after_set
- if (port_id==None): + if port_id == None: eaton_resolv_port_id(conn, options)
# Ajust OID for Switched ePDU when the get is after a set - if ((after_set == True) and (device.ident_str == "Eaton Switched ePDU")): + if after_set and device.ident_str == "Eaton Switched ePDU": port_id -= 1 after_set = False
@@ -135,9 +135,9 @@ def get_power_status(conn, options):
try: (oid, status)=conn.get(oid) - if (status==str(device.state_on)): + if status == str(device.state_on): return "on" - elif (status==str(device.state_off)): + elif status == str(device.state_off): return "off" else: return None @@ -149,11 +149,11 @@ def set_power_status(conn, options):
after_set = True
- if (port_id==None): + if port_id == None: eaton_resolv_port_id(conn, options)
# Controls start at #2 on Switched ePDU, since #1 is the global command - if (device.ident_str == "Eaton Switched ePDU"): + if device.ident_str == "Eaton Switched ePDU": port_id = int(port_id)+1
oid = ((device.has_switches) and device.control_oid%(switch_id, port_id) or device.control_oid%(port_id)) @@ -165,7 +165,7 @@ def get_outlets_status(conn, options): outletCount = 0 result = {}
- if (device==None): + if device == None: eaton_set_device(conn)
res_ports = conn.walk(device.outlet_table_oid, 30) @@ -177,7 +177,7 @@ def get_outlets_status(conn, options):
# Plug indexing start from zero, so we substract '1' from the # user's given plug number - if (device.ident_str == "Eaton Managed ePDU"): + if device.ident_str == "Eaton Managed ePDU": port_num = str(int(((device.has_switches) and "%s:%s"%(t[len(t)-3], t[len(t)-1]) or "%s"%(t[len(t)-1]))) + 1)
@@ -193,7 +193,7 @@ def get_outlets_status(conn, options): port_num = str(outletCount) port_name = str(outletCount) port_status = "" - if (status != '0'): + if status != '0': result[port_num] = (port_name, port_status)
return result @@ -214,7 +214,7 @@ def main(): # Plug indexing start from zero on ePDU Managed, so we substract '1' from # the user's given plug number. # For Switched ePDU, we will add this back again later. - if ((options.has_key("--plug")) and (options["--plug"].isdigit())): + if options.has_key("--plug") and options["--plug"].isdigit(): options["--plug"] = str(int(options["--plug"]) - 1)
docs = { } diff --git a/fence/agents/eps/fence_eps.py b/fence/agents/eps/fence_eps.py index 5efc8df..68a0991 100644 --- a/fence/agents/eps/fence_eps.py +++ b/fence/agents/eps/fence_eps.py @@ -27,14 +27,14 @@ def eps_run_command(options, params):
request_str = "/"+options["--page"]
- if (params!=""): + if params != "": request_str += "?"+params
logging.debug("GET %s\n" % request_str) conn.putrequest('GET', request_str)
- if (options.has_key("--username")): - if (not options.has_key("--password")): + if options.has_key("--username"): + if not options.has_key("--password"): options["--password"] = "" # Default is empty password
# String for Authorization header @@ -49,7 +49,7 @@ def eps_run_command(options, params): logging.debug("%d %s\n"%(response.status, response.reason))
#Response != OK -> couldn't login - if (response.status!=200): + if response.status != 200: fail(EC_LOGIN_DENIED)
result = response.read() @@ -71,8 +71,8 @@ def get_power_status(conn, options): for out_num, out_stat in status: result[out_num] = ("",(out_stat=="1" and "on" or "off"))
- if (not (options["--action"] in ['monitor','list'])): - if (not (options["--plug"] in result)): + if not options["--action"] in ['monitor','list']: + if not options["--plug"] in result: fail_usage("Failed: You have to enter existing physical plug!") else: return result[options["--plug"]][1] diff --git a/fence/agents/hds_cb/fence_hds_cb.py b/fence/agents/hds_cb/fence_hds_cb.py index f895fd3..6caee7f 100755 --- a/fence/agents/hds_cb/fence_hds_cb.py +++ b/fence/agents/hds_cb/fence_hds_cb.py @@ -39,9 +39,9 @@ def get_power_status(conn, options): for line in conn.before.splitlines(): # populate the relevant fields based on regex partition = re.search(RE_STATUS_LINE, line) - if( partition != None): + if partition != None: # find the blade number defined in args - if( partition.group(1) == options["--plug"] ): + if partition.group(1) == options["--plug"]: result = partition.group(2).lower() # We must make sure we go back to the main menu as the # status is checked before any fencing operations are @@ -97,7 +97,7 @@ def get_blades_list(conn, options): # "1 On Normal Off Basic Synchronized" for line in conn.before.splitlines(): partition = re.search(RE_STATUS_LINE, line) - if( partition != None): + if partition != None: outlets[partition.group(1)] = (partition.group(2), "") conn.sendline("Q") # Quit back to system command mode conn.log_expect(options, "SVP>", int(options["--shell-timeout"])) diff --git a/fence/agents/ibmblade/fence_ibmblade.py b/fence/agents/ibmblade/fence_ibmblade.py index d1bb065..f3c810e 100644 --- a/fence/agents/ibmblade/fence_ibmblade.py +++ b/fence/agents/ibmblade/fence_ibmblade.py @@ -29,7 +29,7 @@ STATUS_SET_ON = 1
def get_power_status(conn, options): (_, status) = conn.get("%s.%s"% (STATUSES_OID, options["--plug"])) - return (status == str(STATUS_UP) and "on" or "off") + return status == str(STATUS_UP) and "on" or "off"
def set_power_status(conn, options): conn.set("%s.%s"%(CONTROL_OID, options["--plug"]), diff --git a/fence/agents/ifmib/fence_ifmib.py b/fence/agents/ifmib/fence_ifmib.py index c477ba2..04edbf9 100644 --- a/fence/agents/ifmib/fence_ifmib.py +++ b/fence/agents/ifmib/fence_ifmib.py @@ -42,17 +42,17 @@ port_num = None def port2index(conn, port): res = None
- if (port.isdigit()): + if port.isdigit(): res = int(port) else: ports = conn.walk(PORTS_OID, 30)
for x in ports: - if (x[1].strip('"')==port): + if x[1].strip('"') == port: res = int(x[0].split('.')[-1]) break
- if (res==None): + if res == None: fail_usage("Can't find port with name %s!"%(port))
return res @@ -60,16 +60,16 @@ def port2index(conn, port): def get_power_status(conn, options): global port_num
- if (port_num==None): + if port_num == None: port_num = port2index(conn, options["--plug"])
(_, status) = conn.get("%s.%d"%(STATUSES_OID, port_num)) - return (status==str(STATUS_UP) and "on" or "off") + return status == str(STATUS_UP) and "on" or "off"
def set_power_status(conn, options): global port_num
- if (port_num==None): + if port_num == None: port_num = port2index(conn, options["--plug"])
conn.set("%s.%d"%(STATUSES_OID, port_num), (options["--action"]=="on" and STATUS_UP or STATUS_DOWN)) diff --git a/fence/agents/intelmodular/fence_intelmodular.py b/fence/agents/intelmodular/fence_intelmodular.py index e9ef43c..bdb45b5 100644 --- a/fence/agents/intelmodular/fence_intelmodular.py +++ b/fence/agents/intelmodular/fence_intelmodular.py @@ -40,7 +40,7 @@ STATUS_SET_OFF = 3
def get_power_status(conn, options): (_, status) = conn.get("%s.%s"% (STATUSES_OID, options["--plug"])) - return (status==str(STATUS_UP) and "on" or "off") + return status == str(STATUS_UP) and "on" or "off"
def set_power_status(conn, options): conn.set("%s.%s" % (STATUSES_OID, options["--plug"]), diff --git a/fence/agents/ipdu/fence_ipdu.py b/fence/agents/ipdu/fence_ipdu.py index 913322d..e17d837 100644 --- a/fence/agents/ipdu/fence_ipdu.py +++ b/fence/agents/ipdu/fence_ipdu.py @@ -54,7 +54,7 @@ def ipdu_set_device(conn, options): # First resolve type of PDU device pdu_type = conn.walk(OID_SYS_OBJECT_ID)
- if (not ((len(pdu_type)==1) and (agents_dir.has_key(pdu_type[0][1])))): + if not ((len(pdu_type)==1) and (agents_dir.has_key(pdu_type[0][1]))): pdu_type = [[None, None]]
device = agents_dir[pdu_type[0][1]] @@ -64,41 +64,41 @@ def ipdu_set_device(conn, options): def ipdu_resolv_port_id(conn, options): global port_id, switch_id
- if (device==None): + if device == None: ipdu_set_device(conn, options)
# Now we resolv port_id/switch_id - if ((options["--plug"].isdigit()) and ((not device.has_switches) or (options["--switch"].isdigit()))): + if options["--plug"].isdigit() and ((not device.has_switches) or (options["--switch"].isdigit())): port_id = int(options["--plug"])
- if (device.has_switches): + if device.has_switches: switch_id = int(options["--switch"]) else: table = conn.walk(device.outlet_table_oid, 30)
for x in table: - if (x[1].strip('"')==options["--plug"]): + if x[1].strip('"') == options["--plug"]: t = x[0].split('.') - if (device.has_switches): + if device.has_switches: port_id = int(t[len(t)-1]) switch_id = int(t[len(t)-3]) else: port_id = int(t[len(t)-1])
- if (port_id==None): + if port_id == None: fail_usage("Can't find port with name %s!"%(options["--plug"]))
def get_power_status(conn, options): - if (port_id==None): + if port_id == None: ipdu_resolv_port_id(conn, options)
oid = ((device.has_switches) and device.status_oid%(switch_id, port_id) or device.status_oid%(port_id))
(oid, status) = conn.get(oid) - return (status==str(device.state_on) and "on" or "off") + return status == str(device.state_on) and "on" or "off"
def set_power_status(conn, options): - if (port_id==None): + if port_id == None: ipdu_resolv_port_id(conn, options)
oid = ((device.has_switches) and device.control_oid%(switch_id, port_id) or device.control_oid%(port_id)) @@ -109,7 +109,7 @@ def set_power_status(conn, options): def get_outlets_status(conn, options): result = {}
- if (device == None): + if device == None: ipdu_set_device(conn, options)
res_ports = conn.walk(device.outlet_table_oid, 30) diff --git a/fence/agents/ldom/fence_ldom.py b/fence/agents/ldom/fence_ldom.py index 65c810b..5e046df 100644 --- a/fence/agents/ldom/fence_ldom.py +++ b/fence/agents/ldom/fence_ldom.py @@ -46,14 +46,14 @@ def get_power_status(conn, options): for line in conn.before.splitlines(): domain = re.search(r"^(\S+)\s+(\S+)\s+.*$", line)
- if (domain!=None): - if ((fa_status==0) and (domain.group(1)=="NAME") and (domain.group(2)=="STATE")): + if domain != None: + if fa_status == 0 and domain.group(1) == "NAME" and domain.group(2) == "STATE": fa_status = 1 - elif (fa_status==1): + elif fa_status == 1: result[domain.group(1)] = ("", (domain.group(2).lower()=="bound" and "off" or "on"))
- if (not (options["--action"] in ['monitor','list'])): - if (not (options["--plug"] in result)): + if not options["--action"] in ['monitor','list']: + if not options["--plug"] in result: fail_usage("Failed: You have to enter existing logical domain!") else: return result[options["--plug"]][1] diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py index a37cd0d..56a8a1a 100644 --- a/fence/agents/lib/fencing.py.py +++ b/fence/agents/lib/fencing.py.py @@ -495,7 +495,7 @@ def metadata(avail_opt, options, docs): mixed = all_opt[option]["help"] ## split it between option and help text res = re.compile(r"^(.*--\S+)\s+", re.IGNORECASE | re.S).search(mixed) - if (None != res): + if None != res: mixed = res.group(1) mixed = mixed.replace("<", "<").replace(">", ">") print "\t\t<getopt mixed="" + mixed + "" />" @@ -596,7 +596,7 @@ def process_input(avail_opt): name = "" for line in sys.stdin.readlines(): line = line.strip() - if ((line.startswith("#")) or (len(line) == 0)): + if (line.startswith("#")) or (len(line) == 0): continue
(name, value) = (line + "=").split("=", 1) @@ -710,7 +710,7 @@ def check_input(device_opt, opt): if device_opt.count("ipaddr") and 0 == options.has_key("--ip") and 0 == options.has_key("--managed"): fail_usage("Failed: You have to enter fence address")
- if (device_opt.count("no_password") == 0): + 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")): fail_usage("Failed: You have to enter password or password script") @@ -850,10 +850,10 @@ def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None
## Process options that manipulate fencing device ##### - if (options["--action"] == "list") and 0 == options["device_opt"].count("port"): + if options["--action"] == "list" and 0 == options["device_opt"].count("port"): print "N/A" return - elif (options["--action"] == "list" and get_outlet_list == None): + elif options["--action"] == "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 @@ -959,13 +959,13 @@ def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None def fence_login(options, re_login_string = r"(login\s*: )|(Login Name: )|(username: )|(User Name :)"): force_ipvx = ""
- if (options.has_key("--inet6-only")): + if options.has_key("--inet6-only"): force_ipvx = "-6 "
- if (options.has_key("--inet4-only")): + if options.has_key("--inet4-only"): force_ipvx = "-4 "
- if (options.has_key("eol") == False): + if not options.has_key("eol"): options["eol"] = "\r\n"
if options.has_key("--command-prompt") and type(options["--command-prompt"]) is not list: @@ -1057,11 +1057,11 @@ def fence_login(options, re_login_string = r"(login\s*: )|(Login Name: )|(usern
## automatically change end of line separator screen = conn.read_nonblocking(size=100, timeout=int(options["--shell-timeout"])) - if (re_login.search(screen) != None): + if re_login.search(screen) != None: options["eol"] = "\n" conn.send_eol(options["--username"]) result = conn.log_expect(options, re_pass, int(options["--login-timeout"])) - elif (re_pass.search(screen) == None): + elif re_pass.search(screen) != None: conn.log_expect(options, re_pass, int(options["--shell-timeout"]))
try: @@ -1074,7 +1074,7 @@ def fence_login(options, re_login_string = r"(login\s*: )|(Login Name: )|(usern conn.send_eol("") screen = conn.read_nonblocking(size=100, timeout=int(options["--shell-timeout"])) ## after sending EOL the fence device can either show 'Login' or 'Password' - if (re_login.search(screen) != None): + if re_login.search(screen) != None: conn.send_eol("") conn.send_eol(options["--username"]) conn.log_expect(options, re_pass, int(options["--login-timeout"])) @@ -1111,7 +1111,7 @@ def run_command(options, command, timeout = None, env = None): thread = threading.Thread(target = process.wait) thread.start() thread.join(timeout) - if (thread.is_alive()): + if thread.is_alive(): process.kill() fail(EC_TIMED_OUT)
diff --git a/fence/agents/lib/fencing_snmp.py.py b/fence/agents/lib/fencing_snmp.py.py index 055c8f2..24ad171 100644 --- a/fence/agents/lib/fencing_snmp.py.py +++ b/fence/agents/lib/fencing_snmp.py.py @@ -42,11 +42,11 @@ class FencingSnmp: res = True
for item in e: - if ((item[0]=='!') and (self.options.has_key("--"+item[1:]))): + if item[0] == '!' and self.options.has_key("--" + item[1:]): res = False break
- if ((item[0]!='!') and (not self.options.has_key("--"+item[0:]))): + if item[0] != '!' and not self.options.has_key("--" + item[0:]): res = False break
@@ -62,7 +62,7 @@ class FencingSnmp: mapping = (('snmp-version', 'v'),('community', 'c'))
for item in mapping: - if (self.options.has_key("--" + item[0])): + if self.options.has_key("--" + item[0]): cmd += " -%s '%s'"% (item[1], self.quote_for_run(self.options["--" + item[0]]))
# Some options make sense only for v3 (and for v1/2c can cause "problems") @@ -71,15 +71,15 @@ class FencingSnmp: mapping_v3 = (('snmp-auth-prot','a'), ('snmp-sec-level','l'), ('snmp-priv-prot','x'), \ ('snmp-priv-passwd','X'),('password','A'),('username','u')) for item in mapping_v3: - if (self.options.has_key("--"+item[0])): + if self.options.has_key("--"+item[0]): cmd += " -%s '%s'"% (item[1], self.quote_for_run(self.options["--" + item[0]]))
force_ipvx = ""
- if (self.options.has_key("--inet6-only")): + if self.options.has_key("--inet6-only"): force_ipvx = "udp6:"
- if (self.options.has_key("--inet4-only")): + if self.options.has_key("--inet4-only"): force_ipvx = "udp:"
cmd += " '%s%s%s'"% (force_ipvx, self.quote_for_run(self.options["--ip"]), @@ -95,7 +95,7 @@ class FencingSnmp: int(self.options["--login-timeout"]) + additional_timemout, True)
- if (res_code==None): + if res_code == None: fail(EC_TIMED_OUT)
self.log_command(res_output) @@ -120,7 +120,7 @@ class FencingSnmp: type_of_value = ''
for item in mapping: - if (isinstance(value, item[0])): + if isinstance(value, item[0]): type_of_value = item[1] break
diff --git a/fence/agents/ovh/fence_ovh.py b/fence/agents/ovh/fence_ovh.py index 24c3972..f4e9caf 100644 --- a/fence/agents/ovh/fence_ovh.py +++ b/fence/agents/ovh/fence_ovh.py @@ -40,7 +40,7 @@ def netboot_reboot(options, mode):
# dedicatedNetbootModifyById changes the mode of the next reboot conn.service.dedicatedNetbootModifyById(options["session"], options["--plug"], mode, '', options["--email"]) - + # dedicatedHardRebootDo initiates a hard reboot on the given node conn.service.dedicatedHardRebootDo(options["session"], options["--plug"], 'Fencing initiated by cluster', '', 'en') @@ -81,7 +81,7 @@ def soap_login(options):
def remove_tmp_dir(tmp_dir): shutil.rmtree(tmp_dir) - + def main(): device_opt = [ "login", "passwd", "port", "email" ]
@@ -134,7 +134,7 @@ Poweroff is simulated with a reboot into rescue-pro mode." reboot_t.end.strftime('%Y-%m-%d %H:%M:%S')) logging.debug("after_netboot_reboot: %s\n" % after_netboot_reboot.strftime('%Y-%m-%d %H:%M:%S')) - + if reboot_t.start < after_netboot_reboot < reboot_t.end: result = 0 logging.debug("Netboot reboot went OK.\n") diff --git a/fence/agents/rhevm/fence_rhevm.py b/fence/agents/rhevm/fence_rhevm.py index 54af81b..8ff5ee9 100644 --- a/fence/agents/rhevm/fence_rhevm.py +++ b/fence/agents/rhevm/fence_rhevm.py @@ -26,14 +26,14 @@ def get_power_status(conn, options): res = send_command(options, "vms/?search=name%3D" + options["--plug"])
result = RE_GET_ID.search(res) - if (result == None): + if result == None: # Unable to obtain ID needed to access virtual machine fail(EC_STATUS)
options["id"] = result.group(2)
result = RE_STATUS.search(res) - if (result == None): + if result == None: # We were able to parse ID so output is correct # in some cases it is possible that RHEV-M output does not # contain <status> line. We can assume machine is OFF then @@ -41,7 +41,7 @@ def get_power_status(conn, options): else: status = result.group(1)
- if (status.lower() == "down"): + if status.lower() == "down": return "off" else: return "on" @@ -94,7 +94,7 @@ def send_command(opt, command, method = "GET"): conn.setopt(pycurl.SSL_VERIFYPEER, 0) conn.setopt(pycurl.SSL_VERIFYHOST, 0)
- if (method == "POST"): + if method == "POST": conn.setopt(pycurl.POSTFIELDS, "<action />")
conn.setopt(pycurl.WRITEFUNCTION, web_buffer.write) diff --git a/fence/agents/rsa/fence_rsa.py b/fence/agents/rsa/fence_rsa.py index ba93709..e163397 100644 --- a/fence/agents/rsa/fence_rsa.py +++ b/fence/agents/rsa/fence_rsa.py @@ -23,7 +23,7 @@ def get_power_status(conn, options): conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
match = re.compile("Power: (.*)", re.IGNORECASE).search(conn.before) - if (match != None): + if match != None: status = match.group(1) else: status = "undefined" diff --git a/fence/agents/rsb/fence_rsb.py b/fence/agents/rsb/fence_rsb.py index b72d295..e9e37de 100755 --- a/fence/agents/rsb/fence_rsb.py +++ b/fence/agents/rsb/fence_rsb.py @@ -18,7 +18,7 @@ def get_power_status(conn, options): conn.send("0") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
- return (status.lower().strip()) + return status.lower().strip()
def set_power_status(conn, options): action = { diff --git a/fence/agents/sanbox2/fence_sanbox2.py b/fence/agents/sanbox2/fence_sanbox2.py index 161e002..c53f1ef 100644 --- a/fence/agents/sanbox2/fence_sanbox2.py +++ b/fence/agents/sanbox2/fence_sanbox2.py @@ -85,7 +85,7 @@ def get_list_devices(conn, options):
list_re = re.compile(r"^\s+(\d+?)\s+(Online|Offline)\s+", re.IGNORECASE) for line in conn.before.splitlines(): - if (list_re.search(line)): + if list_re.search(line): status = { 'online' : "ON", 'offline' : "OFF" @@ -130,7 +130,7 @@ because the connection will block any necessary fencing actions." conn.send_eol("admin start") conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
- if (re.search(r"(admin)", conn.before, re.MULTILINE) == None): + if re.search(r"(admin)", conn.before, re.MULTILINE) == None: ## Someone else is in admin section, we can't enable/disable ## ports so we will rather exit logging.error("Failed: Unable to switch to admin section\n") diff --git a/fence/agents/virsh/fence_virsh.py b/fence/agents/virsh/fence_virsh.py index cbdb399..9f94f58 100644 --- a/fence/agents/virsh/fence_virsh.py +++ b/fence/agents/virsh/fence_virsh.py @@ -38,10 +38,10 @@ def get_outlets_status(conn, options): for line in conn.before.splitlines(): domain = re.search(r"^\s*(\S+)\s+(\S+)\s+(\S+).*$", line)
- if (domain!=None): - if ((fa_status==0) and (domain.group(1).lower()=="id") and (domain.group(2).lower()=="name")): + if domain != None: + if fa_status == 0 and domain.group(1).lower() == "id" and domain.group(2).lower() == "name": fa_status = 1 - elif (fa_status==1): + elif fa_status == 1: result[domain.group(2)] = ("", (domain.group(3).lower() in ["running", "blocked", "idle", "no state", "paused"] and "on" or "off")) return result diff --git a/fence/agents/vmware/fence_vmware.py b/fence/agents/vmware/fence_vmware.py index 80dc122..4576f40 100644 --- a/fence/agents/vmware/fence_vmware.py +++ b/fence/agents/vmware/fence_vmware.py @@ -72,24 +72,24 @@ def dsv_split(dsv_str): tmp_str = ""
for x in dsv_str: - if (status==0): - if (x==delimiter_c): + if status == 0: + if x == delimiter_c: res.append(tmp_str) tmp_str = "" - elif (x==escape_c): + elif x == escape_c: status = 1 else: tmp_str += x - elif (status==1): - if (x==delimiter_c): + elif status == 1: + if x == delimiter_c: tmp_str += delimiter_c - elif (x==escape_c): + elif x == escape_c: tmp_str += escape_c else: tmp_str += escape_c+x status = 0
- if (tmp_str != ""): + if tmp_str != "": res.append(tmp_str)
return res @@ -111,28 +111,28 @@ def quote_for_run(text): def vmware_prepare_command(options, add_login_params, additional_params): res = options["--exec"]
- if (add_login_params): - if (vmware_internal_type==VMWARE_TYPE_ESX): + if add_login_params: + if vmware_internal_type==VMWARE_TYPE_ESX: res += " --server '%s' --username '%s' --password '%s' "% (quote_for_run(options["--ip"]), quote_for_run(options["--username"]), quote_for_run(options["--password"])) - elif (vmware_internal_type==VMWARE_TYPE_SERVER2): + elif vmware_internal_type==VMWARE_TYPE_SERVER2: res += " -h 'https://%s/sdk' -u '%s' -p '%s' -T server "% (quote_for_run(options["--ip"]), quote_for_run(options["--username"]), quote_for_run(options["--password"])) - elif (vmware_internal_type==VMWARE_TYPE_SERVER1): + elif vmware_internal_type==VMWARE_TYPE_SERVER1: host_name_array = options["--ip"].split(':')
res += " -h '%s' -u '%s' -p '%s' -T server1 "% (quote_for_run(host_name_array[0]), quote_for_run(options["--username"]), quote_for_run(options["--password"])) - if (len(host_name_array)>1): + if len(host_name_array) > 1: res += "-P '%s' "% (quote_for_run(host_name_array[1]))
- if ((options.has_key("--vmware-datacenter")) and (vmware_internal_type==VMWARE_TYPE_ESX)): + if options.has_key("--vmware-datacenter") and vmware_internal_type == VMWARE_TYPE_ESX: res += "--datacenter '%s' "% (quote_for_run(options["--vmware-datacenter"]))
- if (additional_params != ""): + if additional_params != "": res += additional_params
return res @@ -153,9 +153,9 @@ def vmware_run_command(options, add_login_params, additional_params, additional_ (res_output, res_code) = pexpect.run(command, int(options["--shell-timeout"]) + int(options["--login-timeout"]) + additional_timeout, True)
- if (res_code==None): + if res_code == None: fail(EC_TIMED_OUT) - if ((res_code!=0) and (add_login_params)): + if res_code != 0 and add_login_params: vmware_log(options, res_output) fail_usage("%s returned %s"% (options["--exec"], res_output)) else: @@ -171,7 +171,7 @@ def vmware_run_command(options, add_login_params, additional_params, additional_ def vmware_get_outlets_vi(options, add_vm_name): outlets = {}
- if (add_vm_name): + if add_vm_name: all_machines = vmware_run_command(options, True, ("--operation status --vmname '%s'"% (quote_for_run(options["--plug"]))), 0) else: @@ -181,11 +181,11 @@ def vmware_get_outlets_vi(options, add_vm_name):
for machine in all_machines_array: machine_array = dsv_split(machine) - if (len(machine_array) == 4): - if (machine_array[0] in outlets): + if len(machine_array) == 4: + if machine_array[0] in outlets: fail_usage("Failed. More machines with same name %s found!"%(machine_array[0]))
- if (vmware_disconnected_hack): + if vmware_disconnected_hack: outlets[machine_array[0]] = ("", ( ((machine_array[2].lower() in ["poweredon"]) and (machine_array[3].lower()=="connected")) @@ -201,14 +201,14 @@ def vmware_get_outlets_vix(options): running_machines = vmware_run_command(options, True, "list", 0) running_machines_array = running_machines.splitlines()[1:]
- if (vmware_internal_type==VMWARE_TYPE_SERVER2): + if vmware_internal_type == VMWARE_TYPE_SERVER2: all_machines = vmware_run_command(options, True, "listRegisteredVM", 0) all_machines_array = all_machines.splitlines()[1:] - elif (vmware_internal_type==VMWARE_TYPE_SERVER1): + elif vmware_internal_type == VMWARE_TYPE_SERVER1: all_machines_array = running_machines_array
for machine in all_machines_array: - if (machine!=""): + if machine != "": outlets[machine] = ("", ((machine in running_machines_array) and "on" or "off"))
return outlets @@ -216,35 +216,35 @@ def vmware_get_outlets_vix(options): def get_outlets_status(conn, options): del conn
- if (vmware_internal_type==VMWARE_TYPE_ESX): + if vmware_internal_type == VMWARE_TYPE_ESX: return vmware_get_outlets_vi(options, False) - if ((vmware_internal_type==VMWARE_TYPE_SERVER1) or (vmware_internal_type==VMWARE_TYPE_SERVER2)): + if vmware_internal_type == VMWARE_TYPE_SERVER1 or vmware_internal_type == VMWARE_TYPE_SERVER2: return vmware_get_outlets_vix(options)
def get_power_status(conn, options): - if (vmware_internal_type==VMWARE_TYPE_ESX): + if vmware_internal_type == VMWARE_TYPE_ESX: outlets = vmware_get_outlets_vi(options, True) else: outlets = get_outlets_status(conn, options)
- if ((vmware_internal_type==VMWARE_TYPE_SERVER2) or (vmware_internal_type==VMWARE_TYPE_ESX)): - if (not (options["--plug"] in outlets)): + if vmware_internal_type == VMWARE_TYPE_SERVER2 or vmware_internal_type == VMWARE_TYPE_ESX: + if not options["--plug"] in outlets: fail_usage("Failed: You have to enter existing name of virtual machine!") else: return outlets[options["--plug"]][1] - elif (vmware_internal_type==VMWARE_TYPE_SERVER1): - return ((options["--plug"] in outlets) and "on" or "off") + elif vmware_internal_type == VMWARE_TYPE_SERVER1: + return (options["--plug"] in outlets) and "on" or "off"
def set_power_status(conn, options): del conn
- if (vmware_internal_type==VMWARE_TYPE_ESX): + if vmware_internal_type == VMWARE_TYPE_ESX: additional_params = "--operation %s --vmname '%s'" % \ ((options["--action"]=="on" and "on" or "off"), quote_for_run(options["--plug"])) - elif ((vmware_internal_type==VMWARE_TYPE_SERVER1) or (vmware_internal_type==VMWARE_TYPE_SERVER2)): + elif vmware_internal_type == VMWARE_TYPE_SERVER1 or vmware_internal_type == VMWARE_TYPE_SERVER2: additional_params = "%s '%s'" % \ ((options["--action"]=="on" and "start" or "stop"), quote_for_run(options["--plug"])) - if (options["--action"]=="off"): + if options["--action"] == "off": additional_params += " hard"
vmware_run_command(options, True, additional_params, int(options["--power-timeout"])) @@ -253,13 +253,13 @@ def set_power_status(conn, options): def vmware_is_supported_vmrun_version(options): vmware_help_str = vmware_run_command(options, False, "", 0) version_re = re.search(r"vmrun version (\d.(\d[.]*)*)", vmware_help_str.lower()) - if (version_re==None): + if version_re == None: return False # Looks like this "vmrun" is not real vmrun
version_array = version_re.group(1).split(".")
try: - if (int(version_array[0]) < VMRUN_MINIMUM_REQUIRED_VERSION): + if int(version_array[0]) < VMRUN_MINIMUM_REQUIRED_VERSION: return False except Exception: return False @@ -273,17 +273,17 @@ def vmware_check_vmware_type(options):
options["--vmware_type"] = options["--vmware_type"].lower()
- if (options["--vmware_type"]=="esx"): + if options["--vmware_type"] == "esx": vmware_internal_type = VMWARE_TYPE_ESX - if (not options.has_key("--exec")): + if not options.has_key("--exec"): options["--exec"] = VMHELPER_COMMAND - elif (options["--vmware_type"]=="server2"): + elif options["--vmware_type"] == "server2": vmware_internal_type = VMWARE_TYPE_SERVER2 - if (not options.has_key("--exec")): + if not options.has_key("--exec"): options["--exec"] = VMRUN_COMMAND - elif (options["--vmware_type"]=="server1"): + elif options["--vmware_type"] == "server1": vmware_internal_type = VMWARE_TYPE_SERVER1 - if (not options.has_key("--exec")): + if not options.has_key("--exec"): options["--exec"] = VMRUN_COMMAND else: fail_usage("vmware_type can be esx,server2 or server1!") @@ -330,8 +330,8 @@ This agent supports only vmrun from version 2.0.0 (VIX API 1.6.0)." vmware_check_vmware_type(options)
# Test user vmrun command version - if ((vmware_internal_type==VMWARE_TYPE_SERVER1) or (vmware_internal_type==VMWARE_TYPE_SERVER2)): - if (not (vmware_is_supported_vmrun_version(options))): + if vmware_internal_type == VMWARE_TYPE_SERVER1 or vmware_internal_type == VMWARE_TYPE_SERVER2: + if not vmware_is_supported_vmrun_version(options): fail_usage("Unsupported version of vmrun command! You must use at least version %d!" % (VMRUN_MINIMUM_REQUIRED_VERSION))
diff --git a/fence/agents/vmware_soap/fence_vmware_soap.py b/fence/agents/vmware_soap/fence_vmware_soap.py index ccdbac1..feba447 100644 --- a/fence/agents/vmware_soap/fence_vmware_soap.py +++ b/fence/agents/vmware_soap/fence_vmware_soap.py @@ -107,7 +107,7 @@ def get_power_status(conn, options): (machines, uuid, mappingToUUID) = process_results(raw_machines, {}, {}, {})
# Probably need to loop over the ContinueRetreive if there are more results after 1 iteration. - while (hasattr(raw_machines, 'token') == True): + while hasattr(raw_machines, 'token'): try: raw_machines = conn.service.ContinueRetrievePropertiesEx(mo_PropertyCollector, raw_machines.token) except Exception: @@ -169,7 +169,7 @@ def set_power_status(conn, options): else: conn.service.PowerOffVM_Task(mo_machine) except suds.WebFault, ex: - if ((str(ex).find("Permission to perform this operation was denied")) >= 0): + if (str(ex).find("Permission to perform this operation was denied")) >= 0: fail(EC_INVALID_PRIVILEGES) else: if options["--action"] == "on": diff --git a/fence/agents/wti/fence_wti.py b/fence/agents/wti/fence_wti.py index d502a0e..a7e1c8f 100644 --- a/fence/agents/wti/fence_wti.py +++ b/fence/agents/wti/fence_wti.py @@ -67,9 +67,9 @@ def get_plug_status(conn, options): ## We already believe that first column contains plug number if len(plug_line[0]) != 0: outlets[plug_line[0]] = (plug_line[name_index], plug_line[status_index]) - elif (plug_section == 1): + elif plug_section == 1: plug_section = 2 - elif (line.upper().startswith("PLUG")): + elif line.upper().startswith("PLUG"): plug_section = 1 plug_header = [x.strip().lower() for x in line.split("|")] plug_index = plug_header.index("plug") @@ -99,7 +99,7 @@ def get_plug_group_status(conn, options): 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): + 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]: @@ -137,7 +137,7 @@ def get_plug_group_status(conn, options): outlets[group_name] = (group_name, get_plug_group_status_from_list(plug_status)) line_index += 1
- elif (line.upper().lstrip().startswith("GROUP NAME")): + elif line.upper().lstrip().startswith("GROUP NAME"): plug_header = [x.strip().lower() for x in line.split("|")] name_index = plug_header.index("group name") plug_index = plug_header.index("plug") diff --git a/fence/agents/xenapi/fence_xenapi.py b/fence/agents/xenapi/fence_xenapi.py index 2a52c98..0a4f838 100644 --- a/fence/agents/xenapi/fence_xenapi.py +++ b/fence/agents/xenapi/fence_xenapi.py @@ -58,7 +58,7 @@ def get_power_fn(session, options): record = session.xenapi.VM.get_record(vm) # Check that we are not trying to manipulate a template or a control # domain as they show up as VM's with specific properties. - if not(record["is_a_template"]) and not(record["is_control_domain"]): + if not record["is_a_template"] and not record["is_control_domain"]: status = record["power_state"] if verbose: print "UUID:", record["uuid"], "NAME:", record["name_label"], "POWER STATUS:", record["power_state"] @@ -70,7 +70,7 @@ def get_power_fn(session, options): # We want to make sure that we only return the status "off" if the machine is actually halted as the status # is checked before a fencing action. Only when the machine is Halted is it not consuming resources which # may include whatever you are trying to protect with this fencing action. - return (status=="Halted" and "off" or "on") + return status == "Halted" and "off" or "on" except Exception, exn: print str(exn)
@@ -87,14 +87,14 @@ def set_power_fn(session, options): record = session.xenapi.VM.get_record(vm) # Check that we are not trying to manipulate a template or a control # domain as they show up as VM's with specific properties. - if not(record["is_a_template"]) and not(record["is_control_domain"]): - if( action == "on" ): + if not record["is_a_template"] and not record["is_control_domain"]: + if action == "on": # Start the VM session.xenapi.VM.start(vm, False, True) - elif( action == "off" ): + elif action == "off": # Force shutdown the VM session.xenapi.VM.hard_shutdown(vm) - elif( action == "reboot" ): + elif action == "reboot": # Force reboot the VM session.xenapi.VM.hard_reboot(vm) except Exception, exn: @@ -116,7 +116,7 @@ def get_outlet_list(session, options): record = session.xenapi.VM.get_record(vm) # Check that we are not trying to manipulate a template or a control # domain as they show up as VM's with specific properties. - if not(record["is_a_template"]) and not(record["is_control_domain"]): + if not record["is_a_template"] and not record["is_control_domain"]: name = record["name_label"] uuid = record["uuid"] status = record["power_state"]
cluster-commits@lists.fedorahosted.org