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 name to Storage Box Subaccount (#787)

##### SUMMARY

Replaces the label based name workaround for Storage Box Subaccounts,
with the new Storage Box Subaccount name property managed in the API.

##### ISSUE TYPE

- Feature Pull Request


##### COMPONENT NAME

- `storage_box_subaccount`
- `storage_box_subaccount_info`
This commit is contained in:
Jonas L. 2026-01-16 14:05:34 +01:00 committed by GitHub
parent 09bff84a32
commit 2c6dbedec1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 27 additions and 69 deletions

View file

@ -11,26 +11,23 @@ from ._vendor.hcloud.storage_boxes import (
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}'")
def get_by_label_name(storage_box: BoundStorageBox, name: str):
"""
Kept for backward compatible upgrade from label based 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}")
return None
def prepare_result(o: BoundStorageBoxSubaccount, name: str):
def prepare_result(o: BoundStorageBoxSubaccount):
return {
"storage_box": o.storage_box.id,
"id": o.id,
"name": name,
"name": o.name,
"description": o.description,
"username": o.username,
"home_directory": o.home_directory,