1# pylint: disable=too-many-lines
2# coding=utf-8
3# --------------------------------------------------------------------------
4# Copyright (c) Microsoft Corporation. All rights reserved.
5# Licensed under the MIT License. See License.txt in the project root for license information.
6# Code generated by Microsoft (R) AutoRest Code Generator.
7# Changes may cause incorrect behavior and will be lost if the code is regenerated.
8# --------------------------------------------------------------------------
9from typing import Any, Callable, Dict, Iterable, Optional, TypeVar
10import urllib.parse
11
12from azure.core.exceptions import (
13 ClientAuthenticationError,
14 HttpResponseError,
15 ResourceExistsError,
16 ResourceNotFoundError,
17 ResourceNotModifiedError,
18 map_error,
19)
20from azure.core.paging import ItemPaged
21from azure.core.pipeline import PipelineResponse
22from azure.core.pipeline.transport import HttpResponse
23from azure.core.rest import HttpRequest
24from azure.core.tracing.decorator import distributed_trace
25from azure.core.utils import case_insensitive_dict
26from azure.mgmt.core.exceptions import ARMErrorFormat
27
28from .. import models as _models
29from .._serialization import Serializer
30from .._vendor import _convert_request
31
32T = TypeVar("T")
33ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]]
34
35_SERIALIZER = Serializer()
36_SERIALIZER.client_side_validation = False
37
38
39def build_list_request(**kwargs: Any) -> HttpRequest:
40 _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
41 _params = case_insensitive_dict(kwargs.pop("params", {}) or {})
42
43 api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2023-04-27"))
44 accept = _headers.pop("Accept", "application/json")
45
46 # Construct URL
47 _url = kwargs.pop("template_url", "/providers/Dynatrace.Observability/operations")
48
49 # Construct parameters
50 _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
51
52 # Construct headers
53 _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
54
55 return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs)
56
57
58class Operations:
59 """
60 .. warning::
61 **DO NOT** instantiate this class directly.
62
63 Instead, you should access the following operations through
64 :class:`~azure.mgmt.dynatrace.DynatraceObservabilityMgmtClient`'s
65 :attr:`operations` attribute.
66 """
67
68 models = _models
69
70 def __init__(self, *args, **kwargs):
71 input_args = list(args)
72 self._client = input_args.pop(0) if input_args else kwargs.pop("client")
73 self._config = input_args.pop(0) if input_args else kwargs.pop("config")
74 self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer")
75 self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer")
76
77 @distributed_trace
78 def list(self, **kwargs: Any) -> Iterable["_models.Operation"]:
79 """List the operations for Dynatrace.Observability.
80
81 List the operations for Dynatrace.Observability.
82
83 :keyword callable cls: A custom type or function that will be passed the direct response
84 :return: An iterator like instance of either Operation or the result of cls(response)
85 :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.dynatrace.models.Operation]
86 :raises ~azure.core.exceptions.HttpResponseError:
87 """
88 _headers = kwargs.pop("headers", {}) or {}
89 _params = case_insensitive_dict(kwargs.pop("params", {}) or {})
90
91 api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version))
92 cls: ClsType[_models.OperationListResult] = kwargs.pop("cls", None)
93
94 error_map = {
95 401: ClientAuthenticationError,
96 404: ResourceNotFoundError,
97 409: ResourceExistsError,
98 304: ResourceNotModifiedError,
99 }
100 error_map.update(kwargs.pop("error_map", {}) or {})
101
102 def prepare_request(next_link=None):
103 if not next_link:
104
105 request = build_list_request(
106 api_version=api_version,
107 template_url=self.list.metadata["url"],
108 headers=_headers,
109 params=_params,
110 )
111 request = _convert_request(request)
112 request.url = self._client.format_url(request.url)
113
114 else:
115 # make call to next link with the client's api-version
116 _parsed_next_link = urllib.parse.urlparse(next_link)
117 _next_request_params = case_insensitive_dict(
118 {
119 key: [urllib.parse.quote(v) for v in value]
120 for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items()
121 }
122 )
123 _next_request_params["api-version"] = self._config.api_version
124 request = HttpRequest(
125 "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params
126 )
127 request = _convert_request(request)
128 request.url = self._client.format_url(request.url)
129 request.method = "GET"
130 return request
131
132 def extract_data(pipeline_response):
133 deserialized = self._deserialize("OperationListResult", pipeline_response)
134 list_of_elem = deserialized.value
135 if cls:
136 list_of_elem = cls(list_of_elem) # type: ignore
137 return deserialized.next_link or None, iter(list_of_elem)
138
139 def get_next(next_link=None):
140 request = prepare_request(next_link)
141
142 _stream = False
143 pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
144 request, stream=_stream, **kwargs
145 )
146 response = pipeline_response.http_response
147
148 if response.status_code not in [200]:
149 map_error(status_code=response.status_code, response=response, error_map=error_map)
150 error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response)
151 raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)
152
153 return pipeline_response
154
155 return ItemPaged(get_next, extract_data)
156
157 list.metadata = {"url": "/providers/Dynatrace.Observability/operations"}