From 758cfeb73eac58d0ee009bfb696c23379c47fd07 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Tue, 30 May 2017 22:08:09 +0200 Subject: [PATCH] contrib: PEP8 compliancy (#24680) - Make PEP8 compliant --- contrib/inventory/freeipa.py | 11 ++++++++--- contrib/inventory/rackhd.py | 27 ++++++++++++++------------- contrib/inventory/vmware_inventory.py | 4 +--- test/sanity/pep8/legacy-files.txt | 3 --- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/contrib/inventory/freeipa.py b/contrib/inventory/freeipa.py index a72b774cfa..c07fe335ba 100755 --- a/contrib/inventory/freeipa.py +++ b/contrib/inventory/freeipa.py @@ -4,6 +4,7 @@ import argparse from ipalib import api import json + def initialize(): ''' This function initializes the FreeIPA/IPA API. This function requires @@ -16,11 +17,12 @@ def initialize(): try: api.Backend.rpcclient.connect() except AttributeError: - #FreeIPA < 4.0 compatibility + # FreeIPA < 4.0 compatibility api.Backend.xmlclient.connect() return api + def list_groups(api): ''' This function prints a list of all host groups. This function requires @@ -28,8 +30,8 @@ def list_groups(api): ''' inventory = {} - hostvars={} - meta={} + hostvars = {} + meta = {} result = api.Command.hostgroup_find()['result'] @@ -51,6 +53,7 @@ def list_groups(api): return None + def parse_args(): ''' This function parses the arguments that were passed in via the command line. @@ -66,6 +69,7 @@ def parse_args(): return parser.parse_args() + def print_host(host): ''' This function is really a stub, it could return variables to be used in @@ -79,6 +83,7 @@ def print_host(host): return None + if __name__ == '__main__': args = parse_args() diff --git a/contrib/inventory/rackhd.py b/contrib/inventory/rackhd.py index a89cb041e4..63e59dedcf 100755 --- a/contrib/inventory/rackhd.py +++ b/contrib/inventory/rackhd.py @@ -1,31 +1,32 @@ #!/usr/bin/env python -import json -import requests -import os import argparse +import json +import os +import requests import types RACKHD_URL = 'http://localhost:8080' + class RackhdInventory(object): def __init__(self, nodeids): self._inventory = {} for nodeid in nodeids: self._load_inventory_data(nodeid) inventory = {} - for nodeid,info in self._inventory.items(): - inventory[nodeid]= (self._format_output(nodeid, info)) + for (nodeid, info) in self._inventory.items(): + inventory[nodeid] = (self._format_output(nodeid, info)) print(json.dumps(inventory)) def _load_inventory_data(self, nodeid): info = {} - info['ohai'] = RACKHD_URL + '/api/common/nodes/{0}/catalogs/ohai'.format(nodeid ) + info['ohai'] = RACKHD_URL + '/api/common/nodes/{0}/catalogs/ohai'.format(nodeid) info['lookup'] = RACKHD_URL + '/api/common/lookups/?q={0}'.format(nodeid) results = {} - for key,url in info.items(): - r = requests.get( url, verify=False) + for (key, url) in info.items(): + r = requests.get(url, verify=False) results[key] = r.text self._inventory[nodeid] = results @@ -35,8 +36,8 @@ class RackhdInventory(object): ipaddress = '' if len(node_info) > 0: ipaddress = node_info[0]['ipAddress'] - output = { 'hosts':[ipaddress],'vars':{}} - for key,result in info.items(): + output = {'hosts': [ipaddress], 'vars': {}} + for (key, result) in info.items(): output['vars'][key] = json.loads(result) output['vars']['ansible_ssh_user'] = 'monorail' except KeyError: @@ -51,10 +52,10 @@ def parse_args(): return parser.parse_args() try: - #check if rackhd url(ie:10.1.1.45:8080) is specified in the environment + # check if rackhd url(ie:10.1.1.45:8080) is specified in the environment RACKHD_URL = 'http://' + str(os.environ['RACKHD_URL']) except: - #use default values + # use default values pass # Use the nodeid specified in the environment to limit the data returned @@ -70,7 +71,7 @@ if (parse_args().host): if (parse_args().list): try: url = RACKHD_URL + '/api/common/nodes' - r = requests.get( url, verify=False) + r = requests.get(url, verify=False) data = json.loads(r.text) for entry in data: if entry['type'] == 'compute': diff --git a/contrib/inventory/vmware_inventory.py b/contrib/inventory/vmware_inventory.py index 893ff5866b..8ef943819a 100755 --- a/contrib/inventory/vmware_inventory.py +++ b/contrib/inventory/vmware_inventory.py @@ -426,7 +426,7 @@ class VMWareInventory(object): # Reset the inventory keys for k, v in name_mapping.items(): - if not host_mapping or not k in host_mapping: + if not host_mapping or k not in host_mapping: continue # set ansible_host (2.x) @@ -742,5 +742,3 @@ class VMWareInventory(object): if __name__ == "__main__": # Run the script print(VMWareInventory().show()) - - diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt index f1cddcc630..854aecc246 100644 --- a/test/sanity/pep8/legacy-files.txt +++ b/test/sanity/pep8/legacy-files.txt @@ -1,6 +1,3 @@ -contrib/inventory/freeipa.py -contrib/inventory/rackhd.py -contrib/inventory/vmware_inventory.py lib/ansible/cli/__init__.py lib/ansible/cli/adhoc.py lib/ansible/cli/console.py