Skip to content

Commit

Permalink
Legacy pep8 clean fixes for contrib and hacking (ansible#21081)
Browse files Browse the repository at this point in the history
  • Loading branch information
sivel authored Feb 7, 2017
1 parent 0de96d6 commit 5942de6
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 40 deletions.
18 changes: 11 additions & 7 deletions contrib/inventory/abiquo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = api_get(vms_entity,config)
for vmcollection in vms['collection']:
vm_vapp = next(link for link in (vmcollection['links']) if (link['rel']=='virtualappliance'))['title'].replace('[','').replace(']','').replace(' ','_')
vm_vdc = next(link for link in (vmcollection['links']) if (link['rel']=='virtualdatacenter'))['title'].replace('[','').replace(']','').replace(' ','_')
vm_template = next(link for link in (vmcollection['links']) if (link['rel']=='virtualmachinetemplate'))['title'].replace('[','').replace(']','').replace(' ','_')
for link in vmcollection['links']:
if link['rel'] == 'virtualappliance':
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
if (config.getboolean('defaults', 'public_ip_only')) == True:
if config.getboolean('defaults', 'public_ip_only') is True:
for link in vmcollection['links']:
if (link['type']=='application/vnd.abiquo.publicip+json' and link['rel']=='ip'):
vm_nic = link['title']
Expand All @@ -137,15 +141,15 @@ def generate_inv_from_api(enterprise_entity,config):
# Otherwise, assigning defined network interface IP address
else:
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']
break
else:
vm_nic = None

vm_state = True
# 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

if vm_nic is not None and vm_state:
Expand All @@ -161,7 +165,7 @@ def generate_inv_from_api(enterprise_entity,config):
inventory[vm_template] = {}
inventory[vm_template]['children'] = []
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'))
try:
metadata = api_get(meta_entity,config)
Expand Down
19 changes: 7 additions & 12 deletions contrib/inventory/digital_ocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,23 +378,18 @@ def build_inventory(self):
self.inventory[droplet['name']] = [dest]

# groups that are always present
for group in [
'region_' + droplet['region']['slug'],
'image_' + str(droplet['image']['id']),
'size_' + droplet['size']['slug'],
'distro_' + self.to_safe(droplet['image']['distribution']),
'status_' + droplet['status'],

]:
for group in ('region_' + droplet['region']['slug'],
'image_' + str(droplet['image']['id']),
'size_' + droplet['size']['slug'],
'distro_' + self.to_safe(droplet['image']['distribution']),
'status_' + droplet['status']):
if group not in self.inventory:
self.inventory[group] = { 'hosts': [ ], 'vars': {} }
self.inventory[group]['hosts'].append(dest)

# groups that are not always present
for group in [
droplet['image']['slug'],
droplet['image']['name']
]:
for group in (droplet['image']['slug'],
droplet['image']['name']):
if group:
image = 'image_' + self.to_safe(group)
if image not in self.inventory:
Expand Down
2 changes: 1 addition & 1 deletion contrib/inventory/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
"docker_hostspath": "/mnt/sda1/var/lib/docker/containers/9f2f80b0a702361d1ac432e6af816c19bda46da15c21264fb418c873de635a14/hosts",
"docker_id": "9f2f80b0a702361d1ac432e6af816c19bda46da15c21264fb418c873de635a14",
"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_mounts": [],
"docker_name": "/hello-world",
Expand Down
4 changes: 2 additions & 2 deletions contrib/inventory/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ def get_host_info_dict_from_instance(self, instance):
instance_vars[key] = value
elif isinstance(value, six.string_types):
instance_vars[key] = value.strip()
elif type(value) == type(None):
elif value is None:
instance_vars[key] = ''
elif key == 'ec2_region':
instance_vars[key] = value.name
Expand Down Expand Up @@ -1431,7 +1431,7 @@ def get_host_info_dict_from_describe_dict(self, describe_dict):

# Target: Everything
# Replace None by an empty string
elif type(value) == type(None):
elif value is None:
host_info[key] = ''

else:
Expand Down
6 changes: 4 additions & 2 deletions contrib/inventory/mdt_dynamic_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def _connect(self, query):
Connect to MDT and dump contents of dbo.ComputerIdentity database
'''
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.execute(query)
self.mdt_dump = cursor.fetchall()
Expand All @@ -69,7 +70,8 @@ def get_hosts(self, hostname=False):
Gets host from MDT Database
'''
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:
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)
Expand Down
9 changes: 8 additions & 1 deletion contrib/inventory/openvz.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ def get_guests():
#loop through guests
for j in json_data:
#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
if j['description'] is not None:
Expand Down
4 changes: 2 additions & 2 deletions contrib/inventory/rax.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ def _list(regions, refresh_cache=True):
'RAX_CACHE_MAX_AGE', 600))

if (not os.path.exists(get_cache_file_path(regions)) or
refresh_cache or
(time() - os.stat(get_cache_file_path(regions))[-1]) > cache_max_age):
refresh_cache or
(time() - os.stat(get_cache_file_path(regions))[-1]) > cache_max_age):
# Cache file doesn't exist or older than 10m or refresh cache requested
_list_into_cache(regions)

Expand Down
8 changes: 6 additions & 2 deletions hacking/metadata-tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,12 @@ def report(version=None):

print('== Summary ==')
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('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'])))
print('Supported by core: {0} Supported by community: {1} Supported by committer: {2}'.format(len(support['core']), len(support['community']),
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

Expand Down
10 changes: 8 additions & 2 deletions hacking/module_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ def list_modules(module_dir, depth=0):
# * windows powershell modules have documentation stubs in python docstring
# format (they are not executed) so skip the ps1 format files
# * 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:
if module_path.endswith('__init__.py'):
Expand Down Expand Up @@ -412,7 +417,8 @@ def process_category(category, categories, options, env, template, outputname):

category_file.write("""\n\n
.. 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)
category_file.close()

Expand Down
9 changes: 0 additions & 9 deletions test/sanity/pep8/legacy-files.txt
Original file line number Diff line number Diff line change
@@ -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/galaxy.py
lib/ansible/cli/playbook.py
Expand Down

0 comments on commit 5942de6

Please sign in to comment.