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 NetworkProfilesOperations: 25 """NetworkProfilesOperations 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 _delete_initial( 47 self, 48 resource_group_name: str, 49 network_profile_name: str, 50 **kwargs 51 ) -> None: 52 cls = kwargs.pop('cls', None) # type: ClsType[None] 53 error_map = { 54 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 55 } 56 error_map.update(kwargs.pop('error_map', {})) 57 api_version = "2020-03-01" 58 accept = "application/json" 59 60 # Construct URL 61 url = self._delete_initial.metadata['url'] # type: ignore 62 path_format_arguments = { 63 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 64 'networkProfileName': self._serialize.url("network_profile_name", network_profile_name, 'str'), 65 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 66 } 67 url = self._client.format_url(url, **path_format_arguments) 68 69 # Construct parameters 70 query_parameters = {} # type: Dict[str, Any] 71 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 72 73 # Construct headers 74 header_parameters = {} # type: Dict[str, Any] 75 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 76 77 request = self._client.delete(url, query_parameters, header_parameters) 78 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 79 response = pipeline_response.http_response 80 81 if response.status_code not in [200, 202, 204]: 82 map_error(status_code=response.status_code, response=response, error_map=error_map) 83 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 84 85 if cls: 86 return cls(pipeline_response, None, {}) 87 88 _delete_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkProfiles/{networkProfileName}'} # type: ignore 89 90 async def begin_delete( 91 self, 92 resource_group_name: str, 93 network_profile_name: str, 94 **kwargs 95 ) -> AsyncLROPoller[None]: 96 """Deletes the specified network profile. 97 98 :param resource_group_name: The name of the resource group. 99 :type resource_group_name: str 100 :param network_profile_name: The name of the NetworkProfile. 101 :type network_profile_name: str 102 :keyword callable cls: A custom type or function that will be passed the direct response 103 :keyword str continuation_token: A continuation token to restart a poller from a saved state. 104 :keyword polling: Pass in True if you'd like the AsyncARMPolling polling method, 105 False for no polling, or your own initialized polling object for a personal polling strategy. 106 :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod 107 :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. 108 :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) 109 :rtype: ~azure.core.polling.AsyncLROPoller[None] 110 :raises ~azure.core.exceptions.HttpResponseError: 111 """ 112 polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] 113 cls = kwargs.pop('cls', None) # type: ClsType[None] 114 lro_delay = kwargs.pop( 115 'polling_interval', 116 self._config.polling_interval 117 ) 118 cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] 119 if cont_token is None: 120 raw_result = await self._delete_initial( 121 resource_group_name=resource_group_name, 122 network_profile_name=network_profile_name, 123 cls=lambda x,y,z: x, 124 **kwargs 125 ) 126 127 kwargs.pop('error_map', None) 128 kwargs.pop('content_type', None) 129 130 def get_long_running_output(pipeline_response): 131 if cls: 132 return cls(pipeline_response, None, {}) 133 134 path_format_arguments = { 135 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 136 'networkProfileName': self._serialize.url("network_profile_name", network_profile_name, 'str'), 137 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 138 } 139 140 if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, path_format_arguments=path_format_arguments, **kwargs) 141 elif polling is False: polling_method = AsyncNoPolling() 142 else: polling_method = polling 143 if cont_token: 144 return AsyncLROPoller.from_continuation_token( 145 polling_method=polling_method, 146 continuation_token=cont_token, 147 client=self._client, 148 deserialization_callback=get_long_running_output 149 ) 150 else: 151 return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) 152 begin_delete.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkProfiles/{networkProfileName}'} # type: ignore 153 154 async def get( 155 self, 156 resource_group_name: str, 157 network_profile_name: str, 158 expand: Optional[str] = None, 159 **kwargs 160 ) -> "_models.NetworkProfile": 161 """Gets the specified network profile in a specified resource group. 162 163 :param resource_group_name: The name of the resource group. 164 :type resource_group_name: str 165 :param network_profile_name: The name of the public IP prefix. 166 :type network_profile_name: str 167 :param expand: Expands referenced resources. 168 :type expand: str 169 :keyword callable cls: A custom type or function that will be passed the direct response 170 :return: NetworkProfile, or the result of cls(response) 171 :rtype: ~azure.mgmt.network.v2020_03_01.models.NetworkProfile 172 :raises: ~azure.core.exceptions.HttpResponseError 173 """ 174 cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkProfile"] 175 error_map = { 176 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 177 } 178 error_map.update(kwargs.pop('error_map', {})) 179 api_version = "2020-03-01" 180 accept = "application/json" 181 182 # Construct URL 183 url = self.get.metadata['url'] # type: ignore 184 path_format_arguments = { 185 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 186 'networkProfileName': self._serialize.url("network_profile_name", network_profile_name, 'str'), 187 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 188 } 189 url = self._client.format_url(url, **path_format_arguments) 190 191 # Construct parameters 192 query_parameters = {} # type: Dict[str, Any] 193 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 194 if expand is not None: 195 query_parameters['$expand'] = self._serialize.query("expand", expand, 'str') 196 197 # Construct headers 198 header_parameters = {} # type: Dict[str, Any] 199 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 200 201 request = self._client.get(url, query_parameters, header_parameters) 202 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 203 response = pipeline_response.http_response 204 205 if response.status_code not in [200]: 206 map_error(status_code=response.status_code, response=response, error_map=error_map) 207 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 208 209 deserialized = self._deserialize('NetworkProfile', pipeline_response) 210 211 if cls: 212 return cls(pipeline_response, deserialized, {}) 213 214 return deserialized 215 get.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkProfiles/{networkProfileName}'} # type: ignore 216 217 async def create_or_update( 218 self, 219 resource_group_name: str, 220 network_profile_name: str, 221 parameters: "_models.NetworkProfile", 222 **kwargs 223 ) -> "_models.NetworkProfile": 224 """Creates or updates a network profile. 225 226 :param resource_group_name: The name of the resource group. 227 :type resource_group_name: str 228 :param network_profile_name: The name of the network profile. 229 :type network_profile_name: str 230 :param parameters: Parameters supplied to the create or update network profile operation. 231 :type parameters: ~azure.mgmt.network.v2020_03_01.models.NetworkProfile 232 :keyword callable cls: A custom type or function that will be passed the direct response 233 :return: NetworkProfile, or the result of cls(response) 234 :rtype: ~azure.mgmt.network.v2020_03_01.models.NetworkProfile 235 :raises: ~azure.core.exceptions.HttpResponseError 236 """ 237 cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkProfile"] 238 error_map = { 239 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 240 } 241 error_map.update(kwargs.pop('error_map', {})) 242 api_version = "2020-03-01" 243 content_type = kwargs.pop("content_type", "application/json") 244 accept = "application/json" 245 246 # Construct URL 247 url = self.create_or_update.metadata['url'] # type: ignore 248 path_format_arguments = { 249 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 250 'networkProfileName': self._serialize.url("network_profile_name", network_profile_name, 'str'), 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['Content-Type'] = self._serialize.header("content_type", content_type, 'str') 262 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 263 264 body_content_kwargs = {} # type: Dict[str, Any] 265 body_content = self._serialize.body(parameters, 'NetworkProfile') 266 body_content_kwargs['content'] = body_content 267 request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) 268 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 269 response = pipeline_response.http_response 270 271 if response.status_code not in [200, 201]: 272 map_error(status_code=response.status_code, response=response, error_map=error_map) 273 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 274 275 if response.status_code == 200: 276 deserialized = self._deserialize('NetworkProfile', pipeline_response) 277 278 if response.status_code == 201: 279 deserialized = self._deserialize('NetworkProfile', pipeline_response) 280 281 if cls: 282 return cls(pipeline_response, deserialized, {}) 283 284 return deserialized 285 create_or_update.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkProfiles/{networkProfileName}'} # type: ignore 286 287 async def update_tags( 288 self, 289 resource_group_name: str, 290 network_profile_name: str, 291 parameters: "_models.TagsObject", 292 **kwargs 293 ) -> "_models.NetworkProfile": 294 """Updates network profile tags. 295 296 :param resource_group_name: The name of the resource group. 297 :type resource_group_name: str 298 :param network_profile_name: The name of the network profile. 299 :type network_profile_name: str 300 :param parameters: Parameters supplied to update network profile tags. 301 :type parameters: ~azure.mgmt.network.v2020_03_01.models.TagsObject 302 :keyword callable cls: A custom type or function that will be passed the direct response 303 :return: NetworkProfile, or the result of cls(response) 304 :rtype: ~azure.mgmt.network.v2020_03_01.models.NetworkProfile 305 :raises: ~azure.core.exceptions.HttpResponseError 306 """ 307 cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkProfile"] 308 error_map = { 309 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 310 } 311 error_map.update(kwargs.pop('error_map', {})) 312 api_version = "2020-03-01" 313 content_type = kwargs.pop("content_type", "application/json") 314 accept = "application/json" 315 316 # Construct URL 317 url = self.update_tags.metadata['url'] # type: ignore 318 path_format_arguments = { 319 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 320 'networkProfileName': self._serialize.url("network_profile_name", network_profile_name, 'str'), 321 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 322 } 323 url = self._client.format_url(url, **path_format_arguments) 324 325 # Construct parameters 326 query_parameters = {} # type: Dict[str, Any] 327 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 328 329 # Construct headers 330 header_parameters = {} # type: Dict[str, Any] 331 header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') 332 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 333 334 body_content_kwargs = {} # type: Dict[str, Any] 335 body_content = self._serialize.body(parameters, 'TagsObject') 336 body_content_kwargs['content'] = body_content 337 request = self._client.patch(url, query_parameters, header_parameters, **body_content_kwargs) 338 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 339 response = pipeline_response.http_response 340 341 if response.status_code not in [200]: 342 map_error(status_code=response.status_code, response=response, error_map=error_map) 343 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 344 345 deserialized = self._deserialize('NetworkProfile', pipeline_response) 346 347 if cls: 348 return cls(pipeline_response, deserialized, {}) 349 350 return deserialized 351 update_tags.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkProfiles/{networkProfileName}'} # type: ignore 352 353 def list_all( 354 self, 355 **kwargs 356 ) -> AsyncIterable["_models.NetworkProfileListResult"]: 357 """Gets all the network profiles in a subscription. 358 359 :keyword callable cls: A custom type or function that will be passed the direct response 360 :return: An iterator like instance of either NetworkProfileListResult or the result of cls(response) 361 :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.network.v2020_03_01.models.NetworkProfileListResult] 362 :raises: ~azure.core.exceptions.HttpResponseError 363 """ 364 cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkProfileListResult"] 365 error_map = { 366 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 367 } 368 error_map.update(kwargs.pop('error_map', {})) 369 api_version = "2020-03-01" 370 accept = "application/json" 371 372 def prepare_request(next_link=None): 373 # Construct headers 374 header_parameters = {} # type: Dict[str, Any] 375 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 376 377 if not next_link: 378 # Construct URL 379 url = self.list_all.metadata['url'] # type: ignore 380 path_format_arguments = { 381 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 382 } 383 url = self._client.format_url(url, **path_format_arguments) 384 # Construct parameters 385 query_parameters = {} # type: Dict[str, Any] 386 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 387 388 request = self._client.get(url, query_parameters, header_parameters) 389 else: 390 url = next_link 391 query_parameters = {} # type: Dict[str, Any] 392 request = self._client.get(url, query_parameters, header_parameters) 393 return request 394 395 async def extract_data(pipeline_response): 396 deserialized = self._deserialize('NetworkProfileListResult', pipeline_response) 397 list_of_elem = deserialized.value 398 if cls: 399 list_of_elem = cls(list_of_elem) 400 return deserialized.next_link or None, AsyncList(list_of_elem) 401 402 async def get_next(next_link=None): 403 request = prepare_request(next_link) 404 405 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 406 response = pipeline_response.http_response 407 408 if response.status_code not in [200]: 409 map_error(status_code=response.status_code, response=response, error_map=error_map) 410 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 411 412 return pipeline_response 413 414 return AsyncItemPaged( 415 get_next, extract_data 416 ) 417 list_all.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.Network/networkProfiles'} # type: ignore 418 419 def list( 420 self, 421 resource_group_name: str, 422 **kwargs 423 ) -> AsyncIterable["_models.NetworkProfileListResult"]: 424 """Gets all network profiles in a resource group. 425 426 :param resource_group_name: The name of the resource group. 427 :type resource_group_name: str 428 :keyword callable cls: A custom type or function that will be passed the direct response 429 :return: An iterator like instance of either NetworkProfileListResult or the result of cls(response) 430 :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.network.v2020_03_01.models.NetworkProfileListResult] 431 :raises: ~azure.core.exceptions.HttpResponseError 432 """ 433 cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkProfileListResult"] 434 error_map = { 435 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 436 } 437 error_map.update(kwargs.pop('error_map', {})) 438 api_version = "2020-03-01" 439 accept = "application/json" 440 441 def prepare_request(next_link=None): 442 # Construct headers 443 header_parameters = {} # type: Dict[str, Any] 444 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 445 446 if not next_link: 447 # Construct URL 448 url = self.list.metadata['url'] # type: ignore 449 path_format_arguments = { 450 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 451 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 452 } 453 url = self._client.format_url(url, **path_format_arguments) 454 # Construct parameters 455 query_parameters = {} # type: Dict[str, Any] 456 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 457 458 request = self._client.get(url, query_parameters, header_parameters) 459 else: 460 url = next_link 461 query_parameters = {} # type: Dict[str, Any] 462 request = self._client.get(url, query_parameters, header_parameters) 463 return request 464 465 async def extract_data(pipeline_response): 466 deserialized = self._deserialize('NetworkProfileListResult', pipeline_response) 467 list_of_elem = deserialized.value 468 if cls: 469 list_of_elem = cls(list_of_elem) 470 return deserialized.next_link or None, AsyncList(list_of_elem) 471 472 async def get_next(next_link=None): 473 request = prepare_request(next_link) 474 475 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 476 response = pipeline_response.http_response 477 478 if response.status_code not in [200]: 479 map_error(status_code=response.status_code, response=response, error_map=error_map) 480 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 481 482 return pipeline_response 483 484 return AsyncItemPaged( 485 get_next, extract_data 486 ) 487 list.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkProfiles'} # type: ignore 488