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 VirtualMachineSizesOperations: 23 """VirtualMachineSizesOperations 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.compute.v2018_06_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: Any 48 ) -> AsyncIterable["_models.VirtualMachineSizeListResult"]: 49 """This API is deprecated. Use `Resources Skus 50 <https://docs.microsoft.com/en-us/rest/api/compute/resourceskus/list>`_. 51 52 :param location: The location upon which virtual-machine-sizes is queried. 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 VirtualMachineSizeListResult or the result of cls(response) 56 :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.compute.v2018_06_01.models.VirtualMachineSizeListResult] 57 :raises: ~azure.core.exceptions.HttpResponseError 58 """ 59 cls = kwargs.pop('cls', None) # type: ClsType["_models.VirtualMachineSizeListResult"] 60 error_map = { 61 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 62 } 63 error_map.update(kwargs.pop('error_map', {})) 64 api_version = "2018-06-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', pattern=r'^[-\w\._]+$'), 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('VirtualMachineSizeListResult', pipeline_response) 93 list_of_elem = deserialized.value 94 if cls: 95 list_of_elem = cls(list_of_elem) 96 return 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.Compute/locations/{location}/vmSizes'} # type: ignore 114