mirror of
https://github.com/ansible-collections/hetzner.hcloud.git
synced 2026-02-04 08:01:49 +00:00
refactor: mark module_utils modules as private (#782)
##### SUMMARY All `module_utils` are now marked as **private**. None of the modules were intended for public use. Similar to https://togithub.com/ansible-collections/community.general/issues/11312
This commit is contained in:
parent
0f23e6c58c
commit
cfa0d181f7
152 changed files with 283 additions and 239 deletions
69
plugins/module_utils/_storage_box.py
Normal file
69
plugins/module_utils/_storage_box.py
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
# Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||
# Do not use this from other collections or standalone plugins/modules!
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from ._client import client_resource_not_found
|
||||
from ._vendor.hcloud.storage_boxes import (
|
||||
BoundStorageBox,
|
||||
StorageBoxesClient,
|
||||
)
|
||||
|
||||
|
||||
def get(client: StorageBoxesClient, param: str | int) -> BoundStorageBox:
|
||||
"""
|
||||
Get a Bound Storage Box either by ID or name.
|
||||
|
||||
If the given parameter is an ID, return a partial Bound Storage Box to reduce the amount
|
||||
of API requests.
|
||||
"""
|
||||
try:
|
||||
return BoundStorageBox(
|
||||
client,
|
||||
data={"id": int(param)},
|
||||
complete=False,
|
||||
)
|
||||
except ValueError: # param is not an id
|
||||
result = client.get_by_name(param)
|
||||
if result is None:
|
||||
# pylint: disable=raise-missing-from
|
||||
raise client_resource_not_found("storage box", param)
|
||||
return result
|
||||
|
||||
|
||||
def prepare_result(o: BoundStorageBox):
|
||||
return {
|
||||
"id": o.id,
|
||||
"name": o.name,
|
||||
"storage_box_type": o.storage_box_type.name,
|
||||
"location": o.location.name,
|
||||
"labels": o.labels,
|
||||
"delete_protection": o.protection["delete"],
|
||||
"access_settings": {
|
||||
"reachable_externally": o.access_settings.reachable_externally,
|
||||
"samba_enabled": o.access_settings.samba_enabled,
|
||||
"ssh_enabled": o.access_settings.ssh_enabled,
|
||||
"webdav_enabled": o.access_settings.webdav_enabled,
|
||||
"zfs_enabled": o.access_settings.zfs_enabled,
|
||||
},
|
||||
"username": o.username,
|
||||
"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,
|
||||
},
|
||||
"snapshot_plan": (
|
||||
None
|
||||
if o.snapshot_plan is None
|
||||
else {
|
||||
"max_snapshots": o.snapshot_plan.max_snapshots,
|
||||
"hour": o.snapshot_plan.hour,
|
||||
"minute": o.snapshot_plan.minute,
|
||||
"day_of_week": o.snapshot_plan.day_of_week,
|
||||
"day_of_month": o.snapshot_plan.day_of_month,
|
||||
}
|
||||
),
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue