7
7
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
8
# --------------------------------------------------------------------------
9
9
from io import IOBase
10
- from typing import Any , Callable , Dict , IO , Optional , TypeVar , Union , overload
10
+ from typing import Any , Callable , Dict , IO , Optional , TypeVar , Union , cast , overload
11
11
12
12
from azure .core .exceptions import (
13
13
ClientAuthenticationError ,
19
19
)
20
20
from azure .core .pipeline import PipelineResponse
21
21
from azure .core .pipeline .transport import AsyncHttpResponse
22
+ from azure .core .polling import AsyncLROPoller , AsyncNoPolling , AsyncPollingMethod
22
23
from azure .core .rest import HttpRequest
23
24
from azure .core .tracing .decorator_async import distributed_trace_async
24
25
from azure .core .utils import case_insensitive_dict
25
26
from azure .mgmt .core .exceptions import ARMErrorFormat
27
+ from azure .mgmt .core .polling .async_arm_polling import AsyncARMPolling
26
28
27
29
from ... import models as _models
28
30
from ..._vendor import _convert_request
@@ -128,8 +130,81 @@ async def get(
128
130
"url" : "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}"
129
131
}
130
132
133
+ async def _register_initial (
134
+ self ,
135
+ vault_name : str ,
136
+ resource_group_name : str ,
137
+ fabric_name : str ,
138
+ container_name : str ,
139
+ parameters : Union [_models .ProtectionContainerResource , IO ],
140
+ ** kwargs : Any
141
+ ) -> Optional [_models .ProtectionContainerResource ]:
142
+ error_map = {
143
+ 401 : ClientAuthenticationError ,
144
+ 404 : ResourceNotFoundError ,
145
+ 409 : ResourceExistsError ,
146
+ 304 : ResourceNotModifiedError ,
147
+ }
148
+ error_map .update (kwargs .pop ("error_map" , {}) or {})
149
+
150
+ _headers = case_insensitive_dict (kwargs .pop ("headers" , {}) or {})
151
+ _params = case_insensitive_dict (kwargs .pop ("params" , {}) or {})
152
+
153
+ api_version : str = kwargs .pop ("api_version" , _params .pop ("api-version" , self ._config .api_version ))
154
+ content_type : Optional [str ] = kwargs .pop ("content_type" , _headers .pop ("Content-Type" , None ))
155
+ cls : ClsType [Optional [_models .ProtectionContainerResource ]] = kwargs .pop ("cls" , None )
156
+
157
+ content_type = content_type or "application/json"
158
+ _json = None
159
+ _content = None
160
+ if isinstance (parameters , (IOBase , bytes )):
161
+ _content = parameters
162
+ else :
163
+ _json = self ._serialize .body (parameters , "ProtectionContainerResource" )
164
+
165
+ request = build_register_request (
166
+ vault_name = vault_name ,
167
+ resource_group_name = resource_group_name ,
168
+ fabric_name = fabric_name ,
169
+ container_name = container_name ,
170
+ subscription_id = self ._config .subscription_id ,
171
+ api_version = api_version ,
172
+ content_type = content_type ,
173
+ json = _json ,
174
+ content = _content ,
175
+ template_url = self ._register_initial .metadata ["url" ],
176
+ headers = _headers ,
177
+ params = _params ,
178
+ )
179
+ request = _convert_request (request )
180
+ request .url = self ._client .format_url (request .url )
181
+
182
+ _stream = False
183
+ pipeline_response : PipelineResponse = await self ._client ._pipeline .run ( # pylint: disable=protected-access
184
+ request , stream = _stream , ** kwargs
185
+ )
186
+
187
+ response = pipeline_response .http_response
188
+
189
+ if response .status_code not in [200 , 202 ]:
190
+ map_error (status_code = response .status_code , response = response , error_map = error_map )
191
+ raise HttpResponseError (response = response , error_format = ARMErrorFormat )
192
+
193
+ deserialized = None
194
+ if response .status_code == 200 :
195
+ deserialized = self ._deserialize ("ProtectionContainerResource" , pipeline_response )
196
+
197
+ if cls :
198
+ return cls (pipeline_response , deserialized , {})
199
+
200
+ return deserialized
201
+
202
+ _register_initial .metadata = {
203
+ "url" : "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}"
204
+ }
205
+
131
206
@overload
132
- async def register (
207
+ async def begin_register (
133
208
self ,
134
209
vault_name : str ,
135
210
resource_group_name : str ,
@@ -139,7 +214,7 @@ async def register(
139
214
* ,
140
215
content_type : str = "application/json" ,
141
216
** kwargs : Any
142
- ) -> Optional [_models .ProtectionContainerResource ]:
217
+ ) -> AsyncLROPoller [_models .ProtectionContainerResource ]:
143
218
"""Registers the container with Recovery Services vault.
144
219
This is an asynchronous operation. To track the operation status, use location header to call
145
220
get latest status of
@@ -161,14 +236,22 @@ async def register(
161
236
Default value is "application/json".
162
237
:paramtype content_type: str
163
238
:keyword callable cls: A custom type or function that will be passed the direct response
164
- :return: ProtectionContainerResource or None or the result of cls(response)
165
- :rtype: ~azure.mgmt.recoveryservicesbackup.activestamp.models.ProtectionContainerResource or
166
- None
239
+ :keyword str continuation_token: A continuation token to restart a poller from a saved state.
240
+ :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for
241
+ this operation to not poll, or pass in your own initialized polling object for a personal
242
+ polling strategy.
243
+ :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod
244
+ :keyword int polling_interval: Default waiting time between two polls for LRO operations if no
245
+ Retry-After header is present.
246
+ :return: An instance of AsyncLROPoller that returns either ProtectionContainerResource or the
247
+ result of cls(response)
248
+ :rtype:
249
+ ~azure.core.polling.AsyncLROPoller[~azure.mgmt.recoveryservicesbackup.activestamp.models.ProtectionContainerResource]
167
250
:raises ~azure.core.exceptions.HttpResponseError:
168
251
"""
169
252
170
253
@overload
171
- async def register (
254
+ async def begin_register (
172
255
self ,
173
256
vault_name : str ,
174
257
resource_group_name : str ,
@@ -178,7 +261,7 @@ async def register(
178
261
* ,
179
262
content_type : str = "application/json" ,
180
263
** kwargs : Any
181
- ) -> Optional [_models .ProtectionContainerResource ]:
264
+ ) -> AsyncLROPoller [_models .ProtectionContainerResource ]:
182
265
"""Registers the container with Recovery Services vault.
183
266
This is an asynchronous operation. To track the operation status, use location header to call
184
267
get latest status of
@@ -199,22 +282,30 @@ async def register(
199
282
Default value is "application/json".
200
283
:paramtype content_type: str
201
284
:keyword callable cls: A custom type or function that will be passed the direct response
202
- :return: ProtectionContainerResource or None or the result of cls(response)
203
- :rtype: ~azure.mgmt.recoveryservicesbackup.activestamp.models.ProtectionContainerResource or
204
- None
285
+ :keyword str continuation_token: A continuation token to restart a poller from a saved state.
286
+ :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for
287
+ this operation to not poll, or pass in your own initialized polling object for a personal
288
+ polling strategy.
289
+ :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod
290
+ :keyword int polling_interval: Default waiting time between two polls for LRO operations if no
291
+ Retry-After header is present.
292
+ :return: An instance of AsyncLROPoller that returns either ProtectionContainerResource or the
293
+ result of cls(response)
294
+ :rtype:
295
+ ~azure.core.polling.AsyncLROPoller[~azure.mgmt.recoveryservicesbackup.activestamp.models.ProtectionContainerResource]
205
296
:raises ~azure.core.exceptions.HttpResponseError:
206
297
"""
207
298
208
299
@distributed_trace_async
209
- async def register (
300
+ async def begin_register (
210
301
self ,
211
302
vault_name : str ,
212
303
resource_group_name : str ,
213
304
fabric_name : str ,
214
305
container_name : str ,
215
306
parameters : Union [_models .ProtectionContainerResource , IO ],
216
307
** kwargs : Any
217
- ) -> Optional [_models .ProtectionContainerResource ]:
308
+ ) -> AsyncLROPoller [_models .ProtectionContainerResource ]:
218
309
"""Registers the container with Recovery Services vault.
219
310
This is an asynchronous operation. To track the operation status, use location header to call
220
311
get latest status of
@@ -237,72 +328,66 @@ async def register(
237
328
Default value is None.
238
329
:paramtype content_type: str
239
330
:keyword callable cls: A custom type or function that will be passed the direct response
240
- :return: ProtectionContainerResource or None or the result of cls(response)
241
- :rtype: ~azure.mgmt.recoveryservicesbackup.activestamp.models.ProtectionContainerResource or
242
- None
331
+ :keyword str continuation_token: A continuation token to restart a poller from a saved state.
332
+ :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for
333
+ this operation to not poll, or pass in your own initialized polling object for a personal
334
+ polling strategy.
335
+ :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod
336
+ :keyword int polling_interval: Default waiting time between two polls for LRO operations if no
337
+ Retry-After header is present.
338
+ :return: An instance of AsyncLROPoller that returns either ProtectionContainerResource or the
339
+ result of cls(response)
340
+ :rtype:
341
+ ~azure.core.polling.AsyncLROPoller[~azure.mgmt.recoveryservicesbackup.activestamp.models.ProtectionContainerResource]
243
342
:raises ~azure.core.exceptions.HttpResponseError:
244
343
"""
245
- error_map = {
246
- 401 : ClientAuthenticationError ,
247
- 404 : ResourceNotFoundError ,
248
- 409 : ResourceExistsError ,
249
- 304 : ResourceNotModifiedError ,
250
- }
251
- error_map .update (kwargs .pop ("error_map" , {}) or {})
252
-
253
344
_headers = case_insensitive_dict (kwargs .pop ("headers" , {}) or {})
254
345
_params = case_insensitive_dict (kwargs .pop ("params" , {}) or {})
255
346
256
347
api_version : str = kwargs .pop ("api_version" , _params .pop ("api-version" , self ._config .api_version ))
257
348
content_type : Optional [str ] = kwargs .pop ("content_type" , _headers .pop ("Content-Type" , None ))
258
- cls : ClsType [Optional [_models .ProtectionContainerResource ]] = kwargs .pop ("cls" , None )
259
-
260
- content_type = content_type or "application/json"
261
- _json = None
262
- _content = None
263
- if isinstance (parameters , (IOBase , bytes )):
264
- _content = parameters
265
- else :
266
- _json = self ._serialize .body (parameters , "ProtectionContainerResource" )
267
-
268
- request = build_register_request (
269
- vault_name = vault_name ,
270
- resource_group_name = resource_group_name ,
271
- fabric_name = fabric_name ,
272
- container_name = container_name ,
273
- subscription_id = self ._config .subscription_id ,
274
- api_version = api_version ,
275
- content_type = content_type ,
276
- json = _json ,
277
- content = _content ,
278
- template_url = self .register .metadata ["url" ],
279
- headers = _headers ,
280
- params = _params ,
281
- )
282
- request = _convert_request (request )
283
- request .url = self ._client .format_url (request .url )
284
-
285
- _stream = False
286
- pipeline_response : PipelineResponse = await self ._client ._pipeline .run ( # pylint: disable=protected-access
287
- request , stream = _stream , ** kwargs
288
- )
289
-
290
- response = pipeline_response .http_response
291
-
292
- if response .status_code not in [200 , 202 ]:
293
- map_error (status_code = response .status_code , response = response , error_map = error_map )
294
- raise HttpResponseError (response = response , error_format = ARMErrorFormat )
295
-
296
- deserialized = None
297
- if response .status_code == 200 :
349
+ cls : ClsType [_models .ProtectionContainerResource ] = kwargs .pop ("cls" , None )
350
+ polling : Union [bool , AsyncPollingMethod ] = kwargs .pop ("polling" , True )
351
+ lro_delay = kwargs .pop ("polling_interval" , self ._config .polling_interval )
352
+ cont_token : Optional [str ] = kwargs .pop ("continuation_token" , None )
353
+ if cont_token is None :
354
+ raw_result = await self ._register_initial (
355
+ vault_name = vault_name ,
356
+ resource_group_name = resource_group_name ,
357
+ fabric_name = fabric_name ,
358
+ container_name = container_name ,
359
+ parameters = parameters ,
360
+ api_version = api_version ,
361
+ content_type = content_type ,
362
+ cls = lambda x , y , z : x ,
363
+ headers = _headers ,
364
+ params = _params ,
365
+ ** kwargs
366
+ )
367
+ kwargs .pop ("error_map" , None )
368
+
369
+ def get_long_running_output (pipeline_response ):
298
370
deserialized = self ._deserialize ("ProtectionContainerResource" , pipeline_response )
299
-
300
- if cls :
301
- return cls (pipeline_response , deserialized , {})
302
-
303
- return deserialized
304
-
305
- register .metadata = {
371
+ if cls :
372
+ return cls (pipeline_response , deserialized , {})
373
+ return deserialized
374
+
375
+ if polling is True :
376
+ polling_method : AsyncPollingMethod = cast (AsyncPollingMethod , AsyncARMPolling (lro_delay , ** kwargs ))
377
+ elif polling is False :
378
+ polling_method = cast (AsyncPollingMethod , AsyncNoPolling ())
379
+ else :
380
+ polling_method = polling
381
+ if cont_token :
382
+ return AsyncLROPoller .from_continuation_token (
383
+ polling_method = polling_method ,
384
+ continuation_token = cont_token ,
385
+ client = self ._client ,
386
+ deserialization_callback = get_long_running_output ,
387
+ )
388
+ return AsyncLROPoller (self ._client , raw_result , get_long_running_output , polling_method ) # type: ignore
389
+
390
+ begin_register .metadata = {
306
391
"url" : "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}"
307
392
}
308
393
0 commit comments