|
6 | 6 |
|
7 | 7 | Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize |
8 | 8 | """ |
9 | | - |
10 | 9 | from typing import List |
11 | | -from typing import Any, Dict, IO, Optional, Union, cast, Callable, TypeVar, Tuple |
12 | | -import urllib.parse |
13 | | - |
14 | | -from azure.core.pipeline import PipelineResponse |
15 | | -from azure.core.pipeline.transport import HttpResponse |
16 | | -from azure.core.polling import LROPoller, NoPolling, PollingMethod |
17 | | -from azure.core.rest import HttpRequest |
18 | | -from azure.core.tracing.decorator import distributed_trace |
19 | | -from azure.core.utils import case_insensitive_dict |
20 | | -from azure.mgmt.core.polling.arm_polling import ARMPolling |
21 | | - |
22 | | -from .. import models as _models |
23 | | -from ._sap_virtual_instances_operations import SAPVirtualInstancesOperations as SAPVirtualInstancesOperationsGen |
24 | | - |
25 | | -T = TypeVar("T") |
26 | | -ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] |
27 | | - |
28 | | -def is_rest(obj: object) -> bool: |
29 | | - """Return whether a request or a response is a rest request / response. |
30 | | -
|
31 | | - Checking whether the response has the object content can sometimes result |
32 | | - in a ResponseNotRead error if you're checking the value on a response |
33 | | - that has not been read in yet. To get around this, we also have added |
34 | | - a check for is_stream_consumed, which is an exclusive property on our new responses. |
35 | | -
|
36 | | - :param obj: The object to check. |
37 | | - :type obj: any |
38 | | - :rtype: bool |
39 | | - :return: Whether the object is a rest request / response. |
40 | | - """ |
41 | | - return hasattr(obj, "is_stream_consumed") or hasattr(obj, "content") |
42 | | - |
43 | | -def update_api_version_of_status_link( |
44 | | - status_link: str, api_version: Optional[str] = None |
45 | | -) -> Tuple[str, Dict[str, Any]]: |
46 | | - """Handle status link. |
47 | | -
|
48 | | - :param status_link: Lro status link. |
49 | | - :type status_link: str |
50 | | - :param api_version: api version. |
51 | | - :type api_version: str or None |
52 | | - :return: Parsed status link and parsed query parameters. |
53 | | - :rtype: Tuple[str, Dict[str, Any]] |
54 | | - """ |
55 | | - request_params: Dict[str, Any] = {} |
56 | | - if api_version is not None: |
57 | | - parsed_status_link = urllib.parse.urlparse(status_link) |
58 | | - request_params = { |
59 | | - key: [urllib.parse.quote(v) for v in value] |
60 | | - for key, value in urllib.parse.parse_qs(parsed_status_link.query).items() |
61 | | - } |
62 | | - add_api_version = True |
63 | | - for k in request_params.keys(): |
64 | | - if k.lower() == "api-version": |
65 | | - request_params[k] = api_version |
66 | | - add_api_version = False |
67 | | - break |
68 | | - if add_api_version: |
69 | | - request_params["api-version"] = api_version |
70 | | - status_link = urllib.parse.urljoin(status_link, parsed_status_link.path) |
71 | | - return status_link, request_params |
72 | | - |
73 | | -class PatchArmPolling(ARMPolling): |
74 | | - |
75 | | - def request_status(self, status_link: str): |
76 | | - """Do a simple GET to this status link. |
77 | | -
|
78 | | - This method re-inject 'x-ms-client-request-id'. |
79 | | -
|
80 | | - :param str status_link: The URL to poll. |
81 | | - :rtype: azure.core.pipeline.PipelineResponse |
82 | | - :return: The response of the status request. |
83 | | - """ |
84 | | - if self._path_format_arguments: |
85 | | - status_link = self._client.format_url(status_link, **self._path_format_arguments) |
86 | | - status_link, request_params = update_api_version_of_status_link( |
87 | | - status_link, (self._lro_options or {}).get("api_version") |
88 | | - ) |
89 | | - # Re-inject 'x-ms-client-request-id' while polling |
90 | | - if "request_id" not in self._operation_config: |
91 | | - self._operation_config["request_id"] = self._get_request_id() |
92 | | - |
93 | | - if is_rest(self._initial_response.http_response): |
94 | | - rest_request = HttpRequest("GET", status_link, params=request_params) |
95 | | - # Need a cast, as "_return_pipeline_response" mutate the return type, and that return type is not |
96 | | - # declared in the typing of "send_request" |
97 | | - return self._client.send_request(rest_request, _return_pipeline_response=True, **self._operation_config) |
98 | | - |
99 | | - # Legacy HttpRequest and HttpResponse from azure.core.pipeline.transport |
100 | | - # casting things here, as we don't want the typing system to know |
101 | | - # about the legacy APIs. |
102 | | - request = self._client.get(status_link, params=request_params) |
103 | | - return self._client._pipeline.run( # pylint: disable=protected-access |
104 | | - request, stream=False, **self._operation_config |
105 | | - ) |
106 | | - |
107 | | -class SAPVirtualInstancesOperations(SAPVirtualInstancesOperationsGen): |
108 | | - """ |
109 | | - .. warning:: |
110 | | - **DO NOT** instantiate this class directly. |
111 | | -
|
112 | | - Instead, you should access the following operations through |
113 | | - :class:`~azure.mgmt.workloadssapvirtualinstance.WorkloadsSapVirtualInstanceMgmtClient`'s |
114 | | - :attr:`sap_virtual_instances` attribute. |
115 | | - """ |
116 | | - |
117 | | - @distributed_trace |
118 | | - def begin_create( |
119 | | - self, |
120 | | - resource_group_name: str, |
121 | | - sap_virtual_instance_name: str, |
122 | | - body: Optional[Union[_models.SAPVirtualInstance, IO]] = None, |
123 | | - **kwargs: Any |
124 | | - ) -> LROPoller[_models.SAPVirtualInstance]: |
125 | | - """Creates a Virtual Instance for SAP solutions (VIS) resource. |
126 | | -
|
127 | | - :param resource_group_name: The name of the resource group. The name is case insensitive. |
128 | | - Required. |
129 | | - :type resource_group_name: str |
130 | | - :param sap_virtual_instance_name: The name of the Virtual Instances for SAP solutions resource. |
131 | | - Required. |
132 | | - :type sap_virtual_instance_name: str |
133 | | - :param body: Virtual Instance for SAP solutions resource request body. Is either a |
134 | | - SAPVirtualInstance type or a IO type. Default value is None. |
135 | | - :type body: ~azure.mgmt.workloadssapvirtualinstance.models.SAPVirtualInstance or IO |
136 | | - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. |
137 | | - Default value is None. |
138 | | - :paramtype content_type: str |
139 | | - :keyword callable cls: A custom type or function that will be passed the direct response |
140 | | - :keyword str continuation_token: A continuation token to restart a poller from a saved state. |
141 | | - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this |
142 | | - operation to not poll, or pass in your own initialized polling object for a personal polling |
143 | | - strategy. |
144 | | - :paramtype polling: bool or ~azure.core.polling.PollingMethod |
145 | | - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no |
146 | | - Retry-After header is present. |
147 | | - :return: An instance of LROPoller that returns either SAPVirtualInstance or the result of |
148 | | - cls(response) |
149 | | - :rtype: |
150 | | - ~azure.core.polling.LROPoller[~azure.mgmt.workloadssapvirtualinstance.models.SAPVirtualInstance] |
151 | | - :raises ~azure.core.exceptions.HttpResponseError: |
152 | | - """ |
153 | | - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) |
154 | | - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) |
155 | | - |
156 | | - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) |
157 | | - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) |
158 | | - cls: ClsType[_models.SAPVirtualInstance] = kwargs.pop("cls", None) |
159 | | - polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) |
160 | | - lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) |
161 | | - cont_token: Optional[str] = kwargs.pop("continuation_token", None) |
162 | | - if cont_token is None: |
163 | | - raw_result = self._create_initial( |
164 | | - resource_group_name=resource_group_name, |
165 | | - sap_virtual_instance_name=sap_virtual_instance_name, |
166 | | - body=body, |
167 | | - api_version=api_version, |
168 | | - content_type=content_type, |
169 | | - cls=lambda x, y, z: x, |
170 | | - headers=_headers, |
171 | | - params=_params, |
172 | | - **kwargs |
173 | | - ) |
174 | | - kwargs.pop("error_map", None) |
175 | | - |
176 | | - def get_long_running_output(pipeline_response): |
177 | | - deserialized = self._deserialize("SAPVirtualInstance", pipeline_response) |
178 | | - if cls: |
179 | | - return cls(pipeline_response, deserialized, {}) |
180 | | - return deserialized |
181 | | - |
182 | | - if polling is True: |
183 | | - polling_method: PollingMethod = cast( |
184 | | - PollingMethod, PatchArmPolling(lro_delay, lro_options={"final-state-via": "location", "api_version": api_version}, **kwargs) |
185 | | - ) |
186 | | - elif polling is False: |
187 | | - polling_method = cast(PollingMethod, NoPolling()) |
188 | | - else: |
189 | | - polling_method = polling |
190 | | - if cont_token: |
191 | | - return LROPoller.from_continuation_token( |
192 | | - polling_method=polling_method, |
193 | | - continuation_token=cont_token, |
194 | | - client=self._client, |
195 | | - deserialization_callback=get_long_running_output, |
196 | | - ) |
197 | | - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore |
198 | | - |
199 | | - begin_create.metadata = { |
200 | | - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Workloads/sapVirtualInstances/{sapVirtualInstanceName}" |
201 | | - } |
202 | 10 |
|
203 | | -__all__: List[str] = [ |
204 | | - "SAPVirtualInstancesOperations" |
205 | | -] # Add all objects you want publicly available to users at this package level |
| 11 | +__all__: List[str] = [] # Add all objects you want publicly available to users at this package level |
206 | 12 |
|
207 | 13 |
|
208 | 14 | def patch_sdk(): |
|
0 commit comments