1
0
Fork 0
mirror of https://github.com/ansible-collections/hetzner.hcloud.git synced 2026-02-04 08:01:49 +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:
Jonas L 2023-11-06 15:23:20 +01:00 committed by GitHub
parent c491799f6f
commit 084e04d576
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 9 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- hcloud_datacenter_info - Add `server_types` field

View file

@ -35,9 +35,27 @@ EXAMPLES = """
- name: Gather hcloud datacenter info - name: Gather hcloud datacenter info
hetzner.hcloud.hcloud_datacenter_info: hetzner.hcloud.hcloud_datacenter_info:
register: output register: output
- name: Print the gathered info - name: Print the gathered info
debug: debug:
var: output 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 = """ RETURN = """
@ -72,6 +90,29 @@ hcloud_datacenter_info:
returned: always returned: always
type: str type: str
sample: fsn1 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 from typing import List, Optional
@ -93,15 +134,22 @@ class AnsibleHCloudDatacenterInfo(AnsibleHCloud):
tmp = [] tmp = []
for datacenter in self.hcloud_datacenter_info: for datacenter in self.hcloud_datacenter_info:
if datacenter is not None: if datacenter is None:
tmp.append( continue
{
"id": to_native(datacenter.id), tmp.append(
"name": to_native(datacenter.name), {
"description": to_native(datacenter.description), "id": to_native(datacenter.id),
"location": to_native(datacenter.location.name), "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 return tmp