mirror of
https://github.com/ansible-collections/hetzner.hcloud
synced 2024-11-10 06:34:13 +00:00
feat: add server_types to datacenter info module (#379)
##### SUMMARY Closes #204 Return the `server_types` dict when querying the datacenters. ##### ISSUE TYPE - Feature Pull Request ##### COMPONENT NAME hcloud_datacenter_info
This commit is contained in:
parent
c491799f6f
commit
084e04d576
2 changed files with 59 additions and 9 deletions
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- hcloud_datacenter_info - Add `server_types` field
|
|
@ -35,9 +35,27 @@ EXAMPLES = """
|
|||
- name: Gather hcloud datacenter info
|
||||
hetzner.hcloud.hcloud_datacenter_info:
|
||||
register: output
|
||||
|
||||
- name: Print the gathered info
|
||||
debug:
|
||||
var: output
|
||||
|
||||
- name: List available server_types in a datacenter
|
||||
block:
|
||||
- name: Gather a hcloud datacenter
|
||||
hetzner.hcloud.hcloud_datacenter_info:
|
||||
name: fsn1-dc14
|
||||
register: output
|
||||
|
||||
- name: Gather a hcloud datacenter available server_types
|
||||
hetzner.hcloud.hcloud_server_type_info:
|
||||
id: "{{ item }}"
|
||||
loop: "{{ output.hcloud_datacenter_info[0].server_types.available }}"
|
||||
register: available_server_types
|
||||
|
||||
- name: Print a hcloud datacenter available server_types
|
||||
ansible.builtin.debug:
|
||||
var: available_server_types.results | map(attribute='hcloud_server_type_info')
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
|
@ -72,6 +90,29 @@ hcloud_datacenter_info:
|
|||
returned: always
|
||||
type: str
|
||||
sample: fsn1
|
||||
server_types:
|
||||
description: The Server types the Datacenter can handle
|
||||
returned: always
|
||||
type: dict
|
||||
contains:
|
||||
available:
|
||||
description: IDs of Server types that are supported and for which the Datacenter has enough resources left
|
||||
returned: always
|
||||
type: list
|
||||
elements: int
|
||||
sample: [1, 2, 3]
|
||||
available_for_migration:
|
||||
description: IDs of Server types that are supported and for which the Datacenter has enough resources left
|
||||
returned: always
|
||||
type: list
|
||||
elements: int
|
||||
sample: [1, 2, 3]
|
||||
supported:
|
||||
description: IDs of Server types that are supported in the Datacenter
|
||||
returned: always
|
||||
type: list
|
||||
elements: int
|
||||
sample: [1, 2, 3]
|
||||
"""
|
||||
|
||||
from typing import List, Optional
|
||||
|
@ -93,15 +134,22 @@ class AnsibleHCloudDatacenterInfo(AnsibleHCloud):
|
|||
tmp = []
|
||||
|
||||
for datacenter in self.hcloud_datacenter_info:
|
||||
if datacenter is not None:
|
||||
tmp.append(
|
||||
{
|
||||
"id": to_native(datacenter.id),
|
||||
"name": to_native(datacenter.name),
|
||||
"description": to_native(datacenter.description),
|
||||
"location": to_native(datacenter.location.name),
|
||||
}
|
||||
)
|
||||
if datacenter is None:
|
||||
continue
|
||||
|
||||
tmp.append(
|
||||
{
|
||||
"id": to_native(datacenter.id),
|
||||
"name": to_native(datacenter.name),
|
||||
"description": to_native(datacenter.description),
|
||||
"location": to_native(datacenter.location.name),
|
||||
"server_types": {
|
||||
"available": [o.id for o in datacenter.server_types.available],
|
||||
"available_for_migration": [o.id for o in datacenter.server_types.available_for_migration],
|
||||
"supported": [o.id for o in datacenter.server_types.supported],
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
return tmp
|
||||
|
||||
|
|
Loading…
Reference in a new issue