|
| 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 |
| 18 | + |
| 19 | +T = TypeVar('T') |
| 20 | +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] |
| 21 | + |
| 22 | +class MarketplaceAgreementsOperations: |
| 23 | + """MarketplaceAgreementsOperations 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: ~microsoft_datadog_client.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.DatadogAgreementResourceListResponse"]: |
| 48 | + """List Datadog marketplace agreements in the subscription. |
| 49 | +
|
| 50 | + List Datadog marketplace agreements in the subscription. |
| 51 | +
|
| 52 | + :keyword callable cls: A custom type or function that will be passed the direct response |
| 53 | + :return: An iterator like instance of either DatadogAgreementResourceListResponse or the result of cls(response) |
| 54 | + :rtype: ~azure.core.async_paging.AsyncItemPaged[~microsoft_datadog_client.models.DatadogAgreementResourceListResponse] |
| 55 | + :raises: ~azure.core.exceptions.HttpResponseError |
| 56 | + """ |
| 57 | + cls = kwargs.pop('cls', None) # type: ClsType["models.DatadogAgreementResourceListResponse"] |
| 58 | + error_map = { |
| 59 | + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError |
| 60 | + } |
| 61 | + error_map.update(kwargs.pop('error_map', {})) |
| 62 | + accept = "application/json" |
| 63 | + |
| 64 | + def prepare_request(next_link=None): |
| 65 | + # Construct headers |
| 66 | + header_parameters = {} # type: Dict[str, Any] |
| 67 | + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') |
| 68 | + |
| 69 | + if not next_link: |
| 70 | + # Construct URL |
| 71 | + url = self.list.metadata['url'] # type: ignore |
| 72 | + path_format_arguments = { |
| 73 | + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), |
| 74 | + } |
| 75 | + url = self._client.format_url(url, **path_format_arguments) |
| 76 | + # Construct parameters |
| 77 | + query_parameters = {} # type: Dict[str, Any] |
| 78 | + |
| 79 | + request = self._client.get(url, query_parameters, header_parameters) |
| 80 | + else: |
| 81 | + url = next_link |
| 82 | + query_parameters = {} # type: Dict[str, Any] |
| 83 | + request = self._client.get(url, query_parameters, header_parameters) |
| 84 | + return request |
| 85 | + |
| 86 | + async def extract_data(pipeline_response): |
| 87 | + deserialized = self._deserialize('DatadogAgreementResourceListResponse', pipeline_response) |
| 88 | + list_of_elem = deserialized.value |
| 89 | + if cls: |
| 90 | + list_of_elem = cls(list_of_elem) |
| 91 | + return deserialized.next_link or None, AsyncList(list_of_elem) |
| 92 | + |
| 93 | + async def get_next(next_link=None): |
| 94 | + request = prepare_request(next_link) |
| 95 | + |
| 96 | + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) |
| 97 | + response = pipeline_response.http_response |
| 98 | + |
| 99 | + if response.status_code not in [200]: |
| 100 | + error = self._deserialize(models.ResourceProviderDefaultErrorResponse, response) |
| 101 | + map_error(status_code=response.status_code, response=response, error_map=error_map) |
| 102 | + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) |
| 103 | + |
| 104 | + return pipeline_response |
| 105 | + |
| 106 | + return AsyncItemPaged( |
| 107 | + get_next, extract_data |
| 108 | + ) |
| 109 | + list.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.Datadog/agreements'} # type: ignore |
| 110 | + |
| 111 | + async def create( |
| 112 | + self, |
| 113 | + body: Optional["models.DatadogAgreementResource"] = None, |
| 114 | + **kwargs |
| 115 | + ) -> "models.DatadogAgreementResource": |
| 116 | + """Create Datadog marketplace agreement in the subscription. |
| 117 | +
|
| 118 | + Create Datadog marketplace agreement in the subscription. |
| 119 | +
|
| 120 | + :param body: |
| 121 | + :type body: ~microsoft_datadog_client.models.DatadogAgreementResource |
| 122 | + :keyword callable cls: A custom type or function that will be passed the direct response |
| 123 | + :return: DatadogAgreementResource, or the result of cls(response) |
| 124 | + :rtype: ~microsoft_datadog_client.models.DatadogAgreementResource |
| 125 | + :raises: ~azure.core.exceptions.HttpResponseError |
| 126 | + """ |
| 127 | + cls = kwargs.pop('cls', None) # type: ClsType["models.DatadogAgreementResource"] |
| 128 | + error_map = { |
| 129 | + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError |
| 130 | + } |
| 131 | + error_map.update(kwargs.pop('error_map', {})) |
| 132 | + content_type = kwargs.pop("content_type", "application/json") |
| 133 | + accept = "application/json" |
| 134 | + |
| 135 | + # Construct URL |
| 136 | + url = self.create.metadata['url'] # type: ignore |
| 137 | + path_format_arguments = { |
| 138 | + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), |
| 139 | + } |
| 140 | + url = self._client.format_url(url, **path_format_arguments) |
| 141 | + |
| 142 | + # Construct parameters |
| 143 | + query_parameters = {} # type: Dict[str, Any] |
| 144 | + |
| 145 | + # Construct headers |
| 146 | + header_parameters = {} # type: Dict[str, Any] |
| 147 | + header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') |
| 148 | + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') |
| 149 | + |
| 150 | + body_content_kwargs = {} # type: Dict[str, Any] |
| 151 | + if body is not None: |
| 152 | + body_content = self._serialize.body(body, 'DatadogAgreementResource') |
| 153 | + else: |
| 154 | + body_content = None |
| 155 | + body_content_kwargs['content'] = body_content |
| 156 | + request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) |
| 157 | + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) |
| 158 | + response = pipeline_response.http_response |
| 159 | + |
| 160 | + if response.status_code not in [200]: |
| 161 | + map_error(status_code=response.status_code, response=response, error_map=error_map) |
| 162 | + error = self._deserialize(models.ResourceProviderDefaultErrorResponse, response) |
| 163 | + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) |
| 164 | + |
| 165 | + deserialized = self._deserialize('DatadogAgreementResource', pipeline_response) |
| 166 | + |
| 167 | + if cls: |
| 168 | + return cls(pipeline_response, deserialized, {}) |
| 169 | + |
| 170 | + return deserialized |
| 171 | + create.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.Datadog/agreements/default'} # type: ignore |
0 commit comments