Add host_aggregate_info module

This module allows operators to get informations on
compute aggregates in a cluster, including availability zone
informations and hosts membership.

Change-Id: I14fa8d6914072bee314efa3753633933b21e9439
Signed-off-by: Bertrand Lanson <bertrand.lanson@infomaniak.com>
This commit is contained in:
Bertrand Lanson
2026-05-19 20:50:29 +02:00
parent 7644aeaf32
commit 94bb10a5ee
3 changed files with 205 additions and 0 deletions

View File

@@ -0,0 +1,107 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (c) 2025 OpenStack Ansible SIG
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
DOCUMENTATION = r'''
---
module: host_aggregate_info
short_description: Fetch OpenStack host aggregates
author: OpenStack Ansible SIG
description:
- Fetch OpenStack host aggregates.
options:
name:
description:
- Name or ID of the aggregate.
- Returns only the matching aggregate when set.
type: str
extends_documentation_fragment:
- openstack.cloud.openstack
'''
EXAMPLES = r'''
- name: Fetch all host aggregates
openstack.cloud.host_aggregate_info:
cloud: mycloud
- name: Fetch a specific host aggregate by name
openstack.cloud.host_aggregate_info:
cloud: mycloud
name: db_aggregate
'''
RETURN = r'''
aggregates:
description: List of dictionaries describing host aggregates.
returned: always
type: list
elements: dict
contains:
availability_zone:
description: Availability zone of the aggregate.
type: str
created_at:
description: The date and time when the resource was created.
type: str
deleted_at:
description: The date and time when the resource was deleted.
type: str
hosts:
description: List of hosts belonging to the aggregate.
type: list
elements: str
id:
description: The UUID of the aggregate.
type: str
is_deleted:
description: Whether or not the resource is deleted.
type: bool
metadata:
description: Metadata attached to the aggregate.
type: dict
name:
description: Name of the aggregate.
type: str
updated_at:
description: The date and time when the resource was updated.
type: str
uuid:
description: UUID of the aggregate.
type: str
'''
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
class ComputeHostAggregateInfoModule(OpenStackModule):
argument_spec = dict(
name=dict(),
)
module_kwargs = dict(
supports_check_mode=True
)
def run(self):
name = self.params['name']
if name:
aggregate = self.conn.compute.find_aggregate(name)
aggregates = [aggregate] if aggregate else []
else:
aggregates = list(self.conn.compute.aggregates())
self.exit_json(changed=False,
aggregates=[a.to_dict(computed=False)
for a in aggregates])
def main():
module = ComputeHostAggregateInfoModule()
module()
if __name__ == '__main__':
main()