Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed dict.iteritems() in modules. #18859

Merged
merged 1 commit into from
Dec 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/ansible/modules/cloud/amazon/dynamodb_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,14 @@ def update_dynamo_table(table, throughput=None, check_mode=False, global_indexes
removed_indexes, added_indexes, index_throughput_changes = get_changed_global_indexes(table, global_indexes)
if removed_indexes:
if not check_mode:
for name, index in removed_indexes.iteritems():
for name, index in removed_indexes.items():
global_indexes_changed = table.delete_global_secondary_index(name) or global_indexes_changed
else:
global_indexes_changed = True

if added_indexes:
if not check_mode:
for name, index in added_indexes.iteritems():
for name, index in added_indexes.items():
global_indexes_changed = table.create_global_secondary_index(global_index=index) or global_indexes_changed
else:
global_indexes_changed = True
Expand Down Expand Up @@ -328,18 +328,18 @@ def get_changed_global_indexes(table, global_indexes):
set_index_info = dict((index.name, index.schema()) for index in global_indexes)
set_index_objects = dict((index.name, index) for index in global_indexes)

removed_indexes = dict((name, index) for name, index in table_index_info.iteritems() if name not in set_index_info)
added_indexes = dict((name, set_index_objects[name]) for name, index in set_index_info.iteritems() if name not in table_index_info)
removed_indexes = dict((name, index) for name, index in table_index_info.items() if name not in set_index_info)
added_indexes = dict((name, set_index_objects[name]) for name, index in set_index_info.items() if name not in table_index_info)
# todo: uncomment once boto has https://github.com/boto/boto/pull/3447 fixed
# index_throughput_changes = dict((name, index.throughput) for name, index in set_index_objects.iteritems() if name not in added_indexes and (index.throughput['read'] != str(table_index_objects[name].throughput['read']) or index.throughput['write'] != str(table_index_objects[name].throughput['write'])))
# index_throughput_changes = dict((name, index.throughput) for name, index in set_index_objects.items() if name not in added_indexes and (index.throughput['read'] != str(table_index_objects[name].throughput['read']) or index.throughput['write'] != str(table_index_objects[name].throughput['write'])))
# todo: remove once boto has https://github.com/boto/boto/pull/3447 fixed
index_throughput_changes = dict((name, index.throughput) for name, index in set_index_objects.iteritems() if name not in added_indexes)
index_throughput_changes = dict((name, index.throughput) for name, index in set_index_objects.items() if name not in added_indexes)

return removed_indexes, added_indexes, index_throughput_changes


def validate_index(index, module):
for key, val in index.iteritems():
for key, val in index.items():
if key not in INDEX_OPTIONS:
module.fail_json(msg='%s is not a valid option for an index' % key)
for required_option in INDEX_REQUIRED_OPTIONS:
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/cloud/amazon/ec2_asg.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def create_autoscaling_group(connection, module):

asg_tags = []
for tag in set_tags:
for k,v in tag.iteritems():
for k,v in tag.items():
if k !='propagate_at_launch':
asg_tags.append(Tag(key=k,
value=v,
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/cloud/amazon/ec2_asg_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
HAS_BOTO3 = False

def match_asg_tags(tags_to_match, asg):
for key, value in tags_to_match.iteritems():
for key, value in tags_to_match.items():
for tag in asg['Tags']:
if key == tag['Key'] and value == tag['Value']:
break
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/modules/cloud/amazon/ec2_elb_lb.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ def _set_health_check(self):
if not self.elb.health_check:
self.elb.health_check = HealthCheck()

for attr, desired_value in health_check_config.iteritems():
for attr, desired_value in health_check_config.items():
if getattr(self.elb.health_check, attr) != desired_value:
setattr(self.elb.health_check, attr, desired_value)
update_health_check = True
Expand Down Expand Up @@ -950,7 +950,7 @@ def _set_access_log(self):
}

update_access_logs_config = False
for attr, desired_value in access_logs_config.iteritems():
for attr, desired_value in access_logs_config.items():
if getattr(attributes.access_log, attr) != desired_value:
setattr(attributes.access_log, attr, desired_value)
update_access_logs_config = True
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/cloud/amazon/ec2_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _fetch(self, url):

def _mangle_fields(self, fields, uri, filter_patterns=['public-keys-0']):
new_fields = {}
for key, value in fields.iteritems():
for key, value in fields.items():
split_fields = key[len(uri):].split('/')
if len(split_fields) > 1 and split_fields[1]:
new_key = "-".join(split_fields)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def list_dhcp_options(client, module):

if module.params.get('filters'):
params['Filters'] = []
for key, value in module.params.get('filters').iteritems():
for key, value in module.params.get('filters').items():
temp_dict = dict()
temp_dict['Name'] = key
if isinstance(value, basestring):
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/modules/cloud/amazon/ec2_vpc_nacl.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def icmp_present(entry):
def load_tags(module):
tags = []
if module.params.get('tags'):
for name, value in module.params.get('tags').iteritems():
for name, value in module.params.get('tags').items():
tags.append({'Key': name, 'Value': str(value)})
tags.append({'Key': "Name", 'Value': module.params.get('name')})
else:
Expand Down Expand Up @@ -239,7 +239,7 @@ def tags_changed(nacl_id, client, module):
if nacl['NetworkAcls']:
nacl_values = [t.values() for t in nacl['NetworkAcls'][0]['Tags']]
nacl_tags = [item for sublist in nacl_values for item in sublist]
tag_values = [[key, str(value)] for key, value in tags.iteritems()]
tag_values = [[key, str(value)] for key, value in tags.items()]
tags = [item for sublist in tag_values for item in sublist]
if sorted(nacl_tags) == sorted(tags):
changed = False
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/modules/cloud/amazon/ec2_vpc_peer.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def tags_changed(pcx_id, client, module):
if pcx['VpcPeeringConnections']:
pcx_values = [t.values() for t in pcx['VpcPeeringConnections'][0]['Tags']]
pcx_tags = [item for sublist in pcx_values for item in sublist]
tag_values = [[key, str(value)] for key, value in tags.iteritems()]
tag_values = [[key, str(value)] for key, value in tags.items()]
tags = [item for sublist in tag_values for item in sublist]
if sorted(pcx_tags) == sorted(tags):
changed = False
Expand Down Expand Up @@ -305,7 +305,7 @@ def accept_reject_delete(state, client, module):
def load_tags(module):
tags = []
if module.params.get('tags'):
for name, value in module.params.get('tags').iteritems():
for name, value in module.params.get('tags').items():
tags.append({'Key': name, 'Value': str(value)})
return tags

Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/cloud/amazon/ec2_vpc_route_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def get_resource_tags(vpc_conn, resource_id):

def tags_match(match_tags, candidate_tags):
return all((k in candidate_tags and candidate_tags[k] == v
for k, v in match_tags.iteritems()))
for k, v in match_tags.items()))


