|
1 | 1 | # coding=utf-8 |
2 | 2 | # -------------------------------------------------------------------------- |
3 | 3 | # Copyright (c) Microsoft Corporation. All rights reserved. |
4 | | -# Licensed under the MIT License. See License.txt in the project root for |
5 | | -# license information. |
6 | | -# |
| 4 | +# Licensed under the MIT License. See License.txt in the project root for license information. |
7 | 5 | # Code generated by Microsoft (R) AutoRest Code Generator. |
8 | | -# Changes may cause incorrect behavior and will be lost if the code is |
9 | | -# regenerated. |
| 6 | +# Changes may cause incorrect behavior and will be lost if the code is regenerated. |
10 | 7 | # -------------------------------------------------------------------------- |
11 | 8 |
|
12 | | -from typing import Any, Optional, TYPE_CHECKING |
| 9 | +from copy import deepcopy |
| 10 | +from typing import Any, TYPE_CHECKING |
| 11 | +from typing_extensions import Self |
13 | 12 |
|
| 13 | +from azure.core.pipeline import policies |
| 14 | +from azure.core.rest import HttpRequest, HttpResponse |
14 | 15 | from azure.mgmt.core import ARMPipelineClient |
15 | | -from azure.profiles import KnownProfiles, ProfileDefinition |
16 | | -from azure.profiles.multiapiclient import MultiApiClientMixin |
| 16 | +from azure.mgmt.core.policies import ARMAutoResourceProviderRegistrationPolicy |
17 | 17 |
|
| 18 | +from . import models as _models |
18 | 19 | from ._configuration import CustomLocationsConfiguration |
19 | 20 | from ._serialization import Deserializer, Serializer |
| 21 | +from .operations import CustomLocationsOperations, ResourceSyncRulesOperations |
20 | 22 |
|
21 | 23 | if TYPE_CHECKING: |
22 | 24 | # pylint: disable=unused-import,ungrouped-imports |
23 | 25 | from azure.core.credentials import TokenCredential |
24 | 26 |
|
25 | | -class _SDKClient(object): |
26 | | - def __init__(self, *args, **kwargs): |
27 | | - """This is a fake class to support current implemetation of MultiApiClientMixin." |
28 | | - Will be removed in final version of multiapi azure-core based client |
29 | | - """ |
30 | | - pass |
31 | 27 |
|
32 | | -class CustomLocations(MultiApiClientMixin, _SDKClient): |
| 28 | +class CustomLocations: # pylint: disable=client-accepts-api-version-keyword |
33 | 29 | """The customLocations Rest API spec. |
34 | 30 |
|
35 | | - This ready contains multiple API versions, to help you deal with all of the Azure clouds |
36 | | - (Azure Stack, Azure Government, Azure China, etc.). |
37 | | - By default, it uses the latest API version available on public Azure. |
38 | | - For production, you should stick to a particular api-version and/or profile. |
39 | | - The profile sets a mapping between an operation group and its API version. |
40 | | - The api-version parameter sets the default API version if the operation |
41 | | - group is not described in the profile. |
42 | | -
|
| 31 | + :ivar custom_locations: CustomLocationsOperations operations |
| 32 | + :vartype custom_locations: azure.mgmt.extendedlocation.operations.CustomLocationsOperations |
| 33 | + :ivar resource_sync_rules: ResourceSyncRulesOperations operations |
| 34 | + :vartype resource_sync_rules: |
| 35 | + azure.mgmt.extendedlocation.operations.ResourceSyncRulesOperations |
43 | 36 | :param credential: Credential needed for the client to connect to Azure. Required. |
44 | 37 | :type credential: ~azure.core.credentials.TokenCredential |
45 | 38 | :param subscription_id: The ID of the target subscription. Required. |
46 | 39 | :type subscription_id: str |
47 | | - :param api_version: API version to use if no profile is provided, or if missing in profile. |
48 | | - :type api_version: str |
49 | | - :param base_url: Service URL |
| 40 | + :param base_url: Service URL. Default value is "https://management.azure.com". |
50 | 41 | :type base_url: str |
51 | | - :param profile: A profile definition, from KnownProfiles to dict. |
52 | | - :type profile: azure.profiles.KnownProfiles |
53 | | - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. |
| 42 | + :keyword api_version: Api Version. Default value is "2021-08-31-preview". Note that overriding |
| 43 | + this default value may result in unsupported behavior. |
| 44 | + :paramtype api_version: str |
| 45 | + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no |
| 46 | + Retry-After header is present. |
54 | 47 | """ |
55 | 48 |
|
56 | | - DEFAULT_API_VERSION = '2021-08-15' |
57 | | - _PROFILE_TAG = "azure.mgmt.extendedlocation.CustomLocations" |
58 | | - LATEST_PROFILE = ProfileDefinition({ |
59 | | - _PROFILE_TAG: { |
60 | | - None: DEFAULT_API_VERSION, |
61 | | - }}, |
62 | | - _PROFILE_TAG + " latest" |
63 | | - ) |
64 | | - |
65 | 49 | def __init__( |
66 | 50 | self, |
67 | 51 | credential: "TokenCredential", |
68 | 52 | subscription_id: str, |
69 | | - api_version: Optional[str]=None, |
70 | 53 | base_url: str = "https://management.azure.com", |
71 | | - profile: KnownProfiles=KnownProfiles.default, |
72 | 54 | **kwargs: Any |
73 | | - ): |
74 | | - self._config = CustomLocationsConfiguration(credential, subscription_id, **kwargs) |
75 | | - self._client = ARMPipelineClient(base_url=base_url, config=self._config, **kwargs) |
76 | | - super(CustomLocations, self).__init__( |
77 | | - api_version=api_version, |
78 | | - profile=profile |
| 55 | + ) -> None: |
| 56 | + self._config = CustomLocationsConfiguration(credential=credential, subscription_id=subscription_id, **kwargs) |
| 57 | + _policies = kwargs.pop("policies", None) |
| 58 | + if _policies is None: |
| 59 | + _policies = [ |
| 60 | + policies.RequestIdPolicy(**kwargs), |
| 61 | + self._config.headers_policy, |
| 62 | + self._config.user_agent_policy, |
| 63 | + self._config.proxy_policy, |
| 64 | + policies.ContentDecodePolicy(**kwargs), |
| 65 | + ARMAutoResourceProviderRegistrationPolicy(), |
| 66 | + self._config.redirect_policy, |
| 67 | + self._config.retry_policy, |
| 68 | + self._config.authentication_policy, |
| 69 | + self._config.custom_hook_policy, |
| 70 | + self._config.logging_policy, |
| 71 | + policies.DistributedTracingPolicy(**kwargs), |
| 72 | + policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None, |
| 73 | + self._config.http_logging_policy, |
| 74 | + ] |
| 75 | + self._client: ARMPipelineClient = ARMPipelineClient(base_url=base_url, policies=_policies, **kwargs) |
| 76 | + |
| 77 | + client_models = {k: v for k, v in _models.__dict__.items() if isinstance(v, type)} |
| 78 | + self._serialize = Serializer(client_models) |
| 79 | + self._deserialize = Deserializer(client_models) |
| 80 | + self._serialize.client_side_validation = False |
| 81 | + self.custom_locations = CustomLocationsOperations( |
| 82 | + self._client, self._config, self._serialize, self._deserialize |
| 83 | + ) |
| 84 | + self.resource_sync_rules = ResourceSyncRulesOperations( |
| 85 | + self._client, self._config, self._serialize, self._deserialize |
79 | 86 | ) |
80 | 87 |
|
81 | | - @classmethod |
82 | | - def _models_dict(cls, api_version): |
83 | | - return {k: v for k, v in cls.models(api_version).__dict__.items() if isinstance(v, type)} |
| 88 | + def _send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse: |
| 89 | + """Runs the network request through the client's chained policies. |
84 | 90 |
|
85 | | - @classmethod |
86 | | - def models(cls, api_version=DEFAULT_API_VERSION): |
87 | | - """Module depends on the API version: |
| 91 | + >>> from azure.core.rest import HttpRequest |
| 92 | + >>> request = HttpRequest("GET", "https://www.example.org/") |
| 93 | + <HttpRequest [GET], url: 'https://www.example.org/'> |
| 94 | + >>> response = client._send_request(request) |
| 95 | + <HttpResponse: 200 OK> |
88 | 96 |
|
89 | | - * 2021-03-15-preview: :mod:`v2021_03_15_preview.models<azure.mgmt.extendedlocation.v2021_03_15_preview.models>` |
90 | | - * 2021-08-15: :mod:`v2021_08_15.models<azure.mgmt.extendedlocation.v2021_08_15.models>` |
91 | | - * 2021-08-31-preview: :mod:`v2021_08_31_preview.models<azure.mgmt.extendedlocation.v2021_08_31_preview.models>` |
92 | | - """ |
93 | | - if api_version == '2021-03-15-preview': |
94 | | - from .v2021_03_15_preview import models |
95 | | - return models |
96 | | - elif api_version == '2021-08-15': |
97 | | - from .v2021_08_15 import models |
98 | | - return models |
99 | | - elif api_version == '2021-08-31-preview': |
100 | | - from .v2021_08_31_preview import models |
101 | | - return models |
102 | | - raise ValueError("API version {} is not available".format(api_version)) |
103 | | - |
104 | | - @property |
105 | | - def custom_locations(self): |
106 | | - """Instance depends on the API version: |
107 | | -
|
108 | | - * 2021-03-15-preview: :class:`CustomLocationsOperations<azure.mgmt.extendedlocation.v2021_03_15_preview.operations.CustomLocationsOperations>` |
109 | | - * 2021-08-15: :class:`CustomLocationsOperations<azure.mgmt.extendedlocation.v2021_08_15.operations.CustomLocationsOperations>` |
110 | | - * 2021-08-31-preview: :class:`CustomLocationsOperations<azure.mgmt.extendedlocation.v2021_08_31_preview.operations.CustomLocationsOperations>` |
111 | | - """ |
112 | | - api_version = self._get_api_version('custom_locations') |
113 | | - if api_version == '2021-03-15-preview': |
114 | | - from .v2021_03_15_preview.operations import CustomLocationsOperations as OperationClass |
115 | | - elif api_version == '2021-08-15': |
116 | | - from .v2021_08_15.operations import CustomLocationsOperations as OperationClass |
117 | | - elif api_version == '2021-08-31-preview': |
118 | | - from .v2021_08_31_preview.operations import CustomLocationsOperations as OperationClass |
119 | | - else: |
120 | | - raise ValueError("API version {} does not have operation group 'custom_locations'".format(api_version)) |
121 | | - self._config.api_version = api_version |
122 | | - return OperationClass(self._client, self._config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version))) |
123 | | - |
124 | | - @property |
125 | | - def resource_sync_rules(self): |
126 | | - """Instance depends on the API version: |
127 | | -
|
128 | | - * 2021-08-31-preview: :class:`ResourceSyncRulesOperations<azure.mgmt.extendedlocation.v2021_08_31_preview.operations.ResourceSyncRulesOperations>` |
| 97 | + For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request |
| 98 | +
|
| 99 | + :param request: The network request you want to make. Required. |
| 100 | + :type request: ~azure.core.rest.HttpRequest |
| 101 | + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. |
| 102 | + :return: The response of your network call. Does not do error handling on your response. |
| 103 | + :rtype: ~azure.core.rest.HttpResponse |
129 | 104 | """ |
130 | | - api_version = self._get_api_version('resource_sync_rules') |
131 | | - if api_version == '2021-08-31-preview': |
132 | | - from .v2021_08_31_preview.operations import ResourceSyncRulesOperations as OperationClass |
133 | | - else: |
134 | | - raise ValueError("API version {} does not have operation group 'resource_sync_rules'".format(api_version)) |
135 | | - self._config.api_version = api_version |
136 | | - return OperationClass(self._client, self._config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version))) |
137 | | - |
138 | | - def close(self): |
| 105 | + |
| 106 | + request_copy = deepcopy(request) |
| 107 | + request_copy.url = self._client.format_url(request_copy.url) |
| 108 | + return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore |
| 109 | + |
| 110 | + def close(self) -> None: |
139 | 111 | self._client.close() |
140 | | - def __enter__(self): |
| 112 | + |
| 113 | + def __enter__(self) -> Self: |
141 | 114 | self._client.__enter__() |
142 | 115 | return self |
143 | | - def __exit__(self, *exc_details): |
| 116 | + |
| 117 | + def __exit__(self, *exc_details: Any) -> None: |
144 | 118 | self._client.__exit__(*exc_details) |
0 commit comments