mirror of
https://github.com/ansible-collections/hetzner.hcloud.git
synced 2026-02-04 08:01:49 +00:00
##### SUMMARY We collect all changes for the Storage Box support in this PR. It will only be merged when everything is implemented through smaller pull requests targeting the `storage-boxes` branch. --------- Co-authored-by: Julian Tölle <julian.toelle@hetzner-cloud.de>
44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
from ..module_utils.vendor.hcloud.storage_boxes import (
|
|
BoundStorageBox,
|
|
BoundStorageBoxSubaccount,
|
|
)
|
|
|
|
NAME_LABEL_KEY = "ansible-name"
|
|
|
|
|
|
def get_by_name(storage_box: BoundStorageBox, name: str):
|
|
if not name:
|
|
raise ValueError(f"invalid storage box subaccount name: '{name}'")
|
|
|
|
result = storage_box.get_subaccount_list(
|
|
label_selector=f"{NAME_LABEL_KEY}={name}",
|
|
)
|
|
if len(result.subaccounts) == 0:
|
|
return None
|
|
if len(result.subaccounts) == 1:
|
|
return result.subaccounts[0]
|
|
|
|
raise ValueError(f"found multiple storage box subaccount with the same name: {name}")
|
|
|
|
|
|
def prepare_result(o: BoundStorageBoxSubaccount, name: str):
|
|
return {
|
|
"storage_box": o.storage_box.id,
|
|
"id": o.id,
|
|
"name": name,
|
|
"description": o.description,
|
|
"username": o.username,
|
|
"home_directory": o.home_directory,
|
|
"server": o.server,
|
|
"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,
|
|
"readonly": o.access_settings.readonly,
|
|
},
|
|
"labels": o.labels,
|
|
"created": o.created.isoformat(),
|
|
}
|