@@ -773,6 +773,125 @@ def action(
773
773
cast_to = TaskIDList ,
774
774
)
775
775
776
+ @overload
777
+ def action_and_poll (
778
+ self ,
779
+ instance_id : str ,
780
+ * ,
781
+ project_id : int | None = None ,
782
+ region_id : int | None = None ,
783
+ action : Literal ["start" ],
784
+ activate_profile : Optional [bool ] | NotGiven = NOT_GIVEN ,
785
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
786
+ # The extra values given here take precedence over values defined on the client or passed to this method.
787
+ extra_headers : Headers | None = None ,
788
+ extra_query : Query | None = None ,
789
+ extra_body : Body | None = None ,
790
+ timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
791
+ ) -> Instance :
792
+ """
793
+ The action can be one of: start, stop, reboot, powercycle, suspend or resume.
794
+ Suspend and resume are not available for bare metal instances.
795
+
796
+ Args:
797
+ action: Instance action name
798
+
799
+ activate_profile: Used on start instance to activate Advanced DDoS profile
800
+
801
+ extra_headers: Send extra headers
802
+
803
+ extra_query: Add additional query parameters to the request
804
+
805
+ extra_body: Add additional JSON properties to the request
806
+
807
+ timeout: Override the client-level default timeout for this request, in seconds
808
+ """
809
+ ...
810
+
811
+ @overload
812
+ def action_and_poll (
813
+ self ,
814
+ instance_id : str ,
815
+ * ,
816
+ project_id : int | None = None ,
817
+ region_id : int | None = None ,
818
+ action : Literal ["reboot" , "reboot_hard" , "resume" , "stop" , "suspend" ],
819
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
820
+ # The extra values given here take precedence over values defined on the client or passed to this method.
821
+ extra_headers : Headers | None = None ,
822
+ extra_query : Query | None = None ,
823
+ extra_body : Body | None = None ,
824
+ timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
825
+ ) -> Instance :
826
+ """
827
+ The action can be one of: start, stop, reboot, powercycle, suspend or resume.
828
+ Suspend and resume are not available for bare metal instances.
829
+
830
+ Args:
831
+ action: Instance action name
832
+
833
+ extra_headers: Send extra headers
834
+
835
+ extra_query: Add additional query parameters to the request
836
+
837
+ extra_body: Add additional JSON properties to the request
838
+
839
+ timeout: Override the client-level default timeout for this request, in seconds
840
+ """
841
+ ...
842
+
843
+ @required_args (["action" ])
844
+ def action_and_poll (
845
+ self ,
846
+ instance_id : str ,
847
+ * ,
848
+ project_id : int | None = None ,
849
+ region_id : int | None = None ,
850
+ action : Literal ["start" , "reboot" , "reboot_hard" , "resume" , "stop" , "suspend" ],
851
+ activate_profile : Optional [bool ] | NotGiven = NOT_GIVEN ,
852
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
853
+ # The extra values given here take precedence over values defined on the client or passed to this method.
854
+ extra_headers : Headers | None = None ,
855
+ extra_query : Query | None = None ,
856
+ extra_body : Body | None = None ,
857
+ timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
858
+ ) -> Instance :
859
+ """
860
+ Perform the action on the instance and poll for the result. Only the first task will be polled. If you need to poll more tasks, use the `tasks.poll` method.
861
+ """
862
+ if project_id is None :
863
+ project_id = self ._client ._get_cloud_project_id_path_param ()
864
+ if region_id is None :
865
+ region_id = self ._client ._get_cloud_region_id_path_param ()
866
+ if not instance_id :
867
+ raise ValueError (f"Expected a non-empty value for `instance_id` but received { instance_id !r} " )
868
+ response = self ._post (
869
+ f"/cloud/v2/instances/{ project_id } /{ region_id } /{ instance_id } /action" ,
870
+ body = maybe_transform (
871
+ {
872
+ "action" : action ,
873
+ "activate_profile" : activate_profile ,
874
+ },
875
+ instance_action_params .InstanceActionParams ,
876
+ ),
877
+ options = make_request_options (
878
+ extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
879
+ ),
880
+ cast_to = TaskIDList ,
881
+ )
882
+ if not response .tasks :
883
+ raise ValueError ("Expected at least one task to be created" )
884
+ self ._client .cloud .tasks .poll (
885
+ task_id = response .tasks [0 ],
886
+ extra_headers = extra_headers ,
887
+ )
888
+ return self .get (
889
+ instance_id = instance_id ,
890
+ project_id = project_id ,
891
+ region_id = region_id ,
892
+ extra_headers = extra_headers ,
893
+ )
894
+
776
895
def add_to_placement_group (
777
896
self ,
778
897
instance_id : str ,
@@ -2023,6 +2142,125 @@ async def action(
2023
2142
cast_to = TaskIDList ,
2024
2143
)
2025
2144
2145
+ @overload
2146
+ async def action_and_poll (
2147
+ self ,
2148
+ instance_id : str ,
2149
+ * ,
2150
+ project_id : int | None = None ,
2151
+ region_id : int | None = None ,
2152
+ action : Literal ["start" ],
2153
+ activate_profile : Optional [bool ] | NotGiven = NOT_GIVEN ,
2154
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
2155
+ # The extra values given here take precedence over values defined on the client or passed to this method.
2156
+ extra_headers : Headers | None = None ,
2157
+ extra_query : Query | None = None ,
2158
+ extra_body : Body | None = None ,
2159
+ timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
2160
+ ) -> Instance :
2161
+ """
2162
+ The action can be one of: start, stop, reboot, powercycle, suspend or resume.
2163
+ Suspend and resume are not available for bare metal instances.
2164
+
2165
+ Args:
2166
+ action: Instance action name
2167
+
2168
+ activate_profile: Used on start instance to activate Advanced DDoS profile
2169
+
2170
+ extra_headers: Send extra headers
2171
+
2172
+ extra_query: Add additional query parameters to the request
2173
+
2174
+ extra_body: Add additional JSON properties to the request
2175
+
2176
+ timeout: Override the client-level default timeout for this request, in seconds
2177
+ """
2178
+ ...
2179
+
2180
+ @overload
2181
+ async def action_and_poll (
2182
+ self ,
2183
+ instance_id : str ,
2184
+ * ,
2185
+ project_id : int | None = None ,
2186
+ region_id : int | None = None ,
2187
+ action : Literal ["reboot" , "reboot_hard" , "resume" , "stop" , "suspend" ],
2188
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
2189
+ # The extra values given here take precedence over values defined on the client or passed to this method.
2190
+ extra_headers : Headers | None = None ,
2191
+ extra_query : Query | None = None ,
2192
+ extra_body : Body | None = None ,
2193
+ timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
2194
+ ) -> Instance :
2195
+ """
2196
+ The action can be one of: start, stop, reboot, powercycle, suspend or resume.
2197
+ Suspend and resume are not available for bare metal instances.
2198
+
2199
+ Args:
2200
+ action: Instance action name
2201
+
2202
+ extra_headers: Send extra headers
2203
+
2204
+ extra_query: Add additional query parameters to the request
2205
+
2206
+ extra_body: Add additional JSON properties to the request
2207
+
2208
+ timeout: Override the client-level default timeout for this request, in seconds
2209
+ """
2210
+ ...
2211
+
2212
+ @required_args (["action" ])
2213
+ async def action_and_poll (
2214
+ self ,
2215
+ instance_id : str ,
2216
+ * ,
2217
+ project_id : int | None = None ,
2218
+ region_id : int | None = None ,
2219
+ action : Literal ["start" , "reboot" , "reboot_hard" , "resume" , "stop" , "suspend" ],
2220
+ activate_profile : Optional [bool ] | NotGiven = NOT_GIVEN ,
2221
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
2222
+ # The extra values given here take precedence over values defined on the client or passed to this method.
2223
+ extra_headers : Headers | None = None ,
2224
+ extra_query : Query | None = None ,
2225
+ extra_body : Body | None = None ,
2226
+ timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
2227
+ ) -> Instance :
2228
+ """
2229
+ Perform the action on the instance and poll for the result. Only the first task will be polled. If you need to poll more tasks, use the `tasks.poll` method.
2230
+ """
2231
+ if project_id is None :
2232
+ project_id = self ._client ._get_cloud_project_id_path_param ()
2233
+ if region_id is None :
2234
+ region_id = self ._client ._get_cloud_region_id_path_param ()
2235
+ if not instance_id :
2236
+ raise ValueError (f"Expected a non-empty value for `instance_id` but received { instance_id !r} " )
2237
+ response = await self ._post (
2238
+ f"/cloud/v2/instances/{ project_id } /{ region_id } /{ instance_id } /action" ,
2239
+ body = await async_maybe_transform (
2240
+ {
2241
+ "action" : action ,
2242
+ "activate_profile" : activate_profile ,
2243
+ },
2244
+ instance_action_params .InstanceActionParams ,
2245
+ ),
2246
+ options = make_request_options (
2247
+ extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
2248
+ ),
2249
+ cast_to = TaskIDList ,
2250
+ )
2251
+ if not response .tasks :
2252
+ raise ValueError ("Expected at least one task to be created" )
2253
+ await self ._client .cloud .tasks .poll (
2254
+ task_id = response .tasks [0 ],
2255
+ extra_headers = extra_headers ,
2256
+ )
2257
+ return await self .get (
2258
+ instance_id = instance_id ,
2259
+ project_id = project_id ,
2260
+ region_id = region_id ,
2261
+ extra_headers = extra_headers ,
2262
+ )
2263
+
2026
2264
async def add_to_placement_group (
2027
2265
self ,
2028
2266
instance_id : str ,
@@ -2591,6 +2829,9 @@ def __init__(self, instances: InstancesResource) -> None:
2591
2829
self .action = to_raw_response_wrapper (
2592
2830
instances .action ,
2593
2831
)
2832
+ self .action_and_poll = to_raw_response_wrapper (
2833
+ instances .action_and_poll ,
2834
+ )
2594
2835
self .add_to_placement_group = to_raw_response_wrapper (
2595
2836
instances .add_to_placement_group ,
2596
2837
)
@@ -2655,6 +2896,9 @@ def __init__(self, instances: AsyncInstancesResource) -> None:
2655
2896
self .action = async_to_raw_response_wrapper (
2656
2897
instances .action ,
2657
2898
)
2899
+ self .action_and_poll = async_to_raw_response_wrapper (
2900
+ instances .action_and_poll ,
2901
+ )
2658
2902
self .add_to_placement_group = async_to_raw_response_wrapper (
2659
2903
instances .add_to_placement_group ,
2660
2904
)
@@ -2719,6 +2963,9 @@ def __init__(self, instances: InstancesResource) -> None:
2719
2963
self .action = to_streamed_response_wrapper (
2720
2964
instances .action ,
2721
2965
)
2966
+ self .action_and_poll = to_streamed_response_wrapper (
2967
+ instances .action_and_poll ,
2968
+ )
2722
2969
self .add_to_placement_group = to_streamed_response_wrapper (
2723
2970
instances .add_to_placement_group ,
2724
2971
)
@@ -2783,6 +3030,9 @@ def __init__(self, instances: AsyncInstancesResource) -> None:
2783
3030
self .action = async_to_streamed_response_wrapper (
2784
3031
instances .action ,
2785
3032
)
3033
+ self .action_and_poll = async_to_streamed_response_wrapper (
3034
+ instances .action_and_poll ,
3035
+ )
2786
3036
self .add_to_placement_group = async_to_streamed_response_wrapper (
2787
3037
instances .add_to_placement_group ,
2788
3038
)
0 commit comments