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:
parent
09bff84a32
commit
2c6dbedec1
4 changed files with 27 additions and 69 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue