Performance improvement using in-operator on dicts
Just a small cleanup for the existing occurrences. Using the in-operator for hash lookups is faster than using .keys() http://stackoverflow.com/questions/29314269/why-do-key-in-dict-and-key-in-dict-keys-have-the-same-output
This commit is contained in:
parent
b06003e5d2
commit
a417a4f4b3
3 changed files with 12 additions and 12 deletions
|
@ -715,22 +715,22 @@ class RHEVConn(object):
|
||||||
for iface in ifaces:
|
for iface in ifaces:
|
||||||
try:
|
try:
|
||||||
setMsg('creating host interface ' + iface['name'])
|
setMsg('creating host interface ' + iface['name'])
|
||||||
if 'management' in iface.keys():
|
if 'management' in iface:
|
||||||
manageip = iface['ip']
|
manageip = iface['ip']
|
||||||
if 'boot_protocol' not in iface.keys():
|
if 'boot_protocol' not in iface:
|
||||||
if 'ip' in iface.keys():
|
if 'ip' in iface:
|
||||||
iface['boot_protocol'] = 'static'
|
iface['boot_protocol'] = 'static'
|
||||||
else:
|
else:
|
||||||
iface['boot_protocol'] = 'none'
|
iface['boot_protocol'] = 'none'
|
||||||
if 'ip' not in iface.keys():
|
if 'ip' not in iface:
|
||||||
iface['ip'] = ''
|
iface['ip'] = ''
|
||||||
if 'netmask' not in iface.keys():
|
if 'netmask' not in iface:
|
||||||
iface['netmask'] = ''
|
iface['netmask'] = ''
|
||||||
if 'gateway' not in iface.keys():
|
if 'gateway' not in iface:
|
||||||
iface['gateway'] = ''
|
iface['gateway'] = ''
|
||||||
|
|
||||||
if 'network' in iface.keys():
|
if 'network' in iface:
|
||||||
if 'bond' in iface.keys():
|
if 'bond' in iface:
|
||||||
bond = []
|
bond = []
|
||||||
for slave in iface['bond']:
|
for slave in iface['bond']:
|
||||||
bond.append(ifacelist[slave])
|
bond.append(ifacelist[slave])
|
||||||
|
|
|
@ -196,10 +196,10 @@ class HAProxy(object):
|
||||||
"""
|
"""
|
||||||
Capture the output for a command
|
Capture the output for a command
|
||||||
"""
|
"""
|
||||||
if not 'command' in self.command_results.keys():
|
if 'command' not in self.command_results:
|
||||||
self.command_results['command'] = []
|
self.command_results['command'] = []
|
||||||
self.command_results['command'].append(cmd)
|
self.command_results['command'].append(cmd)
|
||||||
if not 'output' in self.command_results.keys():
|
if 'output' not in self.command_results:
|
||||||
self.command_results['output'] = []
|
self.command_results['output'] = []
|
||||||
self.command_results['output'].append(output)
|
self.command_results['output'].append(output)
|
||||||
|
|
||||||
|
|
|
@ -153,7 +153,7 @@ def lookup_adminstatus(int_adminstatus):
|
||||||
2: 'down',
|
2: 'down',
|
||||||
3: 'testing'
|
3: 'testing'
|
||||||
}
|
}
|
||||||
if int_adminstatus in adminstatus_options.keys():
|
if int_adminstatus in adminstatus_options:
|
||||||
return adminstatus_options[int_adminstatus]
|
return adminstatus_options[int_adminstatus]
|
||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
|
@ -168,7 +168,7 @@ def lookup_operstatus(int_operstatus):
|
||||||
6: 'notPresent',
|
6: 'notPresent',
|
||||||
7: 'lowerLayerDown'
|
7: 'lowerLayerDown'
|
||||||
}
|
}
|
||||||
if int_operstatus in operstatus_options.keys():
|
if int_operstatus in operstatus_options:
|
||||||
return operstatus_options[int_operstatus]
|
return operstatus_options[int_operstatus]
|
||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
|
|
Loading…
Reference in a new issue