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