mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 04:11:25 -07:00
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
c843eeabc2
commit
54fdff16db
9 changed files with 10 additions and 10 deletions
|
@ -461,7 +461,7 @@ def create_instances(module, gce, instance_names, number):
|
||||||
bad_perms = []
|
bad_perms = []
|
||||||
if service_account_permissions:
|
if service_account_permissions:
|
||||||
for perm in service_account_permissions:
|
for perm in service_account_permissions:
|
||||||
if perm not in gce.SA_SCOPES_MAP.keys():
|
if perm not in gce.SA_SCOPES_MAP:
|
||||||
bad_perms.append(perm)
|
bad_perms.append(perm)
|
||||||
if len(bad_perms) > 0:
|
if len(bad_perms) > 0:
|
||||||
module.fail_json(msg='bad permissions: %s' % str(bad_perms))
|
module.fail_json(msg='bad permissions: %s' % str(bad_perms))
|
||||||
|
|
|
@ -1268,7 +1268,7 @@ def state_present(module, existing, proposed, candidate):
|
||||||
elif value is False:
|
elif value is False:
|
||||||
commands.append('no {0}'.format(key))
|
commands.append('no {0}'.format(key))
|
||||||
elif value == 'default':
|
elif value == 'default':
|
||||||
if key in PARAM_TO_DEFAULT_KEYMAP.keys():
|
if key in PARAM_TO_DEFAULT_KEYMAP:
|
||||||
commands.append('{0} {1}'.format(key, PARAM_TO_DEFAULT_KEYMAP[key]))
|
commands.append('{0} {1}'.format(key, PARAM_TO_DEFAULT_KEYMAP[key]))
|
||||||
elif existing_commands.get(key):
|
elif existing_commands.get(key):
|
||||||
existing_value = existing_commands.get(key)
|
existing_value = existing_commands.get(key)
|
||||||
|
|
|
@ -1418,7 +1418,7 @@ def state_present(module, existing, proposed, candidate):
|
||||||
commands.append('no {0}'.format(key))
|
commands.append('no {0}'.format(key))
|
||||||
|
|
||||||
elif value == 'default':
|
elif value == 'default':
|
||||||
if key in PARAM_TO_DEFAULT_KEYMAP.keys():
|
if key in PARAM_TO_DEFAULT_KEYMAP:
|
||||||
commands.append('{0} {1}'.format(key, PARAM_TO_DEFAULT_KEYMAP[key]))
|
commands.append('{0} {1}'.format(key, PARAM_TO_DEFAULT_KEYMAP[key]))
|
||||||
|
|
||||||
elif existing_commands.get(key):
|
elif existing_commands.get(key):
|
||||||
|
|
|
@ -877,7 +877,7 @@ def get_available_features(feature, module):
|
||||||
if 'enabled' in state:
|
if 'enabled' in state:
|
||||||
state = 'enabled'
|
state = 'enabled'
|
||||||
|
|
||||||
if feature not in available_features.keys():
|
if feature not in available_features:
|
||||||
available_features[feature] = state
|
available_features[feature] = state
|
||||||
else:
|
else:
|
||||||
if (available_features[feature] == 'disabled' and
|
if (available_features[feature] == 'disabled' and
|
||||||
|
@ -963,7 +963,7 @@ def main():
|
||||||
state = module.params['state'].lower()
|
state = module.params['state'].lower()
|
||||||
|
|
||||||
available_features = get_available_features(feature, module)
|
available_features = get_available_features(feature, module)
|
||||||
if feature not in available_features.keys():
|
if feature not in available_features:
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg='Invalid feature name.',
|
msg='Invalid feature name.',
|
||||||
features_currently_supported=available_features,
|
features_currently_supported=available_features,
|
||||||
|
|
|
@ -1343,7 +1343,7 @@ def main():
|
||||||
|
|
||||||
if state == 'absent':
|
if state == 'absent':
|
||||||
for each in CANNOT_ABSENT:
|
for each in CANNOT_ABSENT:
|
||||||
if each in proposed.keys():
|
if each in proposed:
|
||||||
module.fail_json(msg='only params: oif_prefix, oif_source, '
|
module.fail_json(msg='only params: oif_prefix, oif_source, '
|
||||||
'oif_routemap can be used when '
|
'oif_routemap can be used when '
|
||||||
'state=absent')
|
'state=absent')
|
||||||
|
|
|
@ -1081,7 +1081,7 @@ def get_config_ip_commands(delta, interface, existing, version):
|
||||||
# loop used in the situation that just an IP address or just a
|
# loop used in the situation that just an IP address or just a
|
||||||
# mask is changing, not both.
|
# mask is changing, not both.
|
||||||
for each in ['addr', 'mask']:
|
for each in ['addr', 'mask']:
|
||||||
if each not in delta.keys():
|
if each not in delta:
|
||||||
delta[each] = existing[each]
|
delta[each] = existing[each]
|
||||||
|
|
||||||
if version == 'v4':
|
if version == 'v4':
|
||||||
|
|
|
@ -852,7 +852,7 @@ def get_existing(module, prefix, warnings):
|
||||||
group_route = match_route.groupdict()
|
group_route = match_route.groupdict()
|
||||||
|
|
||||||
for key in key_map:
|
for key in key_map:
|
||||||
if key not in group_route.keys():
|
if key not in group_route:
|
||||||
group_route[key] = ''
|
group_route[key] = ''
|
||||||
group_route['prefix'] = prefix
|
group_route['prefix'] = prefix
|
||||||
group_route['vrf'] = module.params['vrf']
|
group_route['vrf'] = module.params['vrf']
|
||||||
|
|
|
@ -1013,7 +1013,7 @@ def main():
|
||||||
if vpc:
|
if vpc:
|
||||||
mapping = get_existing_portchannel_to_vpc_mappings(module)
|
mapping = get_existing_portchannel_to_vpc_mappings(module)
|
||||||
|
|
||||||
if vpc in mapping.keys() and portchannel != mapping[vpc].strip('Po'):
|
if vpc in mapping and portchannel != mapping[vpc].strip('Po'):
|
||||||
module.fail_json(msg="This vpc is already configured on "
|
module.fail_json(msg="This vpc is already configured on "
|
||||||
"another portchannel. Remove it first "
|
"another portchannel. Remove it first "
|
||||||
"before trying to assign it here. ",
|
"before trying to assign it here. ",
|
||||||
|
|
|
@ -877,7 +877,7 @@ def latest(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos):
|
||||||
# or virtual provides (like "python-*" or "smtp-daemon") while
|
# or virtual provides (like "python-*" or "smtp-daemon") while
|
||||||
# updates contains name only.
|
# updates contains name only.
|
||||||
this_name_only = '-'.join(this.split('-')[:-2])
|
this_name_only = '-'.join(this.split('-')[:-2])
|
||||||
if spec in pkgs['update'] and this_name_only in updates.keys():
|
if spec in pkgs['update'] and this_name_only in updates:
|
||||||
nothing_to_do = False
|
nothing_to_do = False
|
||||||
will_update.add(spec)
|
will_update.add(spec)
|
||||||
# Massage the updates list
|
# Massage the updates list
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue