|
6 | 6 | # Changes may cause incorrect behavior and will be lost if the code is regenerated. |
7 | 7 | # -------------------------------------------------------------------------- |
8 | 8 |
|
9 | | -from typing import TYPE_CHECKING |
| 9 | +from copy import deepcopy |
| 10 | +from typing import Any, TYPE_CHECKING |
10 | 11 |
|
11 | | -from azure.mgmt.core import ARMPipelineClient |
12 | 12 | from msrest import Deserializer, Serializer |
13 | 13 |
|
14 | | -if TYPE_CHECKING: |
15 | | - # pylint: disable=unused-import,ungrouped-imports |
16 | | - from typing import Any, Optional |
17 | | - |
18 | | - from azure.core.credentials import TokenCredential |
19 | | - from azure.core.pipeline.transport import HttpRequest, HttpResponse |
| 14 | +from azure.core.rest import HttpRequest, HttpResponse |
| 15 | +from azure.mgmt.core import ARMPipelineClient |
20 | 16 |
|
21 | | -from ._configuration import ImageBuilderClientConfiguration |
22 | | -from .operations import VirtualMachineImageTemplatesOperations |
23 | | -from .operations import Operations |
24 | 17 | from . import models |
| 18 | +from ._configuration import ImageBuilderClientConfiguration |
| 19 | +from .operations import Operations, VirtualMachineImageTemplatesOperations |
25 | 20 |
|
| 21 | +if TYPE_CHECKING: |
| 22 | + # pylint: disable=unused-import,ungrouped-imports |
| 23 | + from azure.core.credentials import TokenCredential |
26 | 24 |
|
27 | | -class ImageBuilderClient(object): |
| 25 | +class ImageBuilderClient: |
28 | 26 | """Azure Virtual Machine Image Builder Client. |
29 | 27 |
|
30 | 28 | :ivar virtual_machine_image_templates: VirtualMachineImageTemplatesOperations operations |
31 | | - :vartype virtual_machine_image_templates: azure.mgmt.imagebuilder.operations.VirtualMachineImageTemplatesOperations |
| 29 | + :vartype virtual_machine_image_templates: |
| 30 | + azure.mgmt.imagebuilder.operations.VirtualMachineImageTemplatesOperations |
32 | 31 | :ivar operations: Operations operations |
33 | 32 | :vartype operations: azure.mgmt.imagebuilder.operations.Operations |
34 | 33 | :param credential: Credential needed for the client to connect to Azure. |
35 | 34 | :type credential: ~azure.core.credentials.TokenCredential |
36 | | - :param subscription_id: Subscription credentials which uniquely identify Microsoft Azure subscription. The subscription Id forms part of the URI for every service call. |
| 35 | + :param subscription_id: Subscription credentials which uniquely identify Microsoft Azure |
| 36 | + subscription. The subscription Id forms part of the URI for every service call. |
37 | 37 | :type subscription_id: str |
38 | | - :param str base_url: Service URL |
39 | | - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. |
| 38 | + :param base_url: Service URL. Default value is "https://management.azure.com". |
| 39 | + :type base_url: str |
| 40 | + :keyword api_version: Api Version. Default value is "2022-02-14". Note that overriding this |
| 41 | + default value may result in unsupported behavior. |
| 42 | + :paramtype api_version: str |
| 43 | + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no |
| 44 | + Retry-After header is present. |
40 | 45 | """ |
41 | 46 |
|
42 | 47 | def __init__( |
43 | 48 | self, |
44 | | - credential, # type: "TokenCredential" |
45 | | - subscription_id, # type: str |
46 | | - base_url=None, # type: Optional[str] |
47 | | - **kwargs # type: Any |
48 | | - ): |
49 | | - # type: (...) -> None |
50 | | - if not base_url: |
51 | | - base_url = 'https://management.azure.com' |
52 | | - self._config = ImageBuilderClientConfiguration(credential, subscription_id, **kwargs) |
| 49 | + credential: "TokenCredential", |
| 50 | + subscription_id: str, |
| 51 | + base_url: str = "https://management.azure.com", |
| 52 | + **kwargs: Any |
| 53 | + ) -> None: |
| 54 | + self._config = ImageBuilderClientConfiguration(credential=credential, subscription_id=subscription_id, **kwargs) |
53 | 55 | self._client = ARMPipelineClient(base_url=base_url, config=self._config, **kwargs) |
54 | 56 |
|
55 | 57 | client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} |
56 | 58 | self._serialize = Serializer(client_models) |
57 | | - self._serialize.client_side_validation = False |
58 | 59 | self._deserialize = Deserializer(client_models) |
| 60 | + self._serialize.client_side_validation = False |
| 61 | + self.virtual_machine_image_templates = VirtualMachineImageTemplatesOperations(self._client, self._config, self._serialize, self._deserialize) |
| 62 | + self.operations = Operations(self._client, self._config, self._serialize, self._deserialize) |
59 | 63 |
|
60 | | - self.virtual_machine_image_templates = VirtualMachineImageTemplatesOperations( |
61 | | - self._client, self._config, self._serialize, self._deserialize) |
62 | | - self.operations = Operations( |
63 | | - self._client, self._config, self._serialize, self._deserialize) |
64 | 64 |
|
65 | | - def _send_request(self, http_request, **kwargs): |
66 | | - # type: (HttpRequest, Any) -> HttpResponse |
| 65 | + def _send_request( |
| 66 | + self, |
| 67 | + request: HttpRequest, |
| 68 | + **kwargs: Any |
| 69 | + ) -> HttpResponse: |
67 | 70 | """Runs the network request through the client's chained policies. |
68 | 71 |
|
69 | | - :param http_request: The network request you want to make. Required. |
70 | | - :type http_request: ~azure.core.pipeline.transport.HttpRequest |
71 | | - :keyword bool stream: Whether the response payload will be streamed. Defaults to True. |
| 72 | + >>> from azure.core.rest import HttpRequest |
| 73 | + >>> request = HttpRequest("GET", "https://www.example.org/") |
| 74 | + <HttpRequest [GET], url: 'https://www.example.org/'> |
| 75 | + >>> response = client._send_request(request) |
| 76 | + <HttpResponse: 200 OK> |
| 77 | +
|
| 78 | + For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart |
| 79 | +
|
| 80 | + :param request: The network request you want to make. Required. |
| 81 | + :type request: ~azure.core.rest.HttpRequest |
| 82 | + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. |
72 | 83 | :return: The response of your network call. Does not do error handling on your response. |
73 | | - :rtype: ~azure.core.pipeline.transport.HttpResponse |
| 84 | + :rtype: ~azure.core.rest.HttpResponse |
74 | 85 | """ |
75 | | - path_format_arguments = { |
76 | | - 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), |
77 | | - } |
78 | | - http_request.url = self._client.format_url(http_request.url, **path_format_arguments) |
79 | | - stream = kwargs.pop("stream", True) |
80 | | - pipeline_response = self._client._pipeline.run(http_request, stream=stream, **kwargs) |
81 | | - return pipeline_response.http_response |
| 86 | + |
| 87 | + request_copy = deepcopy(request) |
| 88 | + request_copy.url = self._client.format_url(request_copy.url) |
| 89 | + return self._client.send_request(request_copy, **kwargs) |
82 | 90 |
|
83 | 91 | def close(self): |
84 | 92 | # type: () -> None |
|
0 commit comments