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