1# coding=utf-8 2# -------------------------------------------------------------------------- 3# Copyright (c) Microsoft Corporation. All rights reserved. 4# Licensed under the MIT License. See License.txt in the project root for license information. 5# Code generated by Microsoft (R) AutoRest Code Generator. 6# Changes may cause incorrect behavior and will be lost if the code is regenerated. 7# -------------------------------------------------------------------------- 8from typing import Any, AsyncIterable, Callable, Dict, Generic, Optional, TypeVar, Union 9import warnings 10 11from azure.core.async_paging import AsyncItemPaged, AsyncList 12from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error 13from azure.core.pipeline import PipelineResponse 14from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest 15from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod 16from azure.mgmt.core.exceptions import ARMErrorFormat 17from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling 18 19from ... import models as _models 20 21T = TypeVar('T') 22ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] 23 24class LocalNetworkGatewaysOperations: 25 """LocalNetworkGatewaysOperations async operations. 26 27 You should not instantiate this class directly. Instead, you should create a Client instance that 28 instantiates it for you and attaches it as an attribute. 29 30 :ivar models: Alias to model classes used in this operation group. 31 :type models: ~azure.mgmt.network.v2020_03_01.models 32 :param client: Client for service requests. 33 :param config: Configuration of service client. 34 :param serializer: An object model serializer. 35 :param deserializer: An object model deserializer. 36 """ 37 38 models = _models 39 40 def __init__(self, client, config, serializer, deserializer) -> None: 41 self._client = client 42 self._serialize = serializer 43 self._deserialize = deserializer 44 self._config = config 45 46 async def _create_or_update_initial( 47 self, 48 resource_group_name: str, 49 local_network_gateway_name: str, 50 parameters: "_models.LocalNetworkGateway", 51 **kwargs 52 ) -> "_models.LocalNetworkGateway": 53 cls = kwargs.pop('cls', None) # type: ClsType["_models.LocalNetworkGateway"] 54 error_map = { 55 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 56 } 57 error_map.update(kwargs.pop('error_map', {})) 58 api_version = "2020-03-01" 59 content_type = kwargs.pop("content_type", "application/json") 60 accept = "application/json" 61 62 # Construct URL 63 url = self._create_or_update_initial.metadata['url'] # type: ignore 64 path_format_arguments = { 65 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 66 'localNetworkGatewayName': self._serialize.url("local_network_gateway_name", local_network_gateway_name, 'str', min_length=1), 67 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 68 } 69 url = self._client.format_url(url, **path_format_arguments) 70 71 # Construct parameters 72 query_parameters = {} # type: Dict[str, Any] 73 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 74 75 # Construct headers 76 header_parameters = {} # type: Dict[str, Any] 77 header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') 78 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 79 80 body_content_kwargs = {} # type: Dict[str, Any] 81 body_content = self._serialize.body(parameters, 'LocalNetworkGateway') 82 body_content_kwargs['content'] = body_content 83 request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) 84 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 85 response = pipeline_response.http_response 86 87 if response.status_code not in [200, 201]: 88 map_error(status_code=response.status_code, response=response, error_map=error_map) 89 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 90 91 if response.status_code == 200: 92 deserialized = self._deserialize('LocalNetworkGateway', pipeline_response) 93 94 if response.status_code == 201: 95 deserialized = self._deserialize('LocalNetworkGateway', pipeline_response) 96 97 if cls: 98 return cls(pipeline_response, deserialized, {}) 99 100 return deserialized 101 _create_or_update_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/localNetworkGateways/{localNetworkGatewayName}'} # type: ignore 102 103 async def begin_create_or_update( 104 self, 105 resource_group_name: str, 106 local_network_gateway_name: str, 107 parameters: "_models.LocalNetworkGateway", 108 **kwargs 109 ) -> AsyncLROPoller["_models.LocalNetworkGateway"]: 110 """Creates or updates a local network gateway in the specified resource group. 111 112 :param resource_group_name: The name of the resource group. 113 :type resource_group_name: str 114 :param local_network_gateway_name: The name of the local network gateway. 115 :type local_network_gateway_name: str 116 :param parameters: Parameters supplied to the create or update local network gateway operation. 117 :type parameters: ~azure.mgmt.network.v2020_03_01.models.LocalNetworkGateway 118 :keyword callable cls: A custom type or function that will be passed the direct response 119 :keyword str continuation_token: A continuation token to restart a poller from a saved state. 120 :keyword polling: Pass in True if you'd like the AsyncARMPolling polling method, 121 False for no polling, or your own initialized polling object for a personal polling strategy. 122 :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod 123 :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. 124 :return: An instance of AsyncLROPoller that returns either LocalNetworkGateway or the result of cls(response) 125 :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.network.v2020_03_01.models.LocalNetworkGateway] 126 :raises ~azure.core.exceptions.HttpResponseError: 127 """ 128 polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] 129 cls = kwargs.pop('cls', None) # type: ClsType["_models.LocalNetworkGateway"] 130 lro_delay = kwargs.pop( 131 'polling_interval', 132 self._config.polling_interval 133 ) 134 cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] 135 if cont_token is None: 136 raw_result = await self._create_or_update_initial( 137 resource_group_name=resource_group_name, 138 local_network_gateway_name=local_network_gateway_name, 139 parameters=parameters, 140 cls=lambda x,y,z: x, 141 **kwargs 142 ) 143 144 kwargs.pop('error_map', None) 145 kwargs.pop('content_type', None) 146 147 def get_long_running_output(pipeline_response): 148 deserialized = self._deserialize('LocalNetworkGateway', pipeline_response) 149 150 if cls: 151 return cls(pipeline_response, deserialized, {}) 152 return deserialized 153 154 path_format_arguments = { 155 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 156 'localNetworkGatewayName': self._serialize.url("local_network_gateway_name", local_network_gateway_name, 'str', min_length=1), 157 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 158 } 159 160 if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, path_format_arguments=path_format_arguments, **kwargs) 161 elif polling is False: polling_method = AsyncNoPolling() 162 else: polling_method = polling 163 if cont_token: 164 return AsyncLROPoller.from_continuation_token( 165 polling_method=polling_method, 166 continuation_token=cont_token, 167 client=self._client, 168 deserialization_callback=get_long_running_output 169 ) 170 else: 171 return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) 172 begin_create_or_update.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/localNetworkGateways/{localNetworkGatewayName}'} # type: ignore 173 174 async def get( 175 self, 176 resource_group_name: str, 177 local_network_gateway_name: str, 178 **kwargs 179 ) -> "_models.LocalNetworkGateway": 180 """Gets the specified local network gateway in a resource group. 181 182 :param resource_group_name: The name of the resource group. 183 :type resource_group_name: str 184 :param local_network_gateway_name: The name of the local network gateway. 185 :type local_network_gateway_name: str 186 :keyword callable cls: A custom type or function that will be passed the direct response 187 :return: LocalNetworkGateway, or the result of cls(response) 188 :rtype: ~azure.mgmt.network.v2020_03_01.models.LocalNetworkGateway 189 :raises: ~azure.core.exceptions.HttpResponseError 190 """ 191 cls = kwargs.pop('cls', None) # type: ClsType["_models.LocalNetworkGateway"] 192 error_map = { 193 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 194 } 195 error_map.update(kwargs.pop('error_map', {})) 196 api_version = "2020-03-01" 197 accept = "application/json" 198 199 # Construct URL 200 url = self.get.metadata['url'] # type: ignore 201 path_format_arguments = { 202 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 203 'localNetworkGatewayName': self._serialize.url("local_network_gateway_name", local_network_gateway_name, 'str', min_length=1), 204 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 205 } 206 url = self._client.format_url(url, **path_format_arguments) 207 208 # Construct parameters 209 query_parameters = {} # type: Dict[str, Any] 210 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 211 212 # Construct headers 213 header_parameters = {} # type: Dict[str, Any] 214 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 215 216 request = self._client.get(url, query_parameters, header_parameters) 217 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 218 response = pipeline_response.http_response 219 220 if response.status_code not in [200]: 221 map_error(status_code=response.status_code, response=response, error_map=error_map) 222 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 223 224 deserialized = self._deserialize('LocalNetworkGateway', pipeline_response) 225 226 if cls: 227 return cls(pipeline_response, deserialized, {}) 228 229 return deserialized 230 get.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/localNetworkGateways/{localNetworkGatewayName}'} # type: ignore 231 232 async def _delete_initial( 233 self, 234 resource_group_name: str, 235 local_network_gateway_name: str, 236 **kwargs 237 ) -> None: 238 cls = kwargs.pop('cls', None) # type: ClsType[None] 239 error_map = { 240 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 241 } 242 error_map.update(kwargs.pop('error_map', {})) 243 api_version = "2020-03-01" 244 accept = "application/json" 245 246 # Construct URL 247 url = self._delete_initial.metadata['url'] # type: ignore 248 path_format_arguments = { 249 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 250 'localNetworkGatewayName': self._serialize.url("local_network_gateway_name", local_network_gateway_name, 'str', min_length=1), 251 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 252 } 253 url = self._client.format_url(url, **path_format_arguments) 254 255 # Construct parameters 256 query_parameters = {} # type: Dict[str, Any] 257 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 258 259 # Construct headers 260 header_parameters = {} # type: Dict[str, Any] 261 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 262 263 request = self._client.delete(url, query_parameters, header_parameters) 264 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 265 response = pipeline_response.http_response 266 267 if response.status_code not in [200, 202, 204]: 268 map_error(status_code=response.status_code, response=response, error_map=error_map) 269 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 270 271 if cls: 272 return cls(pipeline_response, None, {}) 273 274 _delete_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/localNetworkGateways/{localNetworkGatewayName}'} # type: ignore 275 276 async def begin_delete( 277 self, 278 resource_group_name: str, 279 local_network_gateway_name: str, 280 **kwargs 281 ) -> AsyncLROPoller[None]: 282 """Deletes the specified local network gateway. 283 284 :param resource_group_name: The name of the resource group. 285 :type resource_group_name: str 286 :param local_network_gateway_name: The name of the local network gateway. 287 :type local_network_gateway_name: str 288 :keyword callable cls: A custom type or function that will be passed the direct response 289 :keyword str continuation_token: A continuation token to restart a poller from a saved state. 290 :keyword polling: Pass in True if you'd like the AsyncARMPolling polling method, 291 False for no polling, or your own initialized polling object for a personal polling strategy. 292 :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod 293 :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. 294 :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) 295 :rtype: ~azure.core.polling.AsyncLROPoller[None] 296 :raises ~azure.core.exceptions.HttpResponseError: 297 """ 298 polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] 299 cls = kwargs.pop('cls', None) # type: ClsType[None] 300 lro_delay = kwargs.pop( 301 'polling_interval', 302 self._config.polling_interval 303 ) 304 cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] 305 if cont_token is None: 306 raw_result = await self._delete_initial( 307 resource_group_name=resource_group_name, 308 local_network_gateway_name=local_network_gateway_name, 309 cls=lambda x,y,z: x, 310 **kwargs 311 ) 312 313 kwargs.pop('error_map', None) 314 kwargs.pop('content_type', None) 315 316 def get_long_running_output(pipeline_response): 317 if cls: 318 return cls(pipeline_response, None, {}) 319 320 path_format_arguments = { 321 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 322 'localNetworkGatewayName': self._serialize.url("local_network_gateway_name", local_network_gateway_name, 'str', min_length=1), 323 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 324 } 325 326 if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, path_format_arguments=path_format_arguments, **kwargs) 327 elif polling is False: polling_method = AsyncNoPolling() 328 else: polling_method = polling 329 if cont_token: 330 return AsyncLROPoller.from_continuation_token( 331 polling_method=polling_method, 332 continuation_token=cont_token, 333 client=self._client, 334 deserialization_callback=get_long_running_output 335 ) 336 else: 337 return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) 338 begin_delete.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/localNetworkGateways/{localNetworkGatewayName}'} # type: ignore 339 340 async def update_tags( 341 self, 342 resource_group_name: str, 343 local_network_gateway_name: str, 344 parameters: "_models.TagsObject", 345 **kwargs 346 ) -> "_models.LocalNetworkGateway": 347 """Updates a local network gateway tags. 348 349 :param resource_group_name: The name of the resource group. 350 :type resource_group_name: str 351 :param local_network_gateway_name: The name of the local network gateway. 352 :type local_network_gateway_name: str 353 :param parameters: Parameters supplied to update local network gateway tags. 354 :type parameters: ~azure.mgmt.network.v2020_03_01.models.TagsObject 355 :keyword callable cls: A custom type or function that will be passed the direct response 356 :return: LocalNetworkGateway, or the result of cls(response) 357 :rtype: ~azure.mgmt.network.v2020_03_01.models.LocalNetworkGateway 358 :raises: ~azure.core.exceptions.HttpResponseError 359 """ 360 cls = kwargs.pop('cls', None) # type: ClsType["_models.LocalNetworkGateway"] 361 error_map = { 362 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 363 } 364 error_map.update(kwargs.pop('error_map', {})) 365 api_version = "2020-03-01" 366 content_type = kwargs.pop("content_type", "application/json") 367 accept = "application/json" 368 369 # Construct URL 370 url = self.update_tags.metadata['url'] # type: ignore 371 path_format_arguments = { 372 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 373 'localNetworkGatewayName': self._serialize.url("local_network_gateway_name", local_network_gateway_name, 'str', min_length=1), 374 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 375 } 376 url = self._client.format_url(url, **path_format_arguments) 377 378 # Construct parameters 379 query_parameters = {} # type: Dict[str, Any] 380 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 381 382 # Construct headers 383 header_parameters = {} # type: Dict[str, Any] 384 header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') 385 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 386 387 body_content_kwargs = {} # type: Dict[str, Any] 388 body_content = self._serialize.body(parameters, 'TagsObject') 389 body_content_kwargs['content'] = body_content 390 request = self._client.patch(url, query_parameters, header_parameters, **body_content_kwargs) 391 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 392 response = pipeline_response.http_response 393 394 if response.status_code not in [200]: 395 map_error(status_code=response.status_code, response=response, error_map=error_map) 396 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 397 398 deserialized = self._deserialize('LocalNetworkGateway', pipeline_response) 399 400 if cls: 401 return cls(pipeline_response, deserialized, {}) 402 403 return deserialized 404 update_tags.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/localNetworkGateways/{localNetworkGatewayName}'} # type: ignore 405 406 def list( 407 self, 408 resource_group_name: str, 409 **kwargs 410 ) -> AsyncIterable["_models.LocalNetworkGatewayListResult"]: 411 """Gets all the local network gateways in a resource group. 412 413 :param resource_group_name: The name of the resource group. 414 :type resource_group_name: str 415 :keyword callable cls: A custom type or function that will be passed the direct response 416 :return: An iterator like instance of either LocalNetworkGatewayListResult or the result of cls(response) 417 :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.network.v2020_03_01.models.LocalNetworkGatewayListResult] 418 :raises: ~azure.core.exceptions.HttpResponseError 419 """ 420 cls = kwargs.pop('cls', None) # type: ClsType["_models.LocalNetworkGatewayListResult"] 421 error_map = { 422 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 423 } 424 error_map.update(kwargs.pop('error_map', {})) 425 api_version = "2020-03-01" 426 accept = "application/json" 427 428 def prepare_request(next_link=None): 429 # Construct headers 430 header_parameters = {} # type: Dict[str, Any] 431 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 432 433 if not next_link: 434 # Construct URL 435 url = self.list.metadata['url'] # type: ignore 436 path_format_arguments = { 437 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 438 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 439 } 440 url = self._client.format_url(url, **path_format_arguments) 441 # Construct parameters 442 query_parameters = {} # type: Dict[str, Any] 443 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 444 445 request = self._client.get(url, query_parameters, header_parameters) 446 else: 447 url = next_link 448 query_parameters = {} # type: Dict[str, Any] 449 request = self._client.get(url, query_parameters, header_parameters) 450 return request 451 452 async def extract_data(pipeline_response): 453 deserialized = self._deserialize('LocalNetworkGatewayListResult', pipeline_response) 454 list_of_elem = deserialized.value 455 if cls: 456 list_of_elem = cls(list_of_elem) 457 return deserialized.next_link or None, AsyncList(list_of_elem) 458 459 async def get_next(next_link=None): 460 request = prepare_request(next_link) 461 462 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 463 response = pipeline_response.http_response 464 465 if response.status_code not in [200]: 466 map_error(status_code=response.status_code, response=response, error_map=error_map) 467 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 468 469 return pipeline_response 470 471 return AsyncItemPaged( 472 get_next, extract_data 473 ) 474 list.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/localNetworkGateways'} # type: ignore 475