Removed dict.iteritems() in several other files.

This is for py3 compatibility #18506
pull/19292/head
Andrea Tartaglia 8 years ago committed by Toshio Kuratomi
parent 7c71c678fa
commit 59227d8c31

@ -309,7 +309,7 @@ class AzureRM(object):
def _get_env_credentials(self): def _get_env_credentials(self):
env_credentials = dict() env_credentials = dict()
for attribute, env_variable in AZURE_CREDENTIAL_ENV_MAPPING.iteritems(): for attribute, env_variable in AZURE_CREDENTIAL_ENV_MAPPING.items():
env_credentials[attribute] = os.environ.get(env_variable, None) env_credentials[attribute] = os.environ.get(env_variable, None)
if env_credentials['profile'] is not None: if env_credentials['profile'] is not None:
@ -328,7 +328,7 @@ class AzureRM(object):
self.log('Getting credentials') self.log('Getting credentials')
arg_credentials = dict() arg_credentials = dict()
for attribute, env_variable in AZURE_CREDENTIAL_ENV_MAPPING.iteritems(): for attribute, env_variable in AZURE_CREDENTIAL_ENV_MAPPING.items():
arg_credentials[attribute] = getattr(params, attribute) arg_credentials[attribute] = getattr(params, attribute)
# try module params # try module params
@ -664,7 +664,7 @@ class AzureInventory(object):
self._inventory['azure'].append(host_name) self._inventory['azure'].append(host_name)
if self.group_by_tag and vars.get('tags'): if self.group_by_tag and vars.get('tags'):
for key, value in vars['tags'].iteritems(): for key, value in vars['tags'].items():
safe_key = self._to_safe(key) safe_key = self._to_safe(key)
safe_value = safe_key + '_' + self._to_safe(value) safe_value = safe_key + '_' + self._to_safe(value)
if not self._inventory.get(safe_key): if not self._inventory.get(safe_key):
@ -724,7 +724,7 @@ class AzureInventory(object):
def _get_env_settings(self): def _get_env_settings(self):
env_settings = dict() env_settings = dict()
for attribute, env_variable in AZURE_CONFIG_SETTINGS.iteritems(): for attribute, env_variable in AZURE_CONFIG_SETTINGS.items():
env_settings[attribute] = os.environ.get(env_variable, None) env_settings[attribute] = os.environ.get(env_variable, None)
return env_settings return env_settings

@ -201,7 +201,7 @@ class NSoTInventory(object):
_inventory_group() _inventory_group()
''' '''
inventory = dict() inventory = dict()
for group, contents in self.config.iteritems(): for group, contents in self.config.items():
group_response = self._inventory_group(group, contents) group_response = self._inventory_group(group, contents)
inventory.update(group_response) inventory.update(group_response)
inventory.update({'_meta': self._meta}) inventory.update({'_meta': self._meta})

@ -14,7 +14,7 @@ class RackhdInventory(object):
for nodeid in nodeids: for nodeid in nodeids:
self._load_inventory_data(nodeid) self._load_inventory_data(nodeid)
inventory = {} inventory = {}
for nodeid,info in self._inventory.iteritems(): for nodeid,info in self._inventory.items():
inventory[nodeid]= (self._format_output(nodeid, info)) inventory[nodeid]= (self._format_output(nodeid, info))
print(json.dumps(inventory)) print(json.dumps(inventory))
@ -24,7 +24,7 @@ class RackhdInventory(object):
info['lookup'] = RACKHD_URL + '/api/common/lookups/?q={0}'.format(nodeid) info['lookup'] = RACKHD_URL + '/api/common/lookups/?q={0}'.format(nodeid)
results = {} results = {}
for key,url in info.iteritems(): for key,url in info.items():
r = requests.get( url, verify=False) r = requests.get( url, verify=False)
results[key] = r.text results[key] = r.text
self._inventory[nodeid] = results self._inventory[nodeid] = results
@ -36,7 +36,7 @@ class RackhdInventory(object):
if len(node_info) > 0: if len(node_info) > 0:
ipaddress = node_info[0]['ipAddress'] ipaddress = node_info[0]['ipAddress']
output = { 'hosts':[ipaddress],'vars':{}} output = { 'hosts':[ipaddress],'vars':{}}
for key,result in info.iteritems(): for key,result in info.items():
output['vars'][key] = json.loads(result) output['vars'][key] = json.loads(result)
output['vars']['ansible_ssh_user'] = 'monorail' output['vars']['ansible_ssh_user'] = 'monorail'
except KeyError: except KeyError:

