diff options
author | Marius Gedminas <marius@gedmin.as> | 2015-09-03 08:23:27 +0200 |
---|---|---|
committer | Marius Gedminas <marius@gedmin.as> | 2015-09-03 08:23:27 +0200 |
commit | 823677b490d3ddc3bcfe8fa2f215d9d9c2167b14 (patch) | |
tree | 1e0915306f5dec06cb369b3aa5b30cac6b7699bb /contrib | |
parent | Further cleanup from locking changes (diff) | |
download | ansible-823677b490d3ddc3bcfe8fa2f215d9d9c2167b14.tar.xz ansible-823677b490d3ddc3bcfe8fa2f215d9d9c2167b14.zip |
Replace .iteritems() with six.iteritems()
Replace .iteritems() with six.iteritems() everywhere except in
module_utils (because there's no 'six' on the remote host). And except
in lib/ansible/galaxy/data/metadata_template.j2, because I'm not sure
six is available there.
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/inventory/apache-libcloud.py | 3 | ||||
-rwxr-xr-x | contrib/inventory/cobbler.py | 6 | ||||
-rwxr-xr-x | contrib/inventory/collins.py | 4 | ||||
-rwxr-xr-x | contrib/inventory/consul_io.py | 3 | ||||
-rwxr-xr-x | contrib/inventory/nova.py | 3 | ||||
-rwxr-xr-x | contrib/inventory/proxmox.py | 5 | ||||
-rwxr-xr-x | contrib/inventory/rax.py | 4 | ||||
-rwxr-xr-x | contrib/inventory/spacewalk.py | 8 |
8 files changed, 25 insertions, 11 deletions
diff --git a/contrib/inventory/apache-libcloud.py b/contrib/inventory/apache-libcloud.py index f417e3a5e9..21436a02ad 100755 --- a/contrib/inventory/apache-libcloud.py +++ b/contrib/inventory/apache-libcloud.py @@ -37,6 +37,7 @@ import re from time import time import ConfigParser +from six import iteritems from libcloud.compute.types import Provider from libcloud.compute.providers import get_driver import libcloud.security as sec @@ -268,7 +269,7 @@ class LibcloudInventory(object): elif key == 'ec2_region': instance_vars[key] = value.name elif key == 'ec2_tags': - for k, v in value.iteritems(): + for k, v in iteritems(value): key = self.to_safe('ec2_tag_' + k) instance_vars[key] = v elif key == 'ec2_groups': diff --git a/contrib/inventory/cobbler.py b/contrib/inventory/cobbler.py index aca045eaf7..b5fcdeacbb 100755 --- a/contrib/inventory/cobbler.py +++ b/contrib/inventory/cobbler.py @@ -72,6 +72,8 @@ try: except ImportError: import simplejson as json +from six import iteritems + # NOTE -- this file assumes Ansible is being accessed FROM the cobbler # server, so it does not attempt to login with a username and password. # this will be addressed in a future version of this script. @@ -171,7 +173,7 @@ class CobblerInventory(object): interfaces = host['interfaces'] # hostname is often empty for non-static IP hosts if dns_name == '': - for (iname, ivalue) in interfaces.iteritems(): + for (iname, ivalue) in iteritems(interfaces): if ivalue['management'] or not ivalue['static']: this_dns_name = ivalue.get('dns_name', None) if this_dns_name is not None and this_dns_name is not "": @@ -203,7 +205,7 @@ class CobblerInventory(object): self.cache[dns_name] = host if "ks_meta" in host: - for key, value in host["ks_meta"].iteritems(): + for key, value in iteritems(host["ks_meta"]): self.cache[dns_name][key] = value self.write_to_cache(self.cache, self.cache_path_cache) diff --git a/contrib/inventory/collins.py b/contrib/inventory/collins.py index 72c5b88ea9..a33d27ec6d 100755 --- a/contrib/inventory/collins.py +++ b/contrib/inventory/collins.py @@ -83,6 +83,8 @@ try: except ImportError: import simplejson as json +from six import iteritems + class CollinsDefaults(object): ASSETS_API_ENDPOINT = '%s/api/assets' @@ -174,7 +176,7 @@ class CollinsInventory(object): # the CQL search feature as described here: # http://tumblr.github.io/collins/recipes.html attributes_query = [ '='.join(attr_pair) - for attr_pair in attributes.iteritems() ] + for attr_pair in iteritems(attributes) ] query_parameters = { 'details': ['True'], 'operation': [operation], diff --git a/contrib/inventory/consul_io.py b/contrib/inventory/consul_io.py index 65d48721dc..1bcf22d373 100755 --- a/contrib/inventory/consul_io.py +++ b/contrib/inventory/consul_io.py @@ -141,6 +141,7 @@ except ImportError as e: http://python-consul.readthedocs.org/en/latest/#installation'""") sys.exit(1) +from six import iteritems class ConsulInventory(object): @@ -187,7 +188,7 @@ class ConsulInventory(object): an 'available' or 'unavailable' grouping. The suffix for each group can be controlled from the config''' if self.config.has_config('availability'): - for service_name, service in node['Services'].iteritems(): + for service_name, service in iteritems(node['Services']): for node in self.consul_api.health.service(service_name)[1]: for check in node['Checks']: if check['ServiceName'] == service_name: diff --git a/contrib/inventory/nova.py b/contrib/inventory/nova.py index 9561f4406a..e8f3b9a626 100755 --- a/contrib/inventory/nova.py +++ b/contrib/inventory/nova.py @@ -26,6 +26,7 @@ import re import os import ConfigParser from novaclient import client as nova_client +from six import iteritems try: import json @@ -194,7 +195,7 @@ if (len(sys.argv) == 2 and sys.argv[1] == '--list') or len(sys.argv) == 1: push(groups, server.name, access_ip) # Run through each metadata item and add instance to it - for key, value in server.metadata.iteritems(): + for key, value in iteritems(server.metadata): composed_key = to_safe('tag_{0}_{1}'.format(key, value)) push(groups, composed_key, access_ip) diff --git a/contrib/inventory/proxmox.py b/contrib/inventory/proxmox.py index 381b3ae7fb..bc636d0ac3 100755 --- a/contrib/inventory/proxmox.py +++ b/contrib/inventory/proxmox.py @@ -25,6 +25,9 @@ import os import sys from optparse import OptionParser +from six import iteritems + + class ProxmoxNodeList(list): def get_names(self): return [node['node'] for node in self] @@ -32,7 +35,7 @@ class ProxmoxNodeList(list): class ProxmoxQemu(dict): def get_variables(self): variables = {} - for key, value in self.iteritems(): + for key, value in iteritems(self): variables['proxmox_' + key] = value return variables diff --git a/contrib/inventory/rax.py b/contrib/inventory/rax.py index 5892f2cbb9..0028f54d20 100755 --- a/contrib/inventory/rax.py +++ b/contrib/inventory/rax.py @@ -153,6 +153,8 @@ import warnings import collections import ConfigParser +from six import iteritems + from ansible.constants import get_config, mk_boolean try: @@ -267,7 +269,7 @@ def _list_into_cache(regions): hostvars[server.name]['rax_region'] = region - for key, value in server.metadata.iteritems(): + for key, value in iteritems(server.metadata): groups['%s_%s_%s' % (prefix, key, value)].append(server.name) groups['instance-%s' % server.id].append(server.name) diff --git a/contrib/inventory/spacewalk.py b/contrib/inventory/spacewalk.py index ecf1948432..fb0a152eca 100755 --- a/contrib/inventory/spacewalk.py +++ b/contrib/inventory/spacewalk.py @@ -49,6 +49,8 @@ from optparse import OptionParser import subprocess import ConfigParser +from six import iteritems + try: import json except: @@ -193,10 +195,10 @@ if options.list: sys.exit(2) if options.human: - for group, systems in groups.iteritems(): + for group, systems in iteritems(groups): print('[%s]\n%s\n' % (group, '\n'.join(systems))) else: - final = dict( [ (k, list(s)) for k, s in groups.iteritems() ] ) + final = dict( [ (k, list(s)) for k, s in iteritems(groups) ] ) final["_meta"] = meta print(json.dumps( final )) #print(json.dumps(groups)) @@ -221,7 +223,7 @@ elif options.host: if options.human: print('Host: %s' % options.host) - for k, v in host_details.iteritems(): + for k, v in iteritems(host_details): print(' %s: %s' % (k, '\n '.join(v.split(';')))) else: print( json.dumps( dict( ( key, ( value.split(';') if ';' in value else value) ) for key, value in host_details.items() ) ) ) |