From 4c75cfc7e581662f11083be36249aeeba0ae0fc6 Mon Sep 17 00:00:00 2001 From: jo Date: Wed, 3 Dec 2025 12:18:20 +0100 Subject: [PATCH] add stats --- plugins/module_utils/storage_box.py | 5 +++++ plugins/modules/storage_box.py | 22 +++++++++++++++++-- plugins/modules/storage_box_info.py | 21 +++++++++++++++++- .../targets/storage_box/tasks/test.yml | 3 +++ .../targets/storage_box_info/tasks/test.yml | 3 +++ 5 files changed, 51 insertions(+), 3 deletions(-) diff --git a/plugins/module_utils/storage_box.py b/plugins/module_utils/storage_box.py index 43ffbc9..2f7268e 100644 --- a/plugins/module_utils/storage_box.py +++ b/plugins/module_utils/storage_box.py @@ -24,4 +24,9 @@ def prepare_result(o: BoundStorageBox): "server": o.server, "system": o.system, "status": o.status, + "stats": { + "size": o.stats.size, + "size_data": o.stats.size_data, + "size_snapshots": o.stats.size_snapshots, + }, } diff --git a/plugins/modules/storage_box.py b/plugins/modules/storage_box.py index c1257c5..ed477d4 100644 --- a/plugins/modules/storage_box.py +++ b/plugins/modules/storage_box.py @@ -219,9 +219,27 @@ hcloud_storage_box: returned: always type: str sample: active - + stats: + description: Statistics of the Storage Box. + returned: always + type: dict + contains: + size: + description: Current disk usage in bytes. + returned: always + type: int + sample: 10485760 + size_data: + description: Current disk usage for data in bytes. + returned: always + type: int + sample: 10485760 + size_snapshots: + description: Current disk usage for snapshots in bytes. + returned: always + type: int + sample: 10485760 """ -# TODO: stats from ansible.module_utils.basic import AnsibleModule diff --git a/plugins/modules/storage_box_info.py b/plugins/modules/storage_box_info.py index 8f2f694..856bba7 100644 --- a/plugins/modules/storage_box_info.py +++ b/plugins/modules/storage_box_info.py @@ -159,8 +159,27 @@ hcloud_storage_box_info: returned: always type: str sample: active + stats: + description: Statistics of the Storage Box. + returned: always + type: dict + contains: + size: + description: Current disk usage in bytes. + returned: always + type: int + sample: 10485760 + size_data: + description: Current disk usage for data in bytes. + returned: always + type: int + sample: 10485760 + size_snapshots: + description: Current disk usage for snapshots in bytes. + returned: always + type: int + sample: 10485760 """ -# TODO: stats from ansible.module_utils.basic import AnsibleModule diff --git a/tests/integration/targets/storage_box/tasks/test.yml b/tests/integration/targets/storage_box/tasks/test.yml index 8105548..7099c12 100644 --- a/tests/integration/targets/storage_box/tasks/test.yml +++ b/tests/integration/targets/storage_box/tasks/test.yml @@ -61,6 +61,9 @@ - result.hcloud_storage_box.server is not none - result.hcloud_storage_box.system is not none - result.hcloud_storage_box.username is not none + - result.hcloud_storage_box.stats.size >= 0 + - result.hcloud_storage_box.stats.size_data >= 0 + - result.hcloud_storage_box.stats.size_snapshots >= 0 - name: Test create idempotency hetzner.hcloud.storage_box: diff --git a/tests/integration/targets/storage_box_info/tasks/test.yml b/tests/integration/targets/storage_box_info/tasks/test.yml index 3446705..e5971ef 100644 --- a/tests/integration/targets/storage_box_info/tasks/test.yml +++ b/tests/integration/targets/storage_box_info/tasks/test.yml @@ -50,6 +50,9 @@ - result.hcloud_storage_box_info[0].server is not none - result.hcloud_storage_box_info[0].system is not none - result.hcloud_storage_box_info[0].username is not none + - result.hcloud_storage_box_info[0].stats.size >= 0 + - result.hcloud_storage_box_info[0].stats.size_data >= 0 + - result.hcloud_storage_box_info[0].stats.size_snapshots >= 0 - name: Gather hcloud_storage_box_info with wrong id hetzner.hcloud.storage_box_info: