mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-28 21:31:26 -07:00
azure - fix for: temporary redirect, not deleted vhds, missing locations and role types, async api calls
This commit is contained in:
parent
aaa16acdf1
commit
188a13efc0
2 changed files with 155 additions and 85 deletions
|
@ -80,8 +80,9 @@ class AzureInventory(object):
|
|||
elif not self.is_cache_valid():
|
||||
self.do_api_calls_update_cache()
|
||||
|
||||
# Data to print
|
||||
if self.args.list:
|
||||
if self.args.list_images:
|
||||
data_to_print = self.json_format_dict(self.get_images(), True)
|
||||
elif self.args.list:
|
||||
# Display list of nodes for inventory
|
||||
if len(self.inventory) == 0:
|
||||
data_to_print = self.get_inventory_from_cache()
|
||||
|
@ -90,6 +91,13 @@ class AzureInventory(object):
|
|||
|
||||
print data_to_print
|
||||
|
||||
def get_images(self):
|
||||
images = []
|
||||
for image in self.sms.list_os_images():
|
||||
if str(image.label).lower().find(self.args.list_images.lower()) >= 0:
|
||||
images.append(vars(image))
|
||||
return json.loads(json.dumps(images, default=lambda o: o.__dict__))
|
||||
|
||||
def is_cache_valid(self):
|
||||
"""Determines if the cache file has expired, or if it is still valid."""
|
||||
if os.path.isfile(self.cache_path_cache):
|
||||
|
@ -131,6 +139,8 @@ class AzureInventory(object):
|
|||
parser = argparse.ArgumentParser(description='Produce an Ansible Inventory file based on Azure')
|
||||
parser.add_argument('--list', action='store_true', default=True,
|
||||
help='List nodes (default: True)')
|
||||
parser.add_argument('--list-images', action='store',
|
||||
help='Get all available images.')
|
||||
parser.add_argument('--refresh-cache', action='store_true', default=False,
|
||||
help='Force refresh of cache by making API requests to Azure (default: False - use cache files)')
|
||||
self.args = parser.parse_args()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue