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 Operations: 23 """Operations 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 **kwargs 47 ) -> AsyncIterable["_models.OperationListResult"]: 48 """Lists all of the available Network Rest API operations. 49 50 :keyword callable cls: A custom type or function that will be passed the direct response 51 :return: An iterator like instance of either OperationListResult or the result of cls(response) 52 :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.network.v2020_03_01.models.OperationListResult] 53 :raises: ~azure.core.exceptions.HttpResponseError 54 """ 55 cls = kwargs.pop('cls', None) # type: ClsType["_models.OperationListResult"] 56 error_map = { 57 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 58 } 59 error_map.update(kwargs.pop('error_map', {})) 60 api_version = "2020-03-01" 61 accept = "application/json" 62 63 def prepare_request(next_link=None): 64 # Construct headers 65 header_parameters = {} # type: Dict[str, Any] 66 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 67 68 if not next_link: 69 # Construct URL 70 url = self.list.metadata['url'] # type: ignore 71 # Construct parameters 72 query_parameters = {} # type: Dict[str, Any] 73 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 74 75 request = self._client.get(url, query_parameters, header_parameters) 76 else: 77 url = next_link 78 query_parameters = {} # type: Dict[str, Any] 79 request = self._client.get(url, query_parameters, header_parameters) 80 return request 81 82 async def extract_data(pipeline_response): 83 deserialized = self._deserialize('OperationListResult', pipeline_response) 84 list_of_elem = deserialized.value 85 if cls: 86 list_of_elem = cls(list_of_elem) 87 return deserialized.next_link or None, AsyncList(list_of_elem) 88 89 async def get_next(next_link=None): 90 request = prepare_request(next_link) 91 92 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 93 response = pipeline_response.http_response 94 95 if response.status_code not in [200]: 96 map_error(status_code=response.status_code, response=response, error_map=error_map) 97 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 98 99 return pipeline_response 100 101 return AsyncItemPaged( 102 get_next, extract_data 103 ) 104 list.metadata = {'url': '/providers/Microsoft.Network/operations'} # type: ignore 105