diff --git a/playbooks/inventory/dynamic_inventory.py b/playbooks/inventory/dynamic_inventory.py index 10b53f69d4..2de3958177 100755 --- a/playbooks/inventory/dynamic_inventory.py +++ b/playbooks/inventory/dynamic_inventory.py @@ -20,7 +20,7 @@ import json import netaddr import os -import Queue +import queue import random import tarfile import uuid @@ -82,7 +82,7 @@ def get_ip_address(name, ip_q): return str(ip_addr) except AttributeError: return None - except Queue.Empty: + except queue.Empty: raise SystemExit( 'Cannot retrieve requested amount of IP addresses. Increase the %s' ' range in your openstack_user_config.yml.' % name @@ -199,7 +199,7 @@ def _append_container_types(inventory, host_type): :param inventory: ``dict`` Living dictionary of inventory :param host_type: ``str`` Name of the host type """ - for _host in inventory['_meta']['hostvars'].keys(): + for _host in list(inventory['_meta']['hostvars'].keys()): hdata = inventory['_meta']['hostvars'][_host] if 'container_name' in hdata: if hdata['container_name'].startswith(host_type): @@ -224,7 +224,7 @@ def _append_to_host_groups(inventory, container_type, assignment, host_type, iph = inventory[physical_group_type]['hosts'] iah = inventory[assignment]['hosts'] - for hname, hdata in inventory['_meta']['hostvars'].iteritems(): + for hname, hdata in inventory['_meta']['hostvars'].items(): is_metal = False properties = hdata.get('properties') if properties: @@ -256,7 +256,7 @@ def _append_to_host_groups(inventory, container_type, assignment, host_type, # Append any options in config to the host_vars of a container container_vars = host_options.get('container_vars') if isinstance(container_vars, dict): - for _keys, _vars in container_vars.items(): + for _keys, _vars in list(container_vars.items()): # Copy the options dictionary for manipulation if isinstance(_vars, dict): options = _vars.copy() @@ -362,7 +362,7 @@ def user_defined_setup(config, inventory, is_metal): :param is_metal: ``bol`` If true, a container entry will not be built """ hvs = inventory['_meta']['hostvars'] - for key, value in config.iteritems(): + for key, value in config.items(): if key.endswith('hosts'): if key not in inventory: inventory[key] = {'hosts': []} @@ -370,7 +370,7 @@ def user_defined_setup(config, inventory, is_metal): if value is None: return - for _key, _value in value.iteritems(): + for _key, _value in value.items(): if _key not in inventory['_meta']['hostvars']: inventory['_meta']['hostvars'][_key] = {} @@ -389,7 +389,7 @@ def user_defined_setup(config, inventory, is_metal): hvs[_key]['properties'].update({'is_metal': is_metal}) if 'host_vars' in _value: - for _k, _v in _value['host_vars'].items(): + for _k, _v in list(_value['host_vars'].items()): hvs[_key][_k] = _v append_if(array=USED_IPS, item=_value['ip']) @@ -402,10 +402,10 @@ def skel_setup(environment_file, inventory): :param environment_file: ``dict`` Known environment information :param inventory: ``dict`` Living dictionary of inventory """ - for key, value in environment_file.iteritems(): + for key, value in environment_file.items(): if key == 'version': continue - for _key, _value in value.iteritems(): + for _key, _value in value.items(): if _key not in inventory: inventory[_key] = {} if _key.endswith('container'): @@ -433,7 +433,7 @@ def skel_load(skeleton, inventory): :param skeleton: :param inventory: ``dict`` Living dictionary of inventory """ - for key, value in skeleton.iteritems(): + for key, value in skeleton.items(): _parse_belongs_to( key, belongs_to=value['belongs_to'], @@ -450,7 +450,7 @@ def _load_optional_q(config, cidr_name): cidr = config.get(cidr_name) ip_q = None if cidr is not None: - ip_q = Queue.Queue() + ip_q = queue.Queue() _load_ip_q(cidr=cidr, ip_q=ip_q) return ip_q @@ -638,7 +638,7 @@ def container_skel_load(container_skel, inventory, config): :param inventory: ``dict`` Living dictionary of inventory :param config: ``dict`` User defined information """ - for key, value in container_skel.iteritems(): + for key, value in container_skel.items(): for assignment in value['contains']: for container_type in value['belongs_to']: _add_container_hosts( @@ -757,9 +757,9 @@ def _set_used_ips(user_defined_config, inventory): append_if(array=USED_IPS, item=split_ip[0]) # Find all used IP addresses and ensure that they are not used again - for host_entry in inventory['_meta']['hostvars'].values(): + for host_entry in list(inventory['_meta']['hostvars'].values()): networks = host_entry.get('container_networks', dict()) - for network_entry in networks.values(): + for network_entry in list(networks.values()): address = network_entry.get('address') if address: append_if(array=USED_IPS, item=address) @@ -773,7 +773,7 @@ def _ensure_inventory_uptodate(inventory, container_skel): :param inventory: ``dict`` Living inventory of containers and hosts """ - for key, value in inventory['_meta']['hostvars'].iteritems(): + for key, value in inventory['_meta']['hostvars'].items(): if 'container_name' not in value: value['container_name'] = key @@ -783,7 +783,7 @@ def _ensure_inventory_uptodate(inventory, container_skel): if rh == 'container_networks': value[rh] = {} - for key, value in container_skel.iteritems(): + for key, value in container_skel.items(): item = inventory.get(key) hosts = item.get('hosts') if hosts: @@ -835,7 +835,7 @@ def _merge_dict(base_items, new_items): :param new_items: ``dict`` :return dictionary: """ - for key, value in new_items.iteritems(): + for key, value in new_items.items(): if isinstance(value, dict): base_merge = _merge_dict(base_items.get(key, {}), value) base_items[key] = base_merge @@ -972,9 +972,9 @@ def main(): # Generate a list of all hosts and their used IP addresses hostnames_ips = {} - for _host, _vars in dynamic_inventory['_meta']['hostvars'].iteritems(): + for _host, _vars in dynamic_inventory['_meta']['hostvars'].items(): host_hash = hostnames_ips[_host] = {} - for _key, _value in _vars.iteritems(): + for _key, _value in _vars.items(): if _key.endswith('address') or _key == 'ansible_ssh_host': host_hash[_key] = _value diff --git a/releasenotes/source/conf.py b/releasenotes/source/conf.py index 7a8ccc569b..a683dc6b37 100644 --- a/releasenotes/source/conf.py +++ b/releasenotes/source/conf.py @@ -55,8 +55,8 @@ master_doc = 'index' # General information about the project. -project = u'OpenStack-Ansible Release Notes' -copyright = u'2015, OpenStack-Ansible Developers' +project = 'OpenStack-Ansible Release Notes' +copyright = '2015, OpenStack-Ansible Developers' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -211,8 +211,8 @@ # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - ('index', 'OpenStackAnsibleReleaseNotes.tex', u'OpenStack-Ansible Release Notes Documentation', - u'OpenStack-Ansible Developers', 'manual'), + ('index', 'OpenStackAnsibleReleaseNotes.tex', 'OpenStack-Ansible Release Notes Documentation', + 'OpenStack-Ansible Developers', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of @@ -241,8 +241,8 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ('index', 'openstackansiblereleasenotes', u'OpenStack-Ansible Release Notes Documentation', - [u'OpenStack-Ansible Developers'], 1) + ('index', 'openstackansiblereleasenotes', 'OpenStack-Ansible Release Notes Documentation', + ['OpenStack-Ansible Developers'], 1) ] # If true, show URL addresses after external links. @@ -255,8 +255,8 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'OpenStackAnsibleReleaseNotes', u'OpenStack-Ansible Release Notes Documentation', - u'OpenStack-Ansible Developers', 'OpenStackAnsibleReleaseNotes', + ('index', 'OpenStackAnsibleReleaseNotes', 'OpenStack-Ansible Release Notes Documentation', + 'OpenStack-Ansible Developers', 'OpenStackAnsibleReleaseNotes', 'One line description of project.', 'Miscellaneous'), ] diff --git a/scripts/inventory-manage.py b/scripts/inventory-manage.py index 139fce129b..6705074c52 100755 --- a/scripts/inventory-manage.py +++ b/scripts/inventory-manage.py @@ -77,9 +77,9 @@ def recursive_dict_removal(inventory, purge_list): inventory -- inventory dictionary purge_list -- list of items to remove """ - for key, value in inventory.iteritems(): + for key, value in inventory.items(): if isinstance(value, dict): - for _key, _value in value.iteritems(): + for _key, _value in value.items(): if isinstance(_value, dict): for item in purge_list: if item in _value: @@ -156,7 +156,7 @@ def get_all_groups(inventory): as values. """ containers = {} - for container_name in inventory['_meta']['hostvars'].keys(): + for container_name in list(inventory['_meta']['hostvars'].keys()): # Skip the default group names since they're not helpful (like aio1). if '_' not in container_name: @@ -179,7 +179,7 @@ def get_groups_for_container(inventory, container_name): """ # Beware, this dictionary comprehension requires Python 2.7, but we should # have this on openstack-ansible hosts already. - groups = {k for (k, v) in inventory.items() if + groups = {k for (k, v) in list(inventory.items()) if ('hosts' in v and container_name in v['hosts'])} return groups @@ -215,11 +215,11 @@ def print_groups_per_container(inventory): ] table = prettytable.PrettyTable(required_list) - for container_name, groups in containers.iteritems(): + for container_name, groups in containers.items(): row = [container_name, ', '.join(sorted(groups))] table.add_row(row) - for tbl in table.align.keys(): + for tbl in list(table.align.keys()): table.align[tbl] = 'l' return table @@ -237,7 +237,7 @@ def print_containers_per_group(inventory): ] table = prettytable.PrettyTable(required_list) - for group_name in inventory.keys(): + for group_name in list(inventory.keys()): containers = get_containers_for_group(inventory, group_name) # Don't show a group if it has no containers @@ -253,7 +253,7 @@ def print_containers_per_group(inventory): row = [group_name, '\n'.join(containers)] table.add_row(row) - for tbl in table.align.keys(): + for tbl in list(table.align.keys()): table.align[tbl] = 'l' return table @@ -276,7 +276,7 @@ def print_inventory(inventory, sort_key): 'container_types' ] table = prettytable.PrettyTable(required_list) - for key, values in _meta_data.iteritems(): + for key, values in _meta_data.items(): for rl in required_list: if rl not in values: values[rl] = None @@ -290,7 +290,7 @@ def print_inventory(inventory, sort_key): row.append(values.get(_rl)) else: table.add_row(row) - for tbl in table.align.keys(): + for tbl in list(table.align.keys()): table.align[tbl] = 'l' table.sortby = sort_key return table @@ -309,15 +309,15 @@ def main(): # Make a table with hosts in the left column and details about each in the # columns to the right if user_args['list_host'] is True: - print(print_inventory(inventory, user_args['sort'])) + print((print_inventory(inventory, user_args['sort']))) # Groups in first column, containers in each group on the right elif user_args['list_groups'] is True: - print(print_groups_per_container(inventory)) + print((print_groups_per_container(inventory))) # Containers in the first column, groups for each container on the right elif user_args['list_containers'] is True: - print(print_containers_per_group(inventory)) + print((print_containers_per_group(inventory))) else: recursive_dict_removal(inventory, user_args['remove_item']) with open(environment_file, 'wb') as f_handle: diff --git a/scripts/pw-token-gen.py b/scripts/pw-token-gen.py index 1bf3124fe5..0c75b13aa0 100755 --- a/scripts/pw-token-gen.py +++ b/scripts/pw-token-gen.py @@ -166,7 +166,7 @@ def main(): changed = False generator = CredentialGenerator() - for entry, value in user_vars.iteritems(): + for entry, value in user_vars.items(): if value is None or all_args['regen'] is True: if entry.endswith('password') or entry.endswith('secret'): changed = True @@ -187,7 +187,7 @@ def main(): # If changed is set to True, this will archive the old passwords if changed is True: user_vars_tar_file = '%s.tar' % user_vars_file - print('Creating backup file [ %s ]' % user_vars_tar_file) + print(('Creating backup file [ %s ]' % user_vars_tar_file)) # Create a tarball if needed with tarfile.open(user_vars_tar_file, 'a') as tar: os.chmod(user_vars_tar_file, 0o600) @@ -208,7 +208,7 @@ def main(): ) ) - print('Operation Complete, [ %s ] is ready' % user_vars_file) + print(('Operation Complete, [ %s ] is ready' % user_vars_file)) if __name__ == '__main__':