File tree Expand file tree Collapse file tree 3 files changed +74
-5
lines changed
Expand file tree Collapse file tree 3 files changed +74
-5
lines changed Original file line number Diff line number Diff line change @@ -536,3 +536,25 @@ def disable_snapshot_plan(
536536 url = f"{ self ._base_url } /{ storage_box .id } /actions/disable_snapshot_plan" ,
537537 )
538538 return BoundAction (self ._parent .actions , response ["action" ])
539+
540+ def enable_snapshot_plan (
541+ self ,
542+ storage_box : StorageBox | BoundStorageBox ,
543+ snapshot_plan : StorageBoxSnapshotPlan ,
544+ ) -> BoundAction :
545+ """
546+ Enable the snapshot plan a Storage Box.
547+
548+ See https://docs.hetzner.cloud/reference/cloud#TODO
549+
550+ :param storage_box: Storage Box to update.
551+ :param snapshot_plan: Snapshot Plan to enable.
552+ """
553+ data : dict [str , Any ] = snapshot_plan .to_payload ()
554+
555+ response = self ._client .request (
556+ method = "POST" ,
557+ url = f"{ self ._base_url } /{ storage_box .id } /actions/enable_snapshot_plan" ,
558+ json = data ,
559+ )
560+ return BoundAction (self ._parent .actions , response ["action" ])
Original file line number Diff line number Diff line change @@ -157,27 +157,41 @@ class StorageBoxSnapshotPlan(BaseDomain):
157157
158158 __api_properties__ = (
159159 "max_snapshots" ,
160- "minute" ,
161160 "hour" ,
161+ "minute" ,
162162 "day_of_week" ,
163163 "day_of_month" ,
164164 )
165165 __slots__ = __api_properties__
166166
167167 def __init__ (
168168 self ,
169- max_snapshots : int | None = None ,
170- minute : int | None = None ,
171- hour : int | None = None ,
169+ max_snapshots : int ,
170+ hour : int ,
171+ minute : int ,
172172 day_of_week : int | None = None ,
173173 day_of_month : int | None = None ,
174174 ):
175175 self .max_snapshots = max_snapshots
176- self .minute = minute
177176 self .hour = hour
177+ self .minute = minute
178178 self .day_of_week = day_of_week
179179 self .day_of_month = day_of_month
180180
181+ def to_payload (self ) -> dict [str , Any ]:
182+ """
183+ Generates the request payload from this domain object.
184+ """
185+ payload : dict [str , Any ] = {
186+ "max_snapshots" : self .max_snapshots ,
187+ "hour" : self .hour ,
188+ "minute" : self .minute ,
189+ "day_of_week" : self .day_of_week , # API default is null
190+ "day_of_month" : self .day_of_month , # API default is null
191+ }
192+
193+ return payload
194+
181195
182196class CreateStorageBoxResponse (BaseDomain ):
183197 """
Original file line number Diff line number Diff line change 1414 BoundStorageBox ,
1515 StorageBox ,
1616 StorageBoxesClient ,
17+ StorageBoxSnapshotPlan ,
1718)
1819from hcloud .storage_boxes .domain import StorageBoxAccessSettings , StorageBoxSnapshot
1920
@@ -438,3 +439,35 @@ def test_disable_snapshot_plan(
438439 )
439440
440441 assert_bound_action1 (action , resource_client ._parent .actions )
442+
443+ def test_enable_snapshot_plan (
444+ self ,
445+ request_mock : mock .MagicMock ,
446+ resource_client : StorageBoxesClient ,
447+ action_response ,
448+ ):
449+ request_mock .return_value = action_response
450+
451+ action = resource_client .enable_snapshot_plan (
452+ StorageBox (id = 42 ),
453+ StorageBoxSnapshotPlan (
454+ max_snapshots = 10 ,
455+ hour = 3 ,
456+ minute = 30 ,
457+ day_of_week = None ,
458+ ),
459+ )
460+
461+ request_mock .assert_called_with (
462+ method = "POST" ,
463+ url = "/storage_boxes/42/actions/enable_snapshot_plan" ,
464+ json = {
465+ "max_snapshots" : 10 ,
466+ "hour" : 3 ,
467+ "minute" : 30 ,
468+ "day_of_week" : None ,
469+ "day_of_month" : None ,
470+ },
471+ )
472+
473+ assert_bound_action1 (action , resource_client ._parent .actions )
You can’t perform that action at this time.
0 commit comments