def ensure_tags(vpc_conn, resource_id, tags, add_only, check_mode):
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/cloud/amazon/ec2_vpc_vgw.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def load_tags(module):
tags = []

if module.params.get('tags'):
for name, value in module.params.get('tags').iteritems():
for name, value in module.params.get('tags').items():
tags.append({'Key': name, 'Value': str(value)})
tags.append({'Key': "Name", 'Value': module.params.get('name')})
else:
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/modules/cloud/amazon/ecs_taskdefinition.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def main():

def _right_has_values_of_left(left, right):
# Make sure the values are equivalent for everything left has
for k, v in left.iteritems():
for k, v in left.items():
if not ((not v and (k not in right or not right[k])) or (k in right and v == right[k])):
# We don't care about list ordering because ECS can change things
if isinstance(v, list) and k in right:
Expand All @@ -261,7 +261,7 @@ def _right_has_values_of_left(left, right):
return False

# Make sure right doesn't have anything that left doesn't
for k, v in right.iteritems():
for k, v in right.items():
if v and k not in left:
return False

Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/modules/cloud/amazon/elasticache.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def _requires_modification(self):
'NumCacheNodes': self.num_nodes,
'EngineVersion': self.cache_engine_version
}
for key, value in modifiable_data.iteritems():
for key, value in modifiable_data.items():
if value is not None and self.data[key] != value:
return True

Expand Down Expand Up @@ -419,7 +419,7 @@ def _requires_destroy_and_create(self):
# Only check for modifications if zone is specified
if self.zone is not None:
unmodifiable_data['zone'] = self.data['PreferredAvailabilityZone']
for key, value in unmodifiable_data.iteritems():
for key, value in unmodifiable_data.items():
if getattr(self, key) is not None and getattr(self, key) != value:
return True
return False
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/cloud/amazon/s3_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def create_tags_container(tags):

