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 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.mgmt.core.exceptions import ARMErrorFormat 16 17from ... import models as _models 18 19T = TypeVar('T') 20ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] 21 22class ExpressRouteLinksOperations: 23 """ExpressRouteLinksOperations async operations. 24 25 You should not instantiate this class directly. Instead, you should create a Client instance that 26 instantiates it for you and attaches it as an attribute. 27 28 :ivar models: Alias to model classes used in this operation group. 29 :type models: ~azure.mgmt.network.v2020_03_01.models 30 :param client: Client for service requests. 31 :param config: Configuration of service client. 32 :param serializer: An object model serializer. 33 :param deserializer: An object model deserializer. 34 """ 35 36 models = _models 37 38 def __init__(self, client, config, serializer, deserializer) -> None: 39 self._client = client 40 self._serialize = serializer 41 self._deserialize = deserializer 42 self._config = config 43 44 async def get( 45 self, 46 resource_group_name: str, 47 express_route_port_name: str, 48 link_name: str, 49 **kwargs 50 ) -> "_models.ExpressRouteLink": 51 """Retrieves the specified ExpressRouteLink resource. 52 53 :param resource_group_name: The name of the resource group. 54 :type resource_group_name: str 55 :param express_route_port_name: The name of the ExpressRoutePort resource. 56 :type express_route_port_name: str 57 :param link_name: The name of the ExpressRouteLink resource. 58 :type link_name: str 59 :keyword callable cls: A custom type or function that will be passed the direct response 60 :return: ExpressRouteLink, or the result of cls(response) 61 :rtype: ~azure.mgmt.network.v2020_03_01.models.ExpressRouteLink 62 :raises: ~azure.core.exceptions.HttpResponseError 63 """ 64 cls = kwargs.pop('cls', None) # type: ClsType["_models.ExpressRouteLink"] 65 error_map = { 66 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 67 } 68 error_map.update(kwargs.pop('error_map', {})) 69 api_version = "2020-03-01" 70 accept = "application/json" 71 72 # Construct URL 73 url = self.get.metadata['url'] # type: ignore 74 path_format_arguments = { 75 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 76 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 77 'expressRoutePortName': self._serialize.url("express_route_port_name", express_route_port_name, 'str'), 78 'linkName': self._serialize.url("link_name", link_name, 'str'), 79 } 80 url = self._client.format_url(url, **path_format_arguments) 81 82 # Construct parameters 83 query_parameters = {} # type: Dict[str, Any] 84 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 85 86 # Construct headers 87 header_parameters = {} # type: Dict[str, Any] 88 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 89 90 request = self._client.get(url, query_parameters, header_parameters) 91 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 92 response = pipeline_response.http_response 93 94 if response.status_code not in [200]: 95 map_error(status_code=response.status_code, response=response, error_map=error_map) 96 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 97 98 deserialized = self._deserialize('ExpressRouteLink', pipeline_response) 99 100 if cls: 101 return cls(pipeline_response, deserialized, {}) 102 103 return deserialized 104 get.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/ExpressRoutePorts/{expressRoutePortName}/links/{linkName}'} # type: ignore 105 106 def list( 107 self, 108 resource_group_name: str, 109 express_route_port_name: str, 110 **kwargs 111 ) -> AsyncIterable["_models.ExpressRouteLinkListResult"]: 112 """Retrieve the ExpressRouteLink sub-resources of the specified ExpressRoutePort resource. 113 114 :param resource_group_name: The name of the resource group. 115 :type resource_group_name: str 116 :param express_route_port_name: The name of the ExpressRoutePort resource. 117 :type express_route_port_name: str 118 :keyword callable cls: A custom type or function that will be passed the direct response 119 :return: An iterator like instance of either ExpressRouteLinkListResult or the result of cls(response) 120 :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.network.v2020_03_01.models.ExpressRouteLinkListResult] 121 :raises: ~azure.core.exceptions.HttpResponseError 122 """ 123 cls = kwargs.pop('cls', None) # type: ClsType["_models.ExpressRouteLinkListResult"] 124 error_map = { 125 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 126 } 127 error_map.update(kwargs.pop('error_map', {})) 128 api_version = "2020-03-01" 129 accept = "application/json" 130 131 def prepare_request(next_link=None): 132 # Construct headers 133 header_parameters = {} # type: Dict[str, Any] 134 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 135 136 if not next_link: 137 # Construct URL 138 url = self.list.metadata['url'] # type: ignore 139 path_format_arguments = { 140 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 141 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 142 'expressRoutePortName': self._serialize.url("express_route_port_name", express_route_port_name, 'str'), 143 } 144 url = self._client.format_url(url, **path_format_arguments) 145 # Construct parameters 146 query_parameters = {} # type: Dict[str, Any] 147 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 148 149 request = self._client.get(url, query_parameters, header_parameters) 150 else: 151 url = next_link 152 query_parameters = {} # type: Dict[str, Any] 153 request = self._client.get(url, query_parameters, header_parameters) 154 return request 155 156 async def extract_data(pipeline_response): 157 deserialized = self._deserialize('ExpressRouteLinkListResult', pipeline_response) 158 list_of_elem = deserialized.value 159 if cls: 160 list_of_elem = cls(list_of_elem) 161 return deserialized.next_link or None, AsyncList(list_of_elem) 162 163 async def get_next(next_link=None): 164 request = prepare_request(next_link) 165 166 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 167 response = pipeline_response.http_response 168 169 if response.status_code not in [200]: 170 map_error(status_code=response.status_code, response=response, error_map=error_map) 171 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 172 173 return pipeline_response 174 175 return AsyncItemPaged( 176 get_next, extract_data 177 ) 178 list.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/ExpressRoutePorts/{expressRoutePortName}/links'} # type: ignore 179