@ -230,7 +230,7 @@ class VMWareInventory(object):
config.read(vmware_ini_path) config.read(vmware_ini_path)
# apply defaults # apply defaults
for k,v in defaults['vmware'].iteritems(): for k,v in defaults['vmware'].items():
if not config.has_option('vmware', k): if not config.has_option('vmware', k):
config.set('vmware', k, str(v)) config.set('vmware', k, str(v))
@ -401,7 +401,7 @@ class VMWareInventory(object):
# Reset the inventory keys # Reset the inventory keys
for k,v in name_mapping.iteritems(): for k,v in name_mapping.items():
if not host_mapping or not k in host_mapping: if not host_mapping or not k in host_mapping:
continue continue
@ -434,7 +434,7 @@ class VMWareInventory(object):
continue continue
self.debugl('filter: %s' % hf) self.debugl('filter: %s' % hf)
filter_map = self.create_template_mapping(inventory, hf, dtype='boolean') filter_map = self.create_template_mapping(inventory, hf, dtype='boolean')
for k,v in filter_map.iteritems(): for k,v in filter_map.items():
if not v: if not v:
# delete this host # delete this host
inventory['all']['hosts'].remove(k) inventory['all']['hosts'].remove(k)
@ -447,7 +447,7 @@ class VMWareInventory(object):
# Create groups # Create groups
for gbp in self.groupby_patterns: for gbp in self.groupby_patterns:
groupby_map = self.create_template_mapping(inventory, gbp) groupby_map = self.create_template_mapping(inventory, gbp)
for k,v in groupby_map.iteritems(): for k,v in groupby_map.items():
if v not in inventory: if v not in inventory:
inventory[v] = {} inventory[v] = {}
inventory[v]['hosts'] = [] inventory[v]['hosts'] = []
@ -462,7 +462,7 @@ class VMWareInventory(object):
''' Return a hash of uuid to templated string from pattern ''' ''' Return a hash of uuid to templated string from pattern '''
mapping = {} mapping = {}
for k,v in inventory['_meta']['hostvars'].iteritems(): for k,v in inventory['_meta']['hostvars'].items():
t = jinja2.Template(pattern) t = jinja2.Template(pattern)
newkey = None newkey = None
try: try:
@ -671,7 +671,7 @@ class VMWareInventory(object):
# check if the machine has the name requested # check if the machine has the name requested
keys = self.inventory['_meta']['hostvars'].keys() keys = self.inventory['_meta']['hostvars'].keys()
match = None match = None
for k,v in self.inventory['_meta']['hostvars'].iteritems(): for k,v in self.inventory['_meta']['hostvars'].items():
if self.inventory['_meta']['hostvars'][k]['name'] == self.args.host: if self.inventory['_meta']['hostvars'][k]['name'] == self.args.host:
match = k match = k
break break

@ -240,12 +240,12 @@ class AzureRMModuleBase(object):
new_tags = copy.copy(tags) if isinstance(tags, dict) else dict() new_tags = copy.copy(tags) if isinstance(tags, dict) else dict()
changed = False changed = False
if isinstance(self.module.params.get('tags'), dict): if isinstance(self.module.params.get('tags'), dict):
for key, value in self.module.params['tags'].iteritems(): for key, value in self.module.params['tags'].items():
if not new_tags.get(key) or new_tags[key] != value: if not new_tags.get(key) or new_tags[key] != value:
changed = True changed = True
new_tags[key] = value new_tags[key] = value
if isinstance(tags, dict): if isinstance(tags, dict):
for key, value in tags.iteritems(): for key, value in tags.items():
if not self.module.params['tags'].get(key): if not self.module.params['tags'].get(key):
new_tags.pop(key) new_tags.pop(key)
changed = True changed = True
@ -318,7 +318,7 @@ class AzureRMModuleBase(object):
def _get_env_credentials(self): def _get_env_credentials(self):
env_credentials = dict() env_credentials = dict()
for attribute, env_variable in AZURE_CREDENTIAL_ENV_MAPPING.iteritems(): for attribute, env_variable in AZURE_CREDENTIAL_ENV_MAPPING.items():
env_credentials[attribute] = os.environ.get(env_variable, None) env_credentials[attribute] = os.environ.get(env_variable, None)
if env_credentials['profile']: if env_credentials['profile']:
@ -337,7 +337,7 @@ class AzureRMModuleBase(object):
self.log('Getting credentials') self.log('Getting credentials')
arg_credentials = dict() arg_credentials = dict()
for attribute, env_variable in AZURE_CREDENTIAL_ENV_MAPPING.iteritems(): for attribute, env_variable in AZURE_CREDENTIAL_ENV_MAPPING.items():
arg_credentials[attribute] = params.get(attribute, None) arg_credentials[attribute] = params.get(attribute, None)
# try module params # try module params

@ -651,7 +651,7 @@ def format_attributes(attributes):
def get_flags_from_attributes(attributes): def get_flags_from_attributes(attributes):
flags = [] flags = []
for key,attr in FILE_ATTRIBUTES.iteritems(): for key,attr in FILE_ATTRIBUTES.items():
if attr in attributes: if attr in attributes:
flags.append(key) flags.append(key)
return ''.join(flags) return ''.join(flags)

