mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 03:41:25 -07:00
pep8 fixes for contrib (#24344)
This commit is contained in:
parent
c7ae6b9fd5
commit
d3249e7875
37 changed files with 326 additions and 380 deletions
|
@ -82,7 +82,6 @@ class LibcloudInventory(object):
|
|||
|
||||
print(data_to_print)
|
||||
|
||||
|
||||
def is_cache_valid(self):
|
||||
''' Determines if the cache files have expired, or if it is still valid '''
|
||||
|
||||
|
@ -95,7 +94,6 @@ class LibcloudInventory(object):
|
|||
|
||||
return False
|
||||
|
||||
|
||||
def read_settings(self):
|
||||
''' Reads the settings from the libcloud.ini file '''
|
||||
|
||||
|
@ -108,17 +106,17 @@ class LibcloudInventory(object):
|
|||
raise ValueError('libcloud.ini file must contain a [driver] section')
|
||||
|
||||
if config.has_option('driver', 'provider'):
|
||||
self.provider = config.get('driver','provider')
|
||||
self.provider = config.get('driver', 'provider')
|
||||
else:
|
||||
raise ValueError('libcloud.ini does not have a provider defined')
|
||||
|
||||
if config.has_option('driver', 'key'):
|
||||
self.key = config.get('driver','key')
|
||||
self.key = config.get('driver', 'key')
|
||||
else:
|
||||
raise ValueError('libcloud.ini does not have a key defined')
|
||||
|
||||
if config.has_option('driver', 'secret'):
|
||||
self.secret = config.get('driver','secret')
|
||||
self.secret = config.get('driver', 'secret')
|
||||
else:
|
||||
raise ValueError('libcloud.ini does not have a secret defined')
|
||||
|
||||
|
@ -146,7 +144,6 @@ class LibcloudInventory(object):
|
|||
self.cache_path_index = cache_path + "/ansible-libcloud.index"
|
||||
self.cache_max_age = config.getint('cache', 'cache_max_age')
|
||||
|
||||
|
||||
def parse_cli_args(self):
|
||||
'''
|
||||
Command line argument processing
|
||||
|
@ -154,14 +151,13 @@ class LibcloudInventory(object):
|
|||
|
||||
parser = argparse.ArgumentParser(description='Produce an Ansible Inventory file based on libcloud supported providers')
|
||||
parser.add_argument('--list', action='store_true', default=True,
|
||||
help='List instances (default: True)')
|
||||
help='List instances (default: True)')
|
||||
parser.add_argument('--host', action='store',
|
||||
help='Get all the variables about a specific instance')
|
||||
help='Get all the variables about a specific instance')
|
||||
parser.add_argument('--refresh-cache', action='store_true', default=False,
|
||||
help='Force refresh of cache by making API requests to libcloud supported providers (default: False - use cache files)')
|
||||
help='Force refresh of cache by making API requests to libcloud supported providers (default: False - use cache files)')
|
||||
self.args = parser.parse_args()
|
||||
|
||||
|
||||
def do_api_calls_update_cache(self):
|
||||
'''
|
||||
Do API calls to a location, and save data in cache files
|
||||
|
@ -172,7 +168,6 @@ class LibcloudInventory(object):
|
|||
self.write_to_cache(self.inventory, self.cache_path_cache)
|
||||
self.write_to_cache(self.index, self.cache_path_index)
|
||||
|
||||
|
||||
def get_nodes(self):
|
||||
'''
|
||||
Gets the list of all nodes
|
||||
|
@ -181,7 +176,6 @@ class LibcloudInventory(object):
|
|||
for node in self.conn.list_nodes():
|
||||
self.add_node(node)
|
||||
|
||||
|
||||
def get_node(self, node_id):
|
||||
'''
|
||||
Gets details about a specific node
|
||||
|
@ -189,7 +183,6 @@ class LibcloudInventory(object):
|
|||
|
||||
return [node for node in self.conn.list_nodes() if node.id == node_id][0]
|
||||
|
||||
|
||||
def add_node(self, node):
|
||||
'''
|
||||
Adds a node to the inventory and index, as long as it is
|
||||
|
@ -244,10 +237,10 @@ class LibcloudInventory(object):
|
|||
# Need to load index from cache
|
||||
self.load_index_from_cache()
|
||||
|
||||
if not self.args.host in self.index:
|
||||
if self.args.host not in self.index:
|
||||
# try updating the cache
|
||||
self.do_api_calls_update_cache()
|
||||
if not self.args.host in self.index:
|
||||
if self.args.host not in self.index:
|
||||
# host migh not exist anymore
|
||||
return self.json_format_dict({}, True)
|
||||
|
||||
|
@ -283,13 +276,12 @@ class LibcloudInventory(object):
|
|||
else:
|
||||
pass
|
||||
# TODO Product codes if someone finds them useful
|
||||
#print(key)
|
||||
#print(type(value))
|
||||
#print(value)
|
||||
# print(key)
|
||||
# print(type(value))
|
||||
# print(value)
|
||||
|
||||
return self.json_format_dict(instance_vars, True)
|
||||
|
||||
|
||||
def push(self, my_dict, key, element):
|
||||
'''
|
||||
Pushed an element onto an array that may not have been defined in
|
||||
|
@ -301,7 +293,6 @@ class LibcloudInventory(object):
|
|||
else:
|
||||
my_dict[key] = [element]
|
||||
|
||||
|
||||
def get_inventory_from_cache(self):
|
||||
'''
|
||||
Reads the inventory from the cache file and returns it as a JSON
|
||||
|
@ -312,7 +303,6 @@ class LibcloudInventory(object):
|
|||
json_inventory = cache.read()
|
||||
return json_inventory
|
||||
|
||||
|
||||
def load_index_from_cache(self):
|
||||
'''
|
||||
Reads the index from the cache file sets self.index
|
||||
|
@ -322,7 +312,6 @@ class LibcloudInventory(object):
|
|||
json_index = cache.read()
|
||||
self.index = json.loads(json_index)
|
||||
|
||||
|
||||
def write_to_cache(self, data, filename):
|
||||
'''
|
||||
Writes data in JSON format to a file
|
||||
|
@ -333,7 +322,6 @@ class LibcloudInventory(object):
|
|||
cache.write(json_data)
|
||||
cache.close()
|
||||
|
||||
|
||||
def to_safe(self, word):
|
||||
'''
|
||||
Converts 'bad' characters in a string to underscores so they can be
|
||||
|
@ -342,7 +330,6 @@ class LibcloudInventory(object):
|
|||
|
||||
return re.sub("[^A-Za-z0-9\-]", "_", word)
|
||||
|
||||
|
||||
def json_format_dict(self, data, pretty=False):
|
||||
'''
|
||||
Converts a dict to a JSON object and dumps it as a formatted
|
||||
|
@ -354,6 +341,7 @@ class LibcloudInventory(object):
|
|||
else:
|
||||
return json.dumps(data)
|
||||
|
||||
|
||||
def main():
|
||||
LibcloudInventory()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue