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

pydetective #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions playbooks/inventory/dynamic_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import json
import netaddr
import os
import Queue
import queue
import random
import tarfile
import uuid
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -362,15 +362,15 @@ 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': []}

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] = {}

Expand All @@ -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'])
Expand All @@ -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'):
Expand Down Expand Up @@ -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'],
Expand All @@ -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

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
16 changes: 8 additions & 8 deletions releasenotes/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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'),
]
Expand Down
26 changes: 13 additions & 13 deletions scripts/inventory-manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions scripts/pw-token-gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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__':
Expand Down