|
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, Optional, TYPE_CHECKING |
10 | 11 |
|
11 | 12 | from azure.core import PipelineClient |
| 13 | +from azure.core.rest import HttpRequest, HttpResponse |
12 | 14 | from msrest import Deserializer, Serializer |
13 | 15 |
|
| 16 | +from ._configuration import DeviceUpdateClientConfiguration |
| 17 | +from .operations import DeviceManagementOperations, DeviceUpdateOperations |
| 18 | + |
14 | 19 | if TYPE_CHECKING: |
15 | 20 | # pylint: disable=unused-import,ungrouped-imports |
16 | | - from typing import Any |
| 21 | + from typing import Dict |
17 | 22 |
|
18 | 23 | from azure.core.credentials import TokenCredential |
19 | | - from azure.core.pipeline.transport import HttpRequest, HttpResponse |
20 | | - |
21 | | -from ._configuration import DeviceUpdateClientConfiguration |
22 | | -from .operations import UpdatesOperations |
23 | | -from .operations import DevicesOperations |
24 | | -from .operations import DeploymentsOperations |
25 | | -from . import models |
26 | 24 |
|
27 | | - |
28 | | -class DeviceUpdateClient(object): |
| 25 | +class DeviceUpdateClient: |
29 | 26 | """Device Update for IoT Hub is an Azure service that enables customers to publish update for their IoT devices to the cloud, and then deploy that update to their devices (approve updates to groups of devices managed and provisioned in IoT Hub). It leverages the proven security and reliability of the Windows Update platform, optimized for IoT devices. It works globally and knows when and how to update devices, enabling customers to focus on their business goals and let Device Update for IoT Hub handle the updates. |
30 | 27 |
|
31 | | - :ivar updates: UpdatesOperations operations |
32 | | - :vartype updates: azure.iot.deviceupdate.operations.UpdatesOperations |
33 | | - :ivar devices: DevicesOperations operations |
34 | | - :vartype devices: azure.iot.deviceupdate.operations.DevicesOperations |
35 | | - :ivar deployments: DeploymentsOperations operations |
36 | | - :vartype deployments: azure.iot.deviceupdate.operations.DeploymentsOperations |
37 | | - :param credential: Credential needed for the client to connect to Azure. |
38 | | - :type credential: ~azure.core.credentials.TokenCredential |
39 | | - :param account_endpoint: Account endpoint. |
40 | | - :type account_endpoint: str |
| 28 | + :ivar device_update: DeviceUpdateOperations operations |
| 29 | + :vartype device_update: azure.iot.deviceupdate.operations.DeviceUpdateOperations |
| 30 | + :ivar device_management: DeviceManagementOperations operations |
| 31 | + :vartype device_management: azure.iot.deviceupdate.operations.DeviceManagementOperations |
| 32 | + :param endpoint: Account endpoint. |
| 33 | + :type endpoint: str |
41 | 34 | :param instance_id: Account instance identifier. |
42 | 35 | :type instance_id: str |
| 36 | + :param credential: Credential needed for the client to connect to Azure. |
| 37 | + :type credential: ~azure.core.credentials.TokenCredential |
| 38 | + :keyword api_version: Api Version. The default value is "2021-06-01-preview". Note that |
| 39 | + overriding this default value may result in unsupported behavior. |
| 40 | + :paramtype api_version: str |
| 41 | + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no |
| 42 | + Retry-After header is present. |
43 | 43 | """ |
44 | 44 |
|
45 | 45 | def __init__( |
46 | 46 | self, |
47 | | - credential, # type: "TokenCredential" |
48 | | - account_endpoint, # type: str |
49 | | - instance_id, # type: str |
50 | | - **kwargs # type: Any |
51 | | - ): |
52 | | - # type: (...) -> None |
53 | | - base_url = 'https://{accountEndpoint}' |
54 | | - self._config = DeviceUpdateClientConfiguration(credential, account_endpoint, instance_id, **kwargs) |
55 | | - self._client = PipelineClient(base_url=base_url, config=self._config, **kwargs) |
56 | | - |
57 | | - client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} |
58 | | - self._serialize = Serializer(client_models) |
| 47 | + endpoint: str, |
| 48 | + instance_id: str, |
| 49 | + credential: "TokenCredential", |
| 50 | + **kwargs: Any |
| 51 | + ) -> None: |
| 52 | + _endpoint = 'https://{endpoint}' |
| 53 | + self._config = DeviceUpdateClientConfiguration(endpoint=endpoint, instance_id=instance_id, credential=credential, **kwargs) |
| 54 | + self._client = PipelineClient(base_url=_endpoint, config=self._config, **kwargs) |
| 55 | + |
| 56 | + self._serialize = Serializer() |
| 57 | + self._deserialize = Deserializer() |
59 | 58 | self._serialize.client_side_validation = False |
60 | | - self._deserialize = Deserializer(client_models) |
| 59 | + self.device_update = DeviceUpdateOperations(self._client, self._config, self._serialize, self._deserialize) |
| 60 | + self.device_management = DeviceManagementOperations(self._client, self._config, self._serialize, self._deserialize) |
61 | 61 |
|
62 | | - self.updates = UpdatesOperations( |
63 | | - self._client, self._config, self._serialize, self._deserialize) |
64 | | - self.devices = DevicesOperations( |
65 | | - self._client, self._config, self._serialize, self._deserialize) |
66 | | - self.deployments = DeploymentsOperations( |
67 | | - self._client, self._config, self._serialize, self._deserialize) |
68 | 62 |
|
69 | | - def _send_request(self, http_request, **kwargs): |
70 | | - # type: (HttpRequest, Any) -> HttpResponse |
| 63 | + def send_request( |
| 64 | + self, |
| 65 | + request, # type: HttpRequest |
| 66 | + **kwargs: Any |
| 67 | + ) -> HttpResponse: |
71 | 68 | """Runs the network request through the client's chained policies. |
72 | 69 |
|
73 | | - :param http_request: The network request you want to make. Required. |
74 | | - :type http_request: ~azure.core.pipeline.transport.HttpRequest |
75 | | - :keyword bool stream: Whether the response payload will be streamed. Defaults to True. |
| 70 | + >>> from azure.core.rest import HttpRequest |
| 71 | + >>> request = HttpRequest("GET", "https://www.example.org/") |
| 72 | + <HttpRequest [GET], url: 'https://www.example.org/'> |
| 73 | + >>> response = client.send_request(request) |
| 74 | + <HttpResponse: 200 OK> |
| 75 | +
|
| 76 | + For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart |
| 77 | +
|
| 78 | + :param request: The network request you want to make. Required. |
| 79 | + :type request: ~azure.core.rest.HttpRequest |
| 80 | + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. |
76 | 81 | :return: The response of your network call. Does not do error handling on your response. |
77 | | - :rtype: ~azure.core.pipeline.transport.HttpResponse |
| 82 | + :rtype: ~azure.core.rest.HttpResponse |
78 | 83 | """ |
| 84 | + |
| 85 | + request_copy = deepcopy(request) |
79 | 86 | path_format_arguments = { |
80 | | - 'accountEndpoint': self._serialize.url("self._config.account_endpoint", self._config.account_endpoint, 'str', skip_quote=True), |
81 | | - 'instanceId': self._serialize.url("self._config.instance_id", self._config.instance_id, 'str', skip_quote=True), |
| 87 | + "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True), |
82 | 88 | } |
83 | | - http_request.url = self._client.format_url(http_request.url, **path_format_arguments) |
84 | | - stream = kwargs.pop("stream", True) |
85 | | - pipeline_response = self._client._pipeline.run(http_request, stream=stream, **kwargs) |
86 | | - return pipeline_response.http_response |
| 89 | + |
| 90 | + request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments) |
| 91 | + return self._client.send_request(request_copy, **kwargs) |
87 | 92 |
|
88 | 93 | def close(self): |
89 | 94 | # type: () -> None |
|
0 commit comments