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 AvailablePrivateEndpointTypesOperations: 23 """AvailablePrivateEndpointTypesOperations 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 def list( 45 self, 46 location: str, 47 **kwargs 48 ) -> AsyncIterable["_models.AvailablePrivateEndpointTypesResult"]: 49 """Returns all of the resource types that can be linked to a Private Endpoint in this subscription 50 in this region. 51 52 :param location: The location of the domain name. 53 :type location: str 54 :keyword callable cls: A custom type or function that will be passed the direct response 55 :return: An iterator like instance of either AvailablePrivateEndpointTypesResult or the result of cls(response) 56 :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.network.v2020_03_01.models.AvailablePrivateEndpointTypesResult] 57 :raises: ~azure.core.exceptions.HttpResponseError 58 """ 59 cls = kwargs.pop('cls', None) # type: ClsType["_models.AvailablePrivateEndpointTypesResult"] 60 error_map = { 61 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 62 } 63 error_map.update(kwargs.pop('error_map', {})) 64 api_version = "2020-03-01" 65 accept = "application/json" 66 67 def prepare_request(next_link=None): 68 # Construct headers 69 header_parameters = {} # type: Dict[str, Any] 70 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 71 72 if not next_link: 73 # Construct URL 74 url = self.list.metadata['url'] # type: ignore 75 path_format_arguments = { 76 'location': self._serialize.url("location", location, 'str'), 77 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 78 } 79 url = self._client.format_url(url, **path_format_arguments) 80 # Construct parameters 81 query_parameters = {} # type: Dict[str, Any] 82 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 83 84 request = self._client.get(url, query_parameters, header_parameters) 85 else: 86 url = next_link 87 query_parameters = {} # type: Dict[str, Any] 88 request = self._client.get(url, query_parameters, header_parameters) 89 return request 90 91 async def extract_data(pipeline_response): 92 deserialized = self._deserialize('AvailablePrivateEndpointTypesResult', pipeline_response) 93 list_of_elem = deserialized.value 94 if cls: 95 list_of_elem = cls(list_of_elem) 96 return deserialized.next_link or None, AsyncList(list_of_elem) 97 98 async def get_next(next_link=None): 99 request = prepare_request(next_link) 100 101 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 102 response = pipeline_response.http_response 103 104 if response.status_code not in [200]: 105 map_error(status_code=response.status_code, response=response, error_map=error_map) 106 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 107 108 return pipeline_response 109 110 return AsyncItemPaged( 111 get_next, extract_data 112 ) 113 list.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.Network/locations/{location}/availablePrivateEndpointTypes'} # type: ignore 114 115 def list_by_resource_group( 116 self, 117 location: str, 118 resource_group_name: str, 119 **kwargs 120 ) -> AsyncIterable["_models.AvailablePrivateEndpointTypesResult"]: 121 """Returns all of the resource types that can be linked to a Private Endpoint in this subscription 122 in this region. 123 124 :param location: The location of the domain name. 125 :type location: str 126 :param resource_group_name: The name of the resource group. 127 :type resource_group_name: str 128 :keyword callable cls: A custom type or function that will be passed the direct response 129 :return: An iterator like instance of either AvailablePrivateEndpointTypesResult or the result of cls(response) 130 :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.network.v2020_03_01.models.AvailablePrivateEndpointTypesResult] 131 :raises: ~azure.core.exceptions.HttpResponseError 132 """ 133 cls = kwargs.pop('cls', None) # type: ClsType["_models.AvailablePrivateEndpointTypesResult"] 134 error_map = { 135 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 136 } 137 error_map.update(kwargs.pop('error_map', {})) 138 api_version = "2020-03-01" 139 accept = "application/json" 140 141 def prepare_request(next_link=None): 142 # Construct headers 143 header_parameters = {} # type: Dict[str, Any] 144 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 145 146 if not next_link: 147 # Construct URL 148 url = self.list_by_resource_group.metadata['url'] # type: ignore 149 path_format_arguments = { 150 'location': self._serialize.url("location", location, 'str'), 151 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 152 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 153 } 154 url = self._client.format_url(url, **path_format_arguments) 155 # Construct parameters 156 query_parameters = {} # type: Dict[str, Any] 157 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 158 159 request = self._client.get(url, query_parameters, header_parameters) 160 else: 161 url = next_link 162 query_parameters = {} # type: Dict[str, Any] 163 request = self._client.get(url, query_parameters, header_parameters) 164 return request 165 166 async def extract_data(pipeline_response): 167 deserialized = self._deserialize('AvailablePrivateEndpointTypesResult', pipeline_response) 168 list_of_elem = deserialized.value 169 if cls: 170 list_of_elem = cls(list_of_elem) 171 return deserialized.next_link or None, AsyncList(list_of_elem) 172 173 async def get_next(next_link=None): 174 request = prepare_request(next_link) 175 176 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 177 response = pipeline_response.http_response 178 179 if response.status_code not in [200]: 180 map_error(status_code=response.status_code, response=response, error_map=error_map) 181 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 182 183 return pipeline_response 184 185 return AsyncItemPaged( 186 get_next, extract_data 187 ) 188 list_by_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/locations/{location}/availablePrivateEndpointTypes'} # type: ignore 189