summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcontrib/inventory/abiquo.py18
-rwxr-xr-xcontrib/inventory/digital_ocean.py19
-rwxr-xr-xcontrib/inventory/docker.py2
-rwxr-xr-xcontrib/inventory/ec2.py4
-rw-r--r--contrib/inventory/mdt_dynamic_inventory.py6
-rwxr-xr-xcontrib/inventory/openvz.py9
-rwxr-xr-xcontrib/inventory/rax.py4
-rwxr-xr-xhacking/metadata-tool.py8
-rwxr-xr-xhacking/module_formatter.py10
-rw-r--r--test/sanity/pep8/legacy-files.txt9
10 files changed, 49 insertions, 40 deletions
diff --git a/contrib/inventory/abiquo.py b/contrib/inventory/abiquo.py
index cea1624270..405bbbb61e 100755
--- a/contrib/inventory/abiquo.py
+++ b/contrib/inventory/abiquo.py
@@ -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']
@@ -137,7 +141,7 @@ 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:
@@ -145,7 +149,7 @@ def generate_inv_from_api(enterprise_entity,config):
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:
@@ -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)
diff --git a/contrib/inventory/digital_ocean.py b/contrib/inventory/digital_ocean.py
index f76cf0c442..07c124bc55 100755
--- a/contrib/inventory/digital_ocean.py
+++ b/contrib/inventory/digital_ocean.py
@@ -378,23 +378,18 @@ or environment variables (DO_API_TOKEN)\n''')
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:
diff --git a/contrib/inventory/docker.py b/contrib/inventory/docker.py
index a5f31f9607..cc7b61e6d2 100755
--- a/contrib/inventory/docker.py
+++ b/contrib/inventory/docker.py
@@ -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_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",
diff --git a/contrib/inventory/ec2.py b/contrib/inventory/ec2.py
index 2dc760af98..50c002abf2 100755
--- a/contrib/inventory/ec2.py
+++ b/contrib/inventory/ec2.py
@@ -1320,7 +1320,7 @@ class Ec2Inventory(object):
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
@@ -1431,7 +1431,7 @@ class Ec2Inventory(object):
# Target: Everything
# Replace None by an empty string
- elif type(value) == type(None):
+ elif value is None:
host_info[key] = ''
else:
diff --git a/contrib/inventory/mdt_dynamic_inventory.py b/contrib/inventory/mdt_dynamic_inventory.py
index dd2f5b8eac..89ecc3ec53 100644
--- a/contrib/inventory/mdt_dynamic_inventory.py
+++ b/contrib/inventory/mdt_dynamic_inventory.py
@@ -58,7 +58,8 @@ class MDTInventory(object):
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()
@@ -69,7 +70,8 @@ class MDTInventory(object):
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)
diff --git a/contrib/inventory/openvz.py b/contrib/inventory/openvz.py
index 68d51c8a42..1ef8ab1448 100755
--- a/contrib/inventory/openvz.py
+++ b/contrib/inventory/openvz.py
@@ -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:
diff --git a/contrib/inventory/rax.py b/contrib/inventory/rax.py
index 4ef2e130d7..d20a8ab6a7 100755
--- a/contrib/inventory/rax.py
+++ b/contrib/inventory/rax.py
@@ -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)
diff --git a/hacking/metadata-tool.py b/hacking/metadata-tool.py
index df0a2fb702..795511f7f9 100755
--- a/hacking/metadata-tool.py
+++ b/hacking/metadata-tool.py
@@ -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
diff --git a/hacking/module_formatter.py b/hacking/module_formatter.py
index 33204ff1b7..4f132aa0cf 100755
--- a/hacking/module_formatter.py
+++ b/hacking/module_formatter.py
@@ -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'):
@@ -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()
diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt
index fffcc4fbec..1b205ce49f 100644
--- a/test/sanity/pep8/legacy-files.txt
+++ b/test/sanity/pep8/legacy-files.txt
@@ -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