Legacy pep8 clean fixes for contrib and hacking (#21081)
This commit is contained in:
parent
0de96d68f6
commit
5942de603d
10 changed files with 49 additions and 40 deletions
|
@ -122,12 +122,16 @@ def generate_inv_from_api(enterprise_entity,config):
|
||||||
vms_entity = next(link for link in (enterprise['links']) if (link['rel']=='virtualmachines'))
|
vms_entity = next(link for link in (enterprise['links']) if (link['rel']=='virtualmachines'))
|
||||||
vms = api_get(vms_entity,config)
|
vms = api_get(vms_entity,config)
|
||||||
for vmcollection in vms['collection']:
|
for vmcollection in vms['collection']:
|
||||||
vm_vapp = next(link for link in (vmcollection['links']) if (link['rel']=='virtualappliance'))['title'].replace('[','').replace(']','').replace(' ','_')
|
for link in vmcollection['links']:
|
||||||
vm_vdc = next(link for link in (vmcollection['links']) if (link['rel']=='virtualdatacenter'))['title'].replace('[','').replace(']','').replace(' ','_')
|
if link['rel'] == 'virtualappliance':
|
||||||
vm_template = next(link for link in (vmcollection['links']) if (link['rel']=='virtualmachinetemplate'))['title'].replace('[','').replace(']','').replace(' ','_')
|
vm_vapp = link['title'].replace('[','').replace(']','').replace(' ','_')
|
||||||
|
elif link['rel'] == 'virtualdatacenter':
|
||||||
|
vm_vdc = link['title'].replace('[','').replace(']','').replace(' ','_')
|
||||||
|
elif link['rel'] == 'virtualmachinetemplate':
|
||||||
|
vm_template = link['title'].replace('[','').replace(']','').replace(' ','_')
|
||||||
|
|
||||||
# From abiquo.ini: Only adding to inventory VMs with public IP
|
# From abiquo.ini: Only adding to inventory VMs with public IP
|
||||||
if (config.getboolean('defaults', 'public_ip_only')) == True:
|
if config.getboolean('defaults', 'public_ip_only') is True:
|
||||||
for link in vmcollection['links']:
|
for link in vmcollection['links']:
|
||||||
if (link['type']=='application/vnd.abiquo.publicip+json' and link['rel']=='ip'):
|
if (link['type']=='application/vnd.abiquo.publicip+json' and link['rel']=='ip'):
|
||||||
vm_nic = link['title']
|
vm_nic = link['title']
|
||||||
|
@ -137,7 +141,7 @@ def generate_inv_from_api(enterprise_entity,config):
|
||||||
# Otherwise, assigning defined network interface IP address
|
# Otherwise, assigning defined network interface IP address
|
||||||
else:
|
else:
|
||||||
for link in vmcollection['links']:
|
for link in vmcollection['links']:
|
||||||
if (link['rel']==config.get('defaults', 'default_net_interface')):
|
if link['rel'] == config.get('defaults', 'default_net_interface'):
|
||||||
vm_nic = link['title']
|
vm_nic = link['title']
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
@ -145,7 +149,7 @@ def generate_inv_from_api(enterprise_entity,config):
|
||||||
|
|
||||||
vm_state = True
|
vm_state = True
|
||||||
# From abiquo.ini: Only adding to inventory VMs deployed
|
# From abiquo.ini: Only adding to inventory VMs deployed
|
||||||
if ((config.getboolean('defaults', 'deployed_only') == True) and (vmcollection['state'] == 'NOT_ALLOCATED')):
|
if config.getboolean('defaults', 'deployed_only') is True and vmcollection['state'] == 'NOT_ALLOCATED':
|
||||||
vm_state = False
|
vm_state = False
|
||||||
|
|
||||||
if vm_nic is not None and vm_state:
|
if vm_nic is not None and vm_state:
|
||||||
|
@ -161,7 +165,7 @@ def generate_inv_from_api(enterprise_entity,config):
|
||||||
inventory[vm_template] = {}
|
inventory[vm_template] = {}
|
||||||
inventory[vm_template]['children'] = []
|
inventory[vm_template]['children'] = []
|
||||||
inventory[vm_template]['hosts'] = []
|
inventory[vm_template]['hosts'] = []
|
||||||
if config.getboolean('defaults', 'get_metadata') == True:
|
if config.getboolean('defaults', 'get_metadata') is True:
|
||||||
meta_entity = next(link for link in (vmcollection['links']) if (link['rel']=='metadata'))
|
meta_entity = next(link for link in (vmcollection['links']) if (link['rel']=='metadata'))
|
||||||
try:
|
try:
|
||||||
metadata = api_get(meta_entity,config)
|
metadata = api_get(meta_entity,config)
|
||||||
|
|
|
@ -378,23 +378,18 @@ or environment variables (DO_API_TOKEN)\n''')
|
||||||
self.inventory[droplet['name']] = [dest]
|
self.inventory[droplet['name']] = [dest]
|
||||||
|
|
||||||
# groups that are always present
|
# groups that are always present
|
||||||
for group in [
|
for group in ('region_' + droplet['region']['slug'],
|
||||||
'region_' + droplet['region']['slug'],
|
|
||||||
'image_' + str(droplet['image']['id']),
|
'image_' + str(droplet['image']['id']),
|
||||||
'size_' + droplet['size']['slug'],
|
'size_' + droplet['size']['slug'],
|
||||||
'distro_' + self.to_safe(droplet['image']['distribution']),
|
'distro_' + self.to_safe(droplet['image']['distribution']),
|
||||||
'status_' + droplet['status'],
|
'status_' + droplet['status']):
|
||||||
|
|
||||||
]:
|
|
||||||
if group not in self.inventory:
|
if group not in self.inventory:
|
||||||
self.inventory[group] = { 'hosts': [ ], 'vars': {} }
|
self.inventory[group] = { 'hosts': [ ], 'vars': {} }
|
||||||
self.inventory[group]['hosts'].append(dest)
|
self.inventory[group]['hosts'].append(dest)
|
||||||
|
|
||||||
# groups that are not always present
|
# groups that are not always present
|
||||||
for group in [
|
for group in (droplet['image']['slug'],
|
||||||
droplet['image']['slug'],
|
droplet['image']['name']):
|
||||||
droplet['image']['name']
|
|
||||||
]:
|
|
||||||
if group:
|
if group:
|
||||||
image = 'image_' + self.to_safe(group)
|
image = 'image_' + self.to_safe(group)
|
||||||
if image not in self.inventory:
|
if image not in self.inventory:
|
||||||
|
|
|
@ -133,7 +133,7 @@ When run for a specific container using the --host option this script returns th
|
||||||
"docker_hostspath": "/mnt/sda1/var/lib/docker/containers/9f2f80b0a702361d1ac432e6af816c19bda46da15c21264fb418c873de635a14/hosts",
|
"docker_hostspath": "/mnt/sda1/var/lib/docker/containers/9f2f80b0a702361d1ac432e6af816c19bda46da15c21264fb418c873de635a14/hosts",
|
||||||
"docker_id": "9f2f80b0a702361d1ac432e6af816c19bda46da15c21264fb418c873de635a14",
|
"docker_id": "9f2f80b0a702361d1ac432e6af816c19bda46da15c21264fb418c873de635a14",
|
||||||
"docker_image": "0a6ba66e537a53a5ea94f7c6a99c534c6adb12e3ed09326d4bf3b38f7c3ba4e7",
|
"docker_image": "0a6ba66e537a53a5ea94f7c6a99c534c6adb12e3ed09326d4bf3b38f7c3ba4e7",
|
||||||
"docker_logpath": "/mnt/sda1/var/lib/docker/containers/9f2f80b0a702361d1ac432e6af816c19bda46da15c21264fb418c873de635a14/9f2f80b0a702361d1ac432e6af816c19bda46da15c21264fb418c873de635a14-json.log",
|
"docker_logpath": "/mnt/sda1/var/lib/docker/containers/9f2f80b0a702361d1ac432e6af816c19bda46da15c21264fb418c873de635a14/9f2f80b0a702361d1ac432e6a-json.log",
|
||||||
"docker_mountlabel": "",
|
"docker_mountlabel": "",
|
||||||
"docker_mounts": [],
|
"docker_mounts": [],
|
||||||
"docker_name": "/hello-world",
|
"docker_name": "/hello-world",
|
||||||
|
|
|
@ -1320,7 +1320,7 @@ class Ec2Inventory(object):
|
||||||
instance_vars[key] = value
|
instance_vars[key] = value
|
||||||
elif isinstance(value, six.string_types):
|
elif isinstance(value, six.string_types):
|
||||||
instance_vars[key] = value.strip()
|
instance_vars[key] = value.strip()
|
||||||
elif type(value) == type(None):
|
elif value is None:
|
||||||
instance_vars[key] = ''
|
instance_vars[key] = ''
|
||||||
elif key == 'ec2_region':
|
elif key == 'ec2_region':
|
||||||
instance_vars[key] = value.name
|
instance_vars[key] = value.name
|
||||||
|
@ -1431,7 +1431,7 @@ class Ec2Inventory(object):
|
||||||
|
|
||||||
# Target: Everything
|
# Target: Everything
|
||||||
# Replace None by an empty string
|
# Replace None by an empty string
|
||||||
elif type(value) == type(None):
|
elif value is None:
|
||||||
host_info[key] = ''
|
host_info[key] = ''
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -58,7 +58,8 @@ class MDTInventory(object):
|
||||||
Connect to MDT and dump contents of dbo.ComputerIdentity database
|
Connect to MDT and dump contents of dbo.ComputerIdentity database
|
||||||
'''
|
'''
|
||||||
if not self.conn:
|
if not self.conn:
|
||||||
self.conn = pymssql.connect(server=self.mdt_server + "\\" + self.mdt_instance, user=self.mdt_user, password=self.mdt_password, database=self.mdt_database)
|
self.conn = pymssql.connect(server=self.mdt_server + "\\" + self.mdt_instance, user=self.mdt_user, password=self.mdt_password,
|
||||||
|
database=self.mdt_database)
|
||||||
cursor = self.conn.cursor()
|
cursor = self.conn.cursor()
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
self.mdt_dump = cursor.fetchall()
|
self.mdt_dump = cursor.fetchall()
|
||||||
|
@ -69,7 +70,8 @@ class MDTInventory(object):
|
||||||
Gets host from MDT Database
|
Gets host from MDT Database
|
||||||
'''
|
'''
|
||||||
if hostname:
|
if hostname:
|
||||||
query = "SELECT t1.ID, t1.Description, t1.MacAddress, t2.Role FROM ComputerIdentity as t1 join Settings_Roles as t2 on t1.ID = t2.ID where t1.Description = '%s'" % hostname
|
query = ("SELECT t1.ID, t1.Description, t1.MacAddress, t2.Role "
|
||||||
|
"FROM ComputerIdentity as t1 join Settings_Roles as t2 on t1.ID = t2.ID where t1.Description = '%s'" % hostname)
|
||||||
else:
|
else:
|
||||||
query = 'SELECT t1.ID, t1.Description, t1.MacAddress, t2.Role FROM ComputerIdentity as t1 join Settings_Roles as t2 on t1.ID = t2.ID'
|
query = 'SELECT t1.ID, t1.Description, t1.MacAddress, t2.Role FROM ComputerIdentity as t1 join Settings_Roles as t2 on t1.ID = t2.ID'
|
||||||
self._connect(query)
|
self._connect(query)
|
||||||
|
|
|
@ -50,7 +50,14 @@ def get_guests():
|
||||||
#loop through guests
|
#loop through guests
|
||||||
for j in json_data:
|
for j in json_data:
|
||||||
#Add information to host vars
|
#Add information to host vars
|
||||||
inventory['_meta']['hostvars'][j['hostname']] = {'ctid': j['ctid'], 'veid': j['veid'], 'vpsid': j['vpsid'], 'private_path': j['private'], 'root_path': j['root'], 'ip': j['ip']}
|
inventory['_meta']['hostvars'][j['hostname']] = {
|
||||||
|
'ctid': j['ctid'],
|
||||||
|
'veid': j['veid'],
|
||||||
|
'vpsid': j['vpsid'],
|
||||||
|
'private_path': j['private'],
|
||||||
|
'root_path': j['root'],
|
||||||
|
'ip': j['ip']
|
||||||
|
}
|
||||||
|
|
||||||
#determine group from guest description
|
#determine group from guest description
|
||||||
if j['description'] is not None:
|
if j['description'] is not None:
|
||||||
|
|
|
@ -560,8 +560,12 @@ def report(version=None):
|
||||||
|
|
||||||
print('== Summary ==')
|
print('== Summary ==')
|
||||||
print('No Metadata: {0} Has Metadata: {1}'.format(len(no_metadata), len(has_metadata)))
|
print('No Metadata: {0} Has Metadata: {1}'.format(len(no_metadata), len(has_metadata)))
|
||||||
print('Supported by core: {0} Supported by community: {1} Supported by committer: {2}'.format(len(support['core']), len(support['community']), len(support['committer'])))
|
print('Supported by core: {0} Supported by community: {1} Supported by committer: {2}'.format(len(support['core']), len(support['community']),
|
||||||
print('Status StableInterface: {0} Status Preview: {1} Status Deprecated: {2} Status Removed: {3}'.format(len(status['stableinterface']), len(status['preview']), len(status['deprecated']), len(status['removed'])))
|
len(support['committer'])))
|
||||||
|
print('Status StableInterface: {0} Status Preview: {1} Status Deprecated: {2} Status Removed: {3}'.format(len(status['stableinterface']),
|
||||||
|
len(status['preview']),
|
||||||
|
len(status['deprecated']),
|
||||||
|
len(status['removed'])))
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
|
@ -135,7 +135,12 @@ def list_modules(module_dir, depth=0):
|
||||||
# * windows powershell modules have documentation stubs in python docstring
|
# * windows powershell modules have documentation stubs in python docstring
|
||||||
# format (they are not executed) so skip the ps1 format files
|
# format (they are not executed) so skip the ps1 format files
|
||||||
# * One glob level for every module level that we're going to traverse
|
# * One glob level for every module level that we're going to traverse
|
||||||
files = glob.glob("%s/*.py" % module_dir) + glob.glob("%s/*/*.py" % module_dir) + glob.glob("%s/*/*/*.py" % module_dir) + glob.glob("%s/*/*/*/*.py" % module_dir)
|
files = (
|
||||||
|
glob.glob("%s/*.py" % module_dir) +
|
||||||
|
glob.glob("%s/*/*.py" % module_dir) +
|
||||||
|
glob.glob("%s/*/*/*.py" % module_dir) +
|
||||||
|
glob.glob("%s/*/*/*/*.py" % module_dir)
|
||||||
|
)
|
||||||
|
|
||||||
for module_path in files:
|
for module_path in files:
|
||||||
if module_path.endswith('__init__.py'):
|
if module_path.endswith('__init__.py'):
|
||||||
|
@ -412,7 +417,8 @@ def process_category(category, categories, options, env, template, outputname):
|
||||||
|
|
||||||
category_file.write("""\n\n
|
category_file.write("""\n\n
|
||||||
.. note::
|
.. note::
|
||||||
- %s: This marks a module as deprecated, which means a module is kept for backwards compatibility but usage is discouraged. The module documentation details page may explain more about this rationale.
|
- %s: This marks a module as deprecated, which means a module is kept for backwards compatibility but usage is discouraged.
|
||||||
|
The module documentation details page may explain more about this rationale.
|
||||||
""" % DEPRECATED)
|
""" % DEPRECATED)
|
||||||
category_file.close()
|
category_file.close()
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,3 @@
|
||||||
contrib/inventory/abiquo.py
|
|
||||||
contrib/inventory/digital_ocean.py
|
|
||||||
contrib/inventory/docker.py
|
|
||||||
contrib/inventory/ec2.py
|
|
||||||
contrib/inventory/mdt_dynamic_inventory.py
|
|
||||||
contrib/inventory/openvz.py
|
|
||||||
contrib/inventory/rax.py
|
|
||||||
hacking/metadata-tool.py
|
|
||||||
hacking/module_formatter.py
|
|
||||||
lib/ansible/cli/__init__.py
|
lib/ansible/cli/__init__.py
|
||||||
lib/ansible/cli/galaxy.py
|
lib/ansible/cli/galaxy.py
|
||||||
lib/ansible/cli/playbook.py
|
lib/ansible/cli/playbook.py
|
||||||
|
|
Loading…
Reference in a new issue