mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Brook inventory (#16122)
* Do not ask for templates in Brook inventory if they do not exist * Add availability zone variable to Brook inventory * Add provider id variable to Brook inventory * Error output sent to stderr in Brook inventory
This commit is contained in:
parent
73438de862
commit
0fa797030e
1 changed files with 10 additions and 7 deletions
|
@ -32,11 +32,13 @@ included, provided the requesting user belongs to it.
|
||||||
|
|
||||||
The following variables are established for every host. They can be retrieved from the hostvars
|
The following variables are established for every host. They can be retrieved from the hostvars
|
||||||
dictionary.
|
dictionary.
|
||||||
|
- brook_pid: str
|
||||||
- brook_name: str
|
- brook_name: str
|
||||||
- brook_description: str
|
- brook_description: str
|
||||||
- brook_project: str
|
- brook_project: str
|
||||||
- brook_template: str
|
- brook_template: str
|
||||||
- brook_region: str
|
- brook_region: str
|
||||||
|
- brook_zone: str
|
||||||
- brook_status: str
|
- brook_status: str
|
||||||
- brook_tags: list(str)
|
- brook_tags: list(str)
|
||||||
- brook_internal_ips: list(str)
|
- brook_internal_ips: list(str)
|
||||||
|
@ -70,7 +72,7 @@ Support:
|
||||||
This script is tested on Python 2.7 and 3.4. It may work on other versions though.
|
This script is tested on Python 2.7 and 3.4. It may work on other versions though.
|
||||||
|
|
||||||
Author: Francisco Ros <fjros@doalitic.com>
|
Author: Francisco Ros <fjros@doalitic.com>
|
||||||
Version: 0.1
|
Version: 0.2
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
@ -122,9 +124,8 @@ class BrookInventory:
|
||||||
self.project_id = config.get('brook', 'project_id')
|
self.project_id = config.get('brook', 'project_id')
|
||||||
|
|
||||||
if not self.api_token:
|
if not self.api_token:
|
||||||
print('You must provide (at least) your Brook.io API token to generate the dynamic '
|
sys.exit('You must provide (at least) your Brook.io API token to generate the dynamic '
|
||||||
'inventory.')
|
'inventory.')
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def get_api_client(self):
|
def get_api_client(self):
|
||||||
"""Authenticate user via the provided credentials and return the corresponding API client.
|
"""Authenticate user via the provided credentials and return the corresponding API client.
|
||||||
|
@ -168,8 +169,8 @@ class BrookInventory:
|
||||||
for project_id in projects:
|
for project_id in projects:
|
||||||
project = projects_api.show_project(project_id=project_id)
|
project = projects_api.show_project(project_id=project_id)
|
||||||
for instance in instances_api.index_instances(project_id=project_id):
|
for instance in instances_api.index_instances(project_id=project_id):
|
||||||
# Get template used for this instance
|
# Get template used for this instance if known
|
||||||
template = templates_api.show_template(template_id=instance.template)
|
template = templates_api.show_template(template_id=instance.template) if instance.template else None
|
||||||
|
|
||||||
# Update hostvars
|
# Update hostvars
|
||||||
try:
|
try:
|
||||||
|
@ -212,11 +213,13 @@ class BrookInventory:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
hostvars = instance.to_dict()
|
hostvars = instance.to_dict()
|
||||||
|
hostvars['brook_pid'] = hostvars.pop('pid')
|
||||||
hostvars['brook_name'] = hostvars.pop('name')
|
hostvars['brook_name'] = hostvars.pop('name')
|
||||||
hostvars['brook_description'] = hostvars.pop('description')
|
hostvars['brook_description'] = hostvars.pop('description')
|
||||||
hostvars['brook_project'] = hostvars.pop('project')
|
hostvars['brook_project'] = hostvars.pop('project')
|
||||||
hostvars['brook_template'] = hostvars.pop('template')
|
hostvars['brook_template'] = hostvars.pop('template')
|
||||||
hostvars['brook_region'] = hostvars.pop('region')
|
hostvars['brook_region'] = hostvars.pop('region')
|
||||||
|
hostvars['brook_zone'] = hostvars.pop('zone')
|
||||||
hostvars['brook_created_at'] = hostvars.pop('created_at')
|
hostvars['brook_created_at'] = hostvars.pop('created_at')
|
||||||
hostvars['brook_updated_at'] = hostvars.pop('updated_at')
|
hostvars['brook_updated_at'] = hostvars.pop('updated_at')
|
||||||
del hostvars['id']
|
del hostvars['id']
|
||||||
|
@ -227,7 +230,7 @@ class BrookInventory:
|
||||||
# Substitute identifiers for names
|
# Substitute identifiers for names
|
||||||
#
|
#
|
||||||
hostvars['brook_project'] = project.name
|
hostvars['brook_project'] = project.name
|
||||||
hostvars['brook_template'] = template.name
|
hostvars['brook_template'] = template.name if template else None
|
||||||
|
|
||||||
# Retrieve instance state
|
# Retrieve instance state
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in a new issue