@ -158,7 +158,7 @@ class AnsibleCloudStack(object):
def has_changed(self, want_dict, current_dict, only_keys=None): def has_changed(self, want_dict, current_dict, only_keys=None):
result = False result = False
for key, value in want_dict.iteritems(): for key, value in want_dict.items():
# Optionally limit by a list of keys # Optionally limit by a list of keys
if only_keys and key not in only_keys: if only_keys and key not in only_keys:
@ -581,12 +581,12 @@ class AnsibleCloudStack(object):
if resource: if resource:
returns = self.common_returns.copy() returns = self.common_returns.copy()
returns.update(self.returns) returns.update(self.returns)
for search_key, return_key in returns.iteritems(): for search_key, return_key in returns.items():
if search_key in resource: if search_key in resource:
self.result[return_key] = resource[search_key] self.result[return_key] = resource[search_key]
# Bad bad API does not always return int when it should. # 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 resource: if search_key in resource:
self.result[return_key] = int(resource[search_key]) self.result[return_key] = int(resource[search_key])

@ -343,7 +343,7 @@ def camel_dict_to_snake_dict(camel_dict):
snake_dict = {} snake_dict = {}
for k, v in camel_dict.iteritems(): for k, v in camel_dict.items():
if isinstance(v, dict): if isinstance(v, dict):
snake_dict[camel_to_snake(k)] = camel_dict_to_snake_dict(v) snake_dict[camel_to_snake(k)] = camel_dict_to_snake_dict(v)
elif isinstance(v, list): elif isinstance(v, list):
@ -378,7 +378,7 @@ def ansible_dict_to_boto3_filter_list(filters_dict):
""" """
filters_list = [] filters_list = []
for k,v in filters_dict.iteritems(): for k,v in filters_dict.items():
filter_dict = {'Name': k} filter_dict = {'Name': k}
if isinstance(v, string_types): if isinstance(v, string_types):
filter_dict['Values'] = [v] filter_dict['Values'] = [v]
@ -443,7 +443,7 @@ def ansible_dict_to_boto3_tag_list(tags_dict):
""" """
tags_list = [] tags_list = []
for k,v in tags_dict.iteritems(): for k,v in tags_dict.items():
tags_list.append({'Key': k, 'Value': v}) tags_list.append({'Key': k, 'Value': v})
return tags_list return tags_list

@ -143,7 +143,7 @@ class ExoDns(object):
def has_changed(self, want_dict, current_dict, only_keys=None): def has_changed(self, want_dict, current_dict, only_keys=None):
changed = False changed = False
for key, value in want_dict.iteritems(): for key, value in want_dict.items():
# Optionally limit by a list of keys # Optionally limit by a list of keys
if only_keys and key not in only_keys: if only_keys and key not in only_keys:
continue continue

@ -204,7 +204,7 @@ class Play(Base, Taggable, Become):
for prompt_data in new_ds: for prompt_data in new_ds:
if 'name' not in prompt_data: if 'name' not in prompt_data:
display.deprecated("Using the 'short form' for vars_prompt has been deprecated") display.deprecated("Using the 'short form' for vars_prompt has been deprecated")
for vname, prompt in prompt_data.iteritems(): for vname, prompt in prompt_data.items():
vars_prompts.append(dict( vars_prompts.append(dict(
name = vname, name = vname,
prompt = prompt, prompt = prompt,

@ -124,7 +124,7 @@ class CallbackModule(CallbackBase):
# Sort the tasks by the specified sort # Sort the tasks by the specified sort
if self.sort_order != 'none': if self.sort_order != 'none':
results = sorted( results = sorted(
self.stats.iteritems(), self.stats.items(),
key=lambda x:x[1]['time'], key=lambda x:x[1]['time'],
reverse=self.sort_order, reverse=self.sort_order,
) )

@ -376,7 +376,7 @@ class ModuleValidator(Validator):
errors.extend(e.errors) errors.extend(e.errors)
options = doc.get('options', {}) options = doc.get('options', {})
for key, option in (options or {}).iteritems(): for key, option in (options or {}).items():
try: try:
option_schema(option) option_schema(option)
except Exception as e: except Exception as e:
@ -525,7 +525,7 @@ class ModuleValidator(Validator):
should_be = '.'.join(ansible_version.split('.')[:2]) should_be = '.'.join(ansible_version.split('.')[:2])
strict_ansible_version = StrictVersion(should_be) strict_ansible_version = StrictVersion(should_be)
for option, details in options.iteritems(): for option, details in options.items():
new = not bool(existing_options.get(option)) new = not bool(existing_options.get(option))
if not new: if not new:
continue continue

@ -29,7 +29,7 @@ from ansible.plugins.action.synchronize import ActionModule
''' '''
import copy import copy
safe_vars = {} safe_vars = {}
for k,v in task_vars.iteritems(): for k,v in task_vars.items():
if k not in ['vars', 'hostvars']: if k not in ['vars', 'hostvars']:
safe_vars[k] = copy.deepcopy(v) safe_vars[k] = copy.deepcopy(v)
else: else:

Loading…
Cancel
Save