File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212 StorageBox ,
1313 StorageBoxAccessSettings ,
1414 StorageBoxFoldersResponse ,
15+ StorageBoxSnapshot ,
1516 StorageBoxSnapshotPlan ,
1617 StorageBoxStats ,
1718)
@@ -492,3 +493,29 @@ def update_access_settings(
492493 json = data ,
493494 )
494495 return BoundAction (self ._parent .actions , response ["action" ])
496+
497+ def rollback_snapshot (
498+ self ,
499+ storage_box : StorageBox | BoundStorageBox ,
500+ # TODO: Add BoundStorageBoxSnapshot
501+ # TODO: snapshot or storage_box_snapshot argument name?
502+ snapshot : StorageBoxSnapshot ,
503+ ) -> BoundAction :
504+ """
505+ Rollback the Storage Box to the given snapshot.
506+
507+ See https://docs.hetzner.cloud/reference/cloud#TODO
508+
509+ :param storage_box: Storage Box to update.
510+ :param snapshot: Snapshot to rollback to.
511+ """
512+ data : dict [str , Any ] = {
513+ "snapshot" : snapshot .id_or_name ,
514+ }
515+
516+ response = self ._client .request (
517+ method = "POST" ,
518+ url = f"{ self ._base_url } /{ storage_box .id } /actions/rollback_snapshot" ,
519+ json = data ,
520+ )
521+ return BoundAction (self ._parent .actions , response ["action" ])
Original file line number Diff line number Diff line change @@ -227,3 +227,28 @@ def __init__(
227227 folders : list [str ],
228228 ):
229229 self .folders = folders
230+
231+
232+ # Snapshots
233+ ###############################################################################
234+
235+
236+ class StorageBoxSnapshot (BaseDomain , DomainIdentityMixin ):
237+ """
238+ Storage Box Snapshot Domain.
239+ """
240+
241+ # TODO: full domain
242+ __api_properties__ = (
243+ "id" ,
244+ "name" ,
245+ )
246+ __slots__ = __api_properties__
247+
248+ def __init__ (
249+ self ,
250+ id : int | None = None ,
251+ name : str | None = None ,
252+ ):
253+ self .id = id
254+ self .name = name
Original file line number Diff line number Diff line change 1515 StorageBox ,
1616 StorageBoxesClient ,
1717)
18- from hcloud .storage_boxes .domain import StorageBoxAccessSettings
18+ from hcloud .storage_boxes .domain import StorageBoxAccessSettings , StorageBoxSnapshot
1919
2020from ..conftest import BoundModelTestCase , assert_bound_action1
2121
@@ -398,3 +398,24 @@ def test_update_access_settings(
398398 )
399399
400400 assert_bound_action1 (action , resource_client ._parent .actions )
401+
402+ def test_rollback_snapshot (
403+ self ,
404+ request_mock : mock .MagicMock ,
405+ resource_client : StorageBoxesClient ,
406+ action_response ,
407+ ):
408+ request_mock .return_value = action_response
409+
410+ action = resource_client .rollback_snapshot (
411+ StorageBox (id = 42 ),
412+ StorageBoxSnapshot (id = 32 ),
413+ )
414+
415+ request_mock .assert_called_with (
416+ method = "POST" ,
417+ url = "/storage_boxes/42/actions/rollback_snapshot" ,
418+ json = {"snapshot" : 32 },
419+ )
420+
421+ assert_bound_action1 (action , resource_client ._parent .actions )
You can’t perform that action at this time.
0 commit comments