|
| 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 | +# -------------------------------------------------------------------------- |
| 8 | +from typing import Any, AsyncIterable, Callable, Dict, Generic, Optional, TypeVar |
| 9 | +import warnings |
| 10 | + |
| 11 | +from azure.core.async_paging import AsyncItemPaged, AsyncList |
| 12 | +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error |
| 13 | +from azure.core.pipeline import PipelineResponse |
| 14 | +from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest |
| 15 | +from azure.mgmt.core.exceptions import ARMErrorFormat |
| 16 | + |
| 17 | +from ... import models as _models |
| 18 | + |
| 19 | +T = TypeVar('T') |
| 20 | +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] |
| 21 | + |
| 22 | +class NetAppResourceQuotaLimitsOperations: |
| 23 | + """NetAppResourceQuotaLimitsOperations 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.netapp.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.SubscriptionQuotaItemList"]: |
| 49 | + """Get quota limits. |
| 50 | +
|
| 51 | + Get the default and current limits for quotas. |
| 52 | +
|
| 53 | + :param location: The location. |
| 54 | + :type location: str |
| 55 | + :keyword callable cls: A custom type or function that will be passed the direct response |
| 56 | + :return: An iterator like instance of either SubscriptionQuotaItemList or the result of cls(response) |
| 57 | + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.netapp.models.SubscriptionQuotaItemList] |
| 58 | + :raises: ~azure.core.exceptions.HttpResponseError |
| 59 | + """ |
| 60 | + cls = kwargs.pop('cls', None) # type: ClsType["_models.SubscriptionQuotaItemList"] |
| 61 | + error_map = { |
| 62 | + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError |
| 63 | + } |
| 64 | + error_map.update(kwargs.pop('error_map', {})) |
| 65 | + api_version = "2021-06-01" |
| 66 | + accept = "application/json" |
| 67 | + |
| 68 | + def prepare_request(next_link=None): |
| 69 | + # Construct headers |
| 70 | + header_parameters = {} # type: Dict[str, Any] |
| 71 | + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') |
| 72 | + |
| 73 | + if not next_link: |
| 74 | + # Construct URL |
| 75 | + url = self.list.metadata['url'] # type: ignore |
| 76 | + path_format_arguments = { |
| 77 | + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), |
| 78 | + 'location': self._serialize.url("location", location, 'str'), |
| 79 | + } |
| 80 | + url = self._client.format_url(url, **path_format_arguments) |
| 81 | + # Construct parameters |
| 82 | + query_parameters = {} # type: Dict[str, Any] |
| 83 | + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') |
| 84 | + |
| 85 | + request = self._client.get(url, query_parameters, header_parameters) |
| 86 | + else: |
| 87 | + url = next_link |
| 88 | + query_parameters = {} # type: Dict[str, Any] |
| 89 | + request = self._client.get(url, query_parameters, header_parameters) |
| 90 | + return request |
| 91 | + |
| 92 | + async def extract_data(pipeline_response): |
| 93 | + deserialized = self._deserialize('SubscriptionQuotaItemList', pipeline_response) |
| 94 | + list_of_elem = deserialized.value |
| 95 | + if cls: |
| 96 | + list_of_elem = cls(list_of_elem) |
| 97 | + return None, AsyncList(list_of_elem) |
| 98 | + |
| 99 | + async def get_next(next_link=None): |
| 100 | + request = prepare_request(next_link) |
| 101 | + |
| 102 | + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) |
| 103 | + response = pipeline_response.http_response |
| 104 | + |
| 105 | + if response.status_code not in [200]: |
| 106 | + map_error(status_code=response.status_code, response=response, error_map=error_map) |
| 107 | + raise HttpResponseError(response=response, error_format=ARMErrorFormat) |
| 108 | + |
| 109 | + return pipeline_response |
| 110 | + |
| 111 | + return AsyncItemPaged( |
| 112 | + get_next, extract_data |
| 113 | + ) |
| 114 | + list.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.NetApp/locations/{location}/quotaLimits'} # type: ignore |
| 115 | + |
| 116 | + async def get( |
| 117 | + self, |
| 118 | + location: str, |
| 119 | + quota_limit_name: str, |
| 120 | + **kwargs: Any |
| 121 | + ) -> "_models.SubscriptionQuotaItem": |
| 122 | + """Get quota limits. |
| 123 | +
|
| 124 | + Get the default and current subscription quota limit. |
| 125 | +
|
| 126 | + :param location: The location. |
| 127 | + :type location: str |
| 128 | + :param quota_limit_name: The name of the Quota Limit. |
| 129 | + :type quota_limit_name: str |
| 130 | + :keyword callable cls: A custom type or function that will be passed the direct response |
| 131 | + :return: SubscriptionQuotaItem, or the result of cls(response) |
| 132 | + :rtype: ~azure.mgmt.netapp.models.SubscriptionQuotaItem |
| 133 | + :raises: ~azure.core.exceptions.HttpResponseError |
| 134 | + """ |
| 135 | + cls = kwargs.pop('cls', None) # type: ClsType["_models.SubscriptionQuotaItem"] |
| 136 | + error_map = { |
| 137 | + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError |
| 138 | + } |
| 139 | + error_map.update(kwargs.pop('error_map', {})) |
| 140 | + api_version = "2021-06-01" |
| 141 | + accept = "application/json" |
| 142 | + |
| 143 | + # Construct URL |
| 144 | + url = self.get.metadata['url'] # type: ignore |
| 145 | + path_format_arguments = { |
| 146 | + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), |
| 147 | + 'location': self._serialize.url("location", location, 'str'), |
| 148 | + 'quotaLimitName': self._serialize.url("quota_limit_name", quota_limit_name, 'str'), |
| 149 | + } |
| 150 | + url = self._client.format_url(url, **path_format_arguments) |
| 151 | + |
| 152 | + # Construct parameters |
| 153 | + query_parameters = {} # type: Dict[str, Any] |
| 154 | + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') |
| 155 | + |
| 156 | + # Construct headers |
| 157 | + header_parameters = {} # type: Dict[str, Any] |
| 158 | + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') |
| 159 | + |
| 160 | + request = self._client.get(url, query_parameters, header_parameters) |
| 161 | + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) |
| 162 | + response = pipeline_response.http_response |
| 163 | + |
| 164 | + if response.status_code not in [200]: |
| 165 | + map_error(status_code=response.status_code, response=response, error_map=error_map) |
| 166 | + raise HttpResponseError(response=response, error_format=ARMErrorFormat) |
| 167 | + |
| 168 | + deserialized = self._deserialize('SubscriptionQuotaItem', pipeline_response) |
| 169 | + |
| 170 | + if cls: |
| 171 | + return cls(pipeline_response, deserialized, {}) |
| 172 | + |
| 173 | + return deserialized |
| 174 | + get.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.NetApp/locations/{location}/quotaLimits/{quotaLimitName}'} # type: ignore |
0 commit comments