22
33from typing import TYPE_CHECKING , Any , NamedTuple
44
5- from ..actions import BoundAction
5+ from ..actions import ActionsPageResult , BoundAction , ResourceActionsClient
66from ..core import BoundModelBase , Meta , ResourceClientBase
77from ..locations import BoundLocation , Location
88from ..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+ )
0 commit comments