Skip to content

Commit 77b8761

Browse files
committed
implement actions read endpoints
1 parent 0a5a06a commit 77b8761

File tree

2 files changed

+119
-1
lines changed

2 files changed

+119
-1
lines changed

hcloud/storage_boxes/client.py

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from typing import TYPE_CHECKING, Any, NamedTuple
44

5-
from ..actions import BoundAction
5+
from ..actions import ActionsPageResult, BoundAction, ResourceActionsClient
66
from ..core import BoundModelBase, Meta, ResourceClientBase
77
from ..locations import BoundLocation, Location
88
from ..storage_box_types import BoundStorageBoxType, StorageBoxType
@@ -55,6 +55,52 @@ def __init__(
5555

5656
super().__init__(client, data, complete)
5757

58+
def get_actions_list(
59+
self,
60+
*,
61+
status: list[str] | None = None,
62+
sort: list[str] | None = None,
63+
page: int | None = None,
64+
per_page: int | None = None,
65+
) -> ActionsPageResult:
66+
"""
67+
Returns all Actions for the Storage Box for a specific page.
68+
69+
See https://docs.hetzner.cloud/reference/hetzner#TODO
70+
71+
:param status: Filter the actions by status. The response will only contain actions matching the specified statuses.
72+
:param sort: Sort resources by field and direction.
73+
:param page: Page number to return.
74+
:param per_page: Maximum number of entries returned per page.
75+
"""
76+
return self._client.get_actions_list(
77+
self,
78+
status=status,
79+
sort=sort,
80+
page=page,
81+
per_page=per_page,
82+
)
83+
84+
def get_actions(
85+
self,
86+
*,
87+
status: list[str] | None = None,
88+
sort: list[str] | None = None,
89+
) -> list[BoundAction]:
90+
"""
91+
Returns all Actions for the Storage Box.
92+
93+
See https://docs.hetzner.cloud/reference/hetzner#TODO
94+
95+
:param status: Filter the actions by status. The response will only contain actions matching the specified statuses.
96+
:param sort: Sort resources by field and direction.
97+
"""
98+
return self._client.get_actions(
99+
self,
100+
status=status,
101+
sort=sort,
102+
)
103+
58104
# TODO: implement bound methods
59105

60106

@@ -72,9 +118,16 @@ class StorageBoxesClient(ResourceClientBase):
72118

73119
_base_url = "/storage_boxes"
74120

121+
actions: ResourceActionsClient
122+
"""Storage Boxes scoped actions client
123+
124+
:type: :class:`ResourceActionsClient <hcloud.actions.client.ResourceActionsClient>`
125+
"""
126+
75127
def __init__(self, client: Client):
76128
super().__init__(client)
77129
self._client = client._client_hetzner
130+
self.actions = ResourceActionsClient(self, self._base_url)
78131

79132
def get_by_id(self, id: int) -> BoundStorageBox:
80133
"""
@@ -280,3 +333,66 @@ def get_folders(
280333
)
281334

282335
return StorageBoxFoldersResponse(folders=response["folders"])
336+
337+
def get_actions_list(
338+
self,
339+
storage_box: StorageBox | BoundStorageBox,
340+
*,
341+
status: list[str] | None = None,
342+
sort: list[str] | None = None,
343+
page: int | None = None,
344+
per_page: int | None = None,
345+
) -> ActionsPageResult:
346+
"""
347+
Returns all Actions for a Storage Box for a specific page.
348+
349+
See https://docs.hetzner.cloud/reference/hetzner#storage-box-actions-list-actions-for-a-storage-box
350+
351+
:param storage_box: Storage Box to fetch the Actions from.
352+
:param status: Filter the actions by status. The response will only contain actions matching the specified statuses.
353+
:param sort: Sort resources by field and direction.
354+
:param page: Page number to return.
355+
:param per_page: Maximum number of entries returned per page.
356+
"""
357+
params: dict[str, Any] = {}
358+
if status is not None:
359+
params["status"] = status
360+
if sort is not None:
361+
params["sort"] = sort
362+
if page is not None:
363+
params["page"] = page
364+
if per_page is not None:
365+
params["per_page"] = per_page
366+
367+
response = self._client.request(
368+
method="GET",
369+
url=f"/storage_boxes/{storage_box.id}/actions",
370+
params=params,
371+
)
372+
return ActionsPageResult(
373+
actions=[BoundAction(self._parent.actions, o) for o in response["actions"]],
374+
meta=Meta.parse_meta(response),
375+
)
376+
377+
def get_actions(
378+
self,
379+
storage_box: StorageBox | BoundStorageBox,
380+
*,
381+
status: list[str] | None = None,
382+
sort: list[str] | None = None,
383+
) -> list[BoundAction]:
384+
"""
385+
Returns all Actions for a Storage Box.
386+
387+
See https://docs.hetzner.cloud/reference/hetzner#storage-box-actions-list-actions-for-a-storage-box
388+
389+
:param storage_box: Storage Box to fetch the Actions from.
390+
:param status: Filter the actions by status. The response will only contain actions matching the specified statuses.
391+
:param sort: Sort resources by field and direction.
392+
"""
393+
return self._iter_pages(
394+
self.get_actions_list,
395+
storage_box,
396+
status=status,
397+
sort=sort,
398+
)

tests/unit/actions/test_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from hcloud.networks import BoundNetwork, NetworksClient
2323
from hcloud.primary_ips import BoundPrimaryIP, PrimaryIPsClient
2424
from hcloud.servers import BoundServer, ServersClient
25+
from hcloud.storage_boxes import BoundStorageBox, StorageBoxesClient
2526
from hcloud.volumes import BoundVolume, VolumesClient
2627
from hcloud.zones import BoundZone, ZonesClient
2728

@@ -38,6 +39,7 @@
3839
"servers": (ServersClient, BoundServer),
3940
"volumes": (VolumesClient, BoundVolume),
4041
"zones": (ZonesClient, BoundZone),
42+
"storage_boxes": (StorageBoxesClient, BoundStorageBox),
4143
}
4244

4345

0 commit comments

Comments
 (0)