mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-23 04:24:00 -07:00
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.
This commit is contained in:
parent
9e1bc434c7
commit
823677b490
28 changed files with 81 additions and 41 deletions
|
|
@ -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':
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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],
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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() ) ) )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue