1
0
Fork 0
mirror of https://github.com/ansible-collections/hetzner.hcloud.git synced 2026-02-04 08:01:49 +00:00

feat: support for Storage Box Types (#744)

- Add `storage_box_type_info` module
This commit is contained in:
Jonas L. 2025-11-18 18:07:58 +01:00 committed by jo
parent 55352c45fe
commit 2c0bc64022
No known key found for this signature in database
GPG key ID: B2FEC9B22722B984
46 changed files with 438 additions and 0 deletions

View file

@ -0,0 +1,185 @@
#!/usr/bin/python
# Copyright: (c) 2025, Hetzner Cloud GmbH <info@hetzner-cloud.de>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = """
---
module: storage_box_type_info
short_description: Gather infos about the Hetzner Storage Box Types.
description:
- Gather infos about available Hetzner Storage Box Types.
author:
- Jonas Lammler (@jooola)
options:
id:
description:
- ID of the Storage Box Type to get.
- If the ID is invalid, the module will fail.
type: int
name:
description:
- Name of the Storage Box Type to get.
type: str
extends_documentation_fragment:
- hetzner.hcloud.hcloud
"""
EXAMPLES = """
- name: Gather Storage Box Types infos
hetzner.hcloud.storage_box_type_info:
register: output
- name: Print the gathered infos
debug:
var: output.hcloud_storage_box_type_info
"""
RETURN = """
hcloud_storage_box_type_info:
description: List of Storage Box Types.
returned: always
type: list
contains:
id:
description: ID of the Storage Box Type.
returned: success
type: int
sample: 1937415
name:
description: Name of the Storage Box Type.
returned: success
type: str
sample: bx21
description:
description: Description of the Storage Box Type.
returned: success
type: str
sample: BX21
snapshot_limit:
description: Maximum number of allowed manual snapshots.
returned: success
type: int
sample: 10
automatic_snapshot_limit:
description: Maximum number of snapshots created automatically by a snapshot plan.
returned: success
type: int
sample: 10
subaccounts_limit:
description: Maximum number of subaccounts.
returned: success
type: int
sample: 200
size:
description: Available storage in bytes.
returned: success
type: int
sample: 1099511627776
deprecation:
description: Deprecation details about the Storage Box Type.
returned: when deprecated
type: dict
contains:
announced:
description: Date when the deprecation was announced.
returned: success
type: str
sample: "2025-06-02T00:00:00Z"
unavailable_after:
description: |
Date when the resource will stop being available.
The resource will be removed from the list endpoint, but details
about the resource can be fetched using its ID.
returned: success
type: str
sample: "2025-09-02T00:00:00Z"
"""
from ansible.module_utils.basic import AnsibleModule
from ..module_utils.hcloud import AnsibleHCloud
from ..module_utils.vendor.hcloud import HCloudException
from ..module_utils.vendor.hcloud.storage_box_types import BoundStorageBoxType
class AnsibleStorageBoxTypeInfo(AnsibleHCloud):
represent = "storage_box_type"
storage_box_type: list[BoundStorageBoxType] | None = None
def _prepare_result(self):
result = []
for o in self.storage_box_type or []:
if o is None:
continue
result.append(
{
"id": o.id,
"name": o.name,
"description": o.description,
"snapshot_limit": o.snapshot_limit,
"automatic_snapshot_limit": o.automatic_snapshot_limit,
"subaccounts_limit": o.subaccounts_limit,
"size": o.size,
"deprecation": (
{
"announced": o.deprecation.announced.isoformat(),
"unavailable_after": o.deprecation.unavailable_after.isoformat(),
}
if o.deprecation is not None
else None
),
}
)
return result
def fetch(self):
try:
if (id_ := self.module.params.get("id")) is not None:
self.storage_box_type = [self.client.storage_box_types.get_by_id(id_)]
elif (name := self.module.params.get("name")) is not None:
self.storage_box_type = [self.client.storage_box_types.get_by_name(name)]
else:
self.storage_box_type = self.client.storage_box_types.get_all()
except HCloudException as exception:
self.fail_json_hcloud(exception)
@classmethod
def define_module(cls):
return AnsibleModule(
argument_spec=dict(
id={"type": "int"},
name={"type": "str"},
**super().base_module_arguments(),
),
supports_check_mode=True,
)
def main():
module = AnsibleStorageBoxTypeInfo.define_module()
o = AnsibleStorageBoxTypeInfo(module)
o.fetch()
result = o.get_result()
module.exit_json(
hcloud_storage_box_type_info=result["storage_box_type"],
)
if __name__ == "__main__":
main()

View file

@ -24,3 +24,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -0,0 +1,3 @@
cloud/hcloud
gather_facts/no
azp/group2

View file

@ -0,0 +1,32 @@
#
# DO NOT EDIT THIS FILE! Please edit the files in tests/integration/common instead.
#
---
# Azure Pipelines will configure this value to something similar to
# "azp-84824-1-hetzner-2-13-test-2-13-hcloud-3-9-1-default-i"
hcloud_prefix: "tests"
# Used to namespace resources created by concurrent test pipelines/targets
hcloud_run_ns: "{{ hcloud_prefix | md5 }}"
hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}"
hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}"
# Used to easily update the server types and images across all our tests.
hcloud_server_type_name: cax11
hcloud_server_type_id: 45
hcloud_server_type_upgrade_name: cax21
hcloud_server_type_upgrade_id: 93
hcloud_image_name: debian-12
hcloud_image_id: 114690389 # architecture=arm
hcloud_location_name: hel1
hcloud_location_id: 3
hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -0,0 +1,3 @@
# Copyright: (c) 2025, Hetzner Cloud GmbH <info@hetzner-cloud.de>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
---

View file

@ -0,0 +1,31 @@
#
# DO NOT EDIT THIS FILE! Please edit the files in tests/integration/common instead.
#
---
- name: Check if cleanup.yml exists
ansible.builtin.stat:
path: "{{ role_path }}/tasks/cleanup.yml"
register: cleanup_file
- name: Check if prepare.yml exists
ansible.builtin.stat:
path: "{{ role_path }}/tasks/prepare.yml"
register: prepare_file
- name: Include cleanup tasks
ansible.builtin.include_tasks: "{{ role_path }}/tasks/cleanup.yml"
when: cleanup_file.stat.exists
- name: Include prepare tasks
ansible.builtin.include_tasks: "{{ role_path }}/tasks/prepare.yml"
when: prepare_file.stat.exists
- name: Run tests
block:
- name: Include test tasks
ansible.builtin.include_tasks: "{{ role_path }}/tasks/test.yml"
always:
- name: Include cleanup tasks
ansible.builtin.include_tasks: "{{ role_path }}/tasks/cleanup.yml"
when: cleanup_file.stat.exists

View file

@ -0,0 +1,64 @@
# Copyright: (c) 2025, Hetzner Cloud GmbH <info@hetzner-cloud.de>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
---
- name: Gather hcloud_storage_box_type_info
hetzner.hcloud.storage_box_type_info:
register: result
- name: Verify hcloud_storage_box_type_info
ansible.builtin.assert:
that:
- result.hcloud_storage_box_type_info | list | count >= 1
- name: Gather hcloud_storage_box_type_info in check mode
hetzner.hcloud.storage_box_type_info:
check_mode: true
register: result
- name: Verify hcloud_storage_box_type_info in check mode
ansible.builtin.assert:
that:
- result.hcloud_storage_box_type_info | list | count >= 1
- name: Gather hcloud_storage_box_type_info with correct id
hetzner.hcloud.storage_box_type_info:
id: "{{ hcloud_storage_box_type_id }}"
register: result
- name: Verify hcloud_storage_box_type_info with correct id
ansible.builtin.assert:
that:
- result.hcloud_storage_box_type_info | list | count == 1
- result.hcloud_storage_box_type_info[0].id == hcloud_storage_box_type_id
- result.hcloud_storage_box_type_info[0].name == hcloud_storage_box_type_name
- result.hcloud_storage_box_type_info[0].description == "BX11"
- result.hcloud_storage_box_type_info[0].snapshot_limit == 10
- result.hcloud_storage_box_type_info[0].automatic_snapshot_limit == 10
- result.hcloud_storage_box_type_info[0].subaccounts_limit == 100
- result.hcloud_storage_box_type_info[0].size == 1099511627776
- result.hcloud_storage_box_type_info[0].deprecation is none
- name: Gather hcloud_storage_box_type_info with wrong id
hetzner.hcloud.storage_box_type_info:
id: "{{ hcloud_storage_box_type_id }}4321"
ignore_errors: true
register: result
- name: Verify hcloud_storage_box_type_info with wrong id
ansible.builtin.assert:
that:
- result is failed
- name: Gather hcloud_storage_box_type_info with correct name
hetzner.hcloud.storage_box_type_info:
name: "{{ hcloud_storage_box_type_name }}"
register: result
- name: Verify hcloud_storage_box_type_info with correct name
ansible.builtin.assert:
that:
- result.hcloud_storage_box_type_info | list | count == 1
- name: Gather hcloud_storage_box_type_info with wrong name
hetzner.hcloud.storage_box_type_info:
name: "{{ hcloud_storage_box_type_name }}-invalid"
register: result
- name: Verify hcloud_storage_box_type_info with wrong name
ansible.builtin.assert:
that:
- result.hcloud_storage_box_type_info | list | count == 0

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333

View file

@ -27,3 +27,6 @@ hcloud_datacenter_name: hel1-dc2
hcloud_datacenter_id: 3
hcloud_network_zone_name: eu-central
hcloud_storage_box_type_name: bx11
hcloud_storage_box_type_id: 1333