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 TYPE_CHECKING 9import warnings 10 11from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error 12from azure.core.paging import ItemPaged 13from azure.core.pipeline import PipelineResponse 14from azure.core.pipeline.transport import HttpRequest, HttpResponse 15from azure.mgmt.core.exceptions import ARMErrorFormat 16 17from .. import models as _models 18 19if TYPE_CHECKING: 20 # pylint: disable=unused-import,ungrouped-imports 21 from typing import Any, Callable, Dict, Generic, Iterable, Optional, TypeVar 22 23 T = TypeVar('T') 24 ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] 25 26class Operations(object): 27 """Operations operations. 28 29 You should not instantiate this class directly. Instead, you should create a Client instance that 30 instantiates it for you and attaches it as an attribute. 31 32 :ivar models: Alias to model classes used in this operation group. 33 :type models: ~azure.mgmt.hdinsight.models 34 :param client: Client for service requests. 35 :param config: Configuration of service client. 36 :param serializer: An object model serializer. 37 :param deserializer: An object model deserializer. 38 """ 39 40 models = _models 41 42 def __init__(self, client, config, serializer, deserializer): 43 self._client = client 44 self._serialize = serializer 45 self._deserialize = deserializer 46 self._config = config 47 48 def list( 49 self, 50 **kwargs # type: Any 51 ): 52 # type: (...) -> Iterable["_models.OperationListResult"] 53 """Lists all of the available HDInsight REST API operations. 54 55 :keyword callable cls: A custom type or function that will be passed the direct response 56 :return: An iterator like instance of either OperationListResult or the result of cls(response) 57 :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.hdinsight.models.OperationListResult] 58 :raises: ~azure.core.exceptions.HttpResponseError 59 """ 60 cls = kwargs.pop('cls', None) # type: ClsType["_models.OperationListResult"] 61 error_map = { 62 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 63 } 64 error_map.update(kwargs.pop('error_map', {})) 65 api_version = "2018-06-01-preview" 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 # Construct parameters 77 query_parameters = {} # type: Dict[str, Any] 78 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 79 80 request = self._client.get(url, query_parameters, header_parameters) 81 else: 82 url = next_link 83 query_parameters = {} # type: Dict[str, Any] 84 request = self._client.get(url, query_parameters, header_parameters) 85 return request 86 87 def extract_data(pipeline_response): 88 deserialized = self._deserialize('OperationListResult', pipeline_response) 89 list_of_elem = deserialized.value 90 if cls: 91 list_of_elem = cls(list_of_elem) 92 return deserialized.next_link or None, iter(list_of_elem) 93 94 def get_next(next_link=None): 95 request = prepare_request(next_link) 96 97 pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) 98 response = pipeline_response.http_response 99 100 if response.status_code not in [200]: 101 error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, response) 102 map_error(status_code=response.status_code, response=response, error_map=error_map) 103 raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) 104 105 return pipeline_response 106 107 return ItemPaged( 108 get_next, extract_data 109 ) 110 list.metadata = {'url': '/providers/Microsoft.HDInsight/operations'} # type: ignore 111