Skip to content

Commit c065216

Browse files
udpate patch code (Azure#37806)
Co-authored-by: msyyc <[email protected]>
1 parent 27328e2 commit c065216

File tree

2 files changed

+2
-344
lines changed
  • sdk/workloads/azure-mgmt-workloadssapvirtualinstance/azure/mgmt/workloadssapvirtualinstance

2 files changed

+2
-344
lines changed

sdk/workloads/azure-mgmt-workloadssapvirtualinstance/azure/mgmt/workloadssapvirtualinstance/aio/operations/_patch.py

+1-149
Original file line numberDiff line numberDiff line change
@@ -8,155 +8,7 @@
88
"""
99
from typing import List
1010

11-
from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, cast
12-
13-
from azure.core.pipeline import PipelineResponse
14-
from azure.core.pipeline.transport import AsyncHttpResponse
15-
from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod
16-
from azure.core.rest import HttpRequest
17-
from azure.core.tracing.decorator_async import distributed_trace_async
18-
from azure.core.utils import case_insensitive_dict
19-
from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling
20-
21-
from ... import models as _models
22-
from ._sap_virtual_instances_operations import SAPVirtualInstancesOperations as SAPVirtualInstancesOperationsGen
23-
from ..operations._patch import is_rest, update_api_version_of_status_link
24-
25-
T = TypeVar("T")
26-
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]]
27-
28-
class AsyncPatchArmPolling(AsyncARMPolling):
29-
async def request_status(self, status_link: str):
30-
"""Do a simple GET to this status link.
31-
32-
This method re-inject 'x-ms-client-request-id'.
33-
34-
:param str status_link: URL to poll.
35-
:rtype: azure.core.pipeline.PipelineResponse
36-
:return: The response of the status request.
37-
"""
38-
if self._path_format_arguments:
39-
status_link = self._client.format_url(status_link, **self._path_format_arguments)
40-
status_link, request_params = update_api_version_of_status_link(
41-
status_link, (self._lro_options or {}).get("api_version")
42-
)
43-
# Re-inject 'x-ms-client-request-id' while polling
44-
if "request_id" not in self._operation_config:
45-
self._operation_config["request_id"] = self._get_request_id()
46-
47-
if is_rest(self._initial_response.http_response):
48-
rest_request = HttpRequest("GET", status_link, params=request_params)
49-
# Need a cast, as "_return_pipeline_response" mutate the return type, and that return type is not
50-
# declared in the typing of "send_request"
51-
return await self._client.send_request(rest_request, _return_pipeline_response=True, **self._operation_config)
52-
53-
# Legacy HttpRequest and AsyncHttpResponse from azure.core.pipeline.transport
54-
# casting things here, as we don't want the typing system to know
55-
# about the legacy APIs.
56-
request = self._client.get(status_link, params=request_params)
57-
return await self._client._pipeline.run( # pylint: disable=protected-access
58-
request, stream=False, **self._operation_config
59-
)
60-
61-
class SAPVirtualInstancesOperations(SAPVirtualInstancesOperationsGen):
62-
"""
63-
.. warning::
64-
**DO NOT** instantiate this class directly.
65-
66-
Instead, you should access the following operations through
67-
:class:`~azure.mgmt.workloadssapvirtualinstance.aio.WorkloadsSapVirtualInstanceMgmtClient`'s
68-
:attr:`sap_virtual_instances` attribute.
69-
"""
70-
71-
@distributed_trace_async
72-
async def begin_create(
73-
self,
74-
resource_group_name: str,
75-
sap_virtual_instance_name: str,
76-
body: Optional[Union[_models.SAPVirtualInstance, IO]] = None,
77-
**kwargs: Any
78-
) -> AsyncLROPoller[_models.SAPVirtualInstance]:
79-
"""Creates a Virtual Instance for SAP solutions (VIS) resource.
80-
81-
:param resource_group_name: The name of the resource group. The name is case insensitive.
82-
Required.
83-
:type resource_group_name: str
84-
:param sap_virtual_instance_name: The name of the Virtual Instances for SAP solutions resource.
85-
Required.
86-
:type sap_virtual_instance_name: str
87-
:param body: Virtual Instance for SAP solutions resource request body. Is either a
88-
SAPVirtualInstance type or a IO type. Default value is None.
89-
:type body: ~azure.mgmt.workloadssapvirtualinstance.models.SAPVirtualInstance or IO
90-
:keyword content_type: Body Parameter content-type. Known values are: 'application/json'.
91-
Default value is None.
92-
:paramtype content_type: str
93-
:keyword callable cls: A custom type or function that will be passed the direct response
94-
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
95-
:keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for
96-
this operation to not poll, or pass in your own initialized polling object for a personal
97-
polling strategy.
98-
:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod
99-
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
100-
Retry-After header is present.
101-
:return: An instance of AsyncLROPoller that returns either SAPVirtualInstance or the result of
102-
cls(response)
103-
:rtype:
104-
~azure.core.polling.AsyncLROPoller[~azure.mgmt.workloadssapvirtualinstance.models.SAPVirtualInstance]
105-
:raises ~azure.core.exceptions.HttpResponseError:
106-
"""
107-
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
108-
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})
109-
110-
api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version))
111-
content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
112-
cls: ClsType[_models.SAPVirtualInstance] = kwargs.pop("cls", None)
113-
polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True)
114-
lro_delay = kwargs.pop("polling_interval", self._config.polling_interval)
115-
cont_token: Optional[str] = kwargs.pop("continuation_token", None)
116-
if cont_token is None:
117-
raw_result = await self._create_initial(
118-
resource_group_name=resource_group_name,
119-
sap_virtual_instance_name=sap_virtual_instance_name,
120-
body=body,
121-
api_version=api_version,
122-
content_type=content_type,
123-
cls=lambda x, y, z: x,
124-
headers=_headers,
125-
params=_params,
126-
**kwargs
127-
)
128-
kwargs.pop("error_map", None)
129-
130-
def get_long_running_output(pipeline_response):
131-
deserialized = self._deserialize("SAPVirtualInstance", pipeline_response)
132-
if cls:
133-
return cls(pipeline_response, deserialized, {})
134-
return deserialized
135-
136-
if polling is True:
137-
polling_method: AsyncPollingMethod = cast(
138-
AsyncPollingMethod, AsyncPatchArmPolling(lro_delay, lro_options={"final-state-via": "location", "api_version": api_version}, **kwargs)
139-
)
140-
elif polling is False:
141-
polling_method = cast(AsyncPollingMethod, AsyncNoPolling())
142-
else:
143-
polling_method = polling
144-
if cont_token:
145-
return AsyncLROPoller.from_continuation_token(
146-
polling_method=polling_method,
147-
continuation_token=cont_token,
148-
client=self._client,
149-
deserialization_callback=get_long_running_output,
150-
)
151-
return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore
152-
153-
begin_create.metadata = {
154-
"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Workloads/sapVirtualInstances/{sapVirtualInstanceName}"
155-
}
156-
157-
__all__: List[str] = [
158-
"SAPVirtualInstancesOperations"
159-
] # 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
16012

16113

16214
def patch_sdk():

sdk/workloads/azure-mgmt-workloadssapvirtualinstance/azure/mgmt/workloadssapvirtualinstance/operations/_patch.py

+1-195
Original file line numberDiff line numberDiff line change
@@ -6,203 +6,9 @@
66
77
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
88
"""
9-
109
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-
}
20210

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
20612

20713

20814
def patch_sdk():

0 commit comments

Comments
 (0)