tag_set = TagSet()
tags_obj = Tags()
for key, val in tags.iteritems():
for key, val in tags.items():
tag_set.add_tag(key, val)

tags_obj.add_tag_set(tag_set)
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/cloud/cloudstack/cs_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def run(self):
result = {}
filter = module.params.get('filter')
if not filter:
for key,path in self.fact_paths.iteritems():
for key,path in self.fact_paths.items():
result[key] = self._fetch(CS_METADATA_BASE_URL + "/" + path)
result['cloudstack_user_data'] = self._get_user_data_json()
else:
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/cloud/cloudstack/cs_portforward.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def get_result(self, portforwarding_rule):
super(AnsibleCloudStackPortforwarding, self).get_result(portforwarding_rule)
if portforwarding_rule:
# Bad bad API does not always return int when it should.
for search_key, return_key in self.returns_to_int.iteritems():
for search_key, return_key in self.returns_to_int.items():
if search_key in portforwarding_rule:
self.result[return_key] = int(portforwarding_rule[search_key])
return self.result
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/cloud/digital_ocean/digital_ocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def is_powered_on(self):

def update_attr(self, attrs=None):
if attrs:
for k, v in attrs.iteritems():
for k, v in attrs.items():
setattr(self, k, v)
else:
json = self.manager.show_droplet(self.id)
Expand Down
20 changes: 10 additions & 10 deletions lib/ansible/modules/cloud/docker/_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,11 +902,11 @@ def get_environment(self, env, env_file):
self.ensure_capability('env_file')
parsed_env_file = docker.utils.parse_env_file(env_file)

for name, value in parsed_env_file.iteritems():
for name, value in parsed_env_file.items():
final_env[name] = str(value)

if env:
for name, value in env.iteritems():
for name, value in env.items():
final_env[name] = str(value)

return final_env
Expand Down Expand Up @@ -998,7 +998,7 @@ def get_start_params(self):
self.ensure_capability('log_driver')
log_config = docker.utils.LogConfig(type=docker.utils.LogConfig.types.JSON)
if optionals['log_opt'] is not None:
for k, v in optionals['log_opt'].iteritems():
for k, v in optionals['log_opt'].items():
log_config.set_config_value(k, v)
log_config.type = optionals['log_driver']
params['log_config'] = log_config
Expand Down Expand Up @@ -1073,7 +1073,7 @@ def get_summary_message(self):
'''

parts = []
for k, v in self.counters.iteritems():
for k, v in self.counters.items():
if v == 0:
continue

Expand All @@ -1100,7 +1100,7 @@ def get_reload_reason_message(self):

def get_summary_counters_msg(self):
msg = ""
for k, v in self.counters.iteritems():
for k, v in self.counters.items():
msg = msg + "%s %d " % (k, v)

return msg
Expand All @@ -1109,7 +1109,7 @@ def increment_counter(self, name):
self.counters[name] = self.counters[name] + 1

def has_changed(self):
for k, v in self.counters.iteritems():
for k, v in self.counters.items():
if v > 0:
return True

Expand Down Expand Up @@ -1287,7 +1287,7 @@ def get_differing_containers(self):
expected_env[name] = value

if self.environment:
for name, value in self.environment.iteritems():
for name, value in self.environment.items():
expected_env[name] = str(value)

actual_env = {}
Expand All @@ -1304,7 +1304,7 @@ def get_differing_containers(self):
# LABELS

expected_labels = {}
for name, value in self.module.params.get('labels').iteritems():
for name, value in self.module.params.get('labels').items():
expected_labels[name] = str(value)

if isinstance(container['Config']['Labels'], dict):
Expand Down Expand Up @@ -1401,7 +1401,7 @@ def get_differing_containers(self):

expected_bound_ports = {}
if self.port_bindings:
for container_port, config in self.port_bindings.iteritems():
for container_port, config in self.port_bindings.items():
if isinstance(container_port, int):
container_port = "{0}/tcp".format(container_port)
if len(config) == 1:
Expand Down Expand Up @@ -1437,7 +1437,7 @@ def get_differing_containers(self):
# LINKS

expected_links = set()
for link, alias in (self.links or {}).iteritems():
for link, alias in (self.links or {}).items():
expected_links.add("/{0}:{1}/{2}".format(link, container["Name"], alias))

actual_links = set(container['HostConfig']['Links'] or [])
Expand Down