File: Readme.md

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (67 lines) | stat: -rw-r--r-- 2,202 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Enumerate updates using Device Update for IoT Hub client SDK

In this sample we will enumerate updates imported to Device Update for IoT Hub using Python SDK client library.

## Prerequisites

* Python 3.6 or later is required to use this package
* You need an [Azure subscription][https://azure.microsoft.com/free/], and a [Device Update for IoT Hub][https://learn.microsoft.com/azure/iot-hub-device-update/understand-device-update] 
account and instance to use this package.

Set the following environment variables:

- `AZURE_CLIENT_ID`: AAD service principal client id
- `AZURE_TENANT_ID`: AAD tenant id
- `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH`: AAD service principal client secret

- `DEVICEUPDATE_ENDPOINT`: Device Update for IoT Hub hostname
- `DEVICEUPDATE_INSTANCE_ID`: Device Update for IoT Hub instance name
- `DEVICEUPDATE_UPDATE_PROVIDER`: Update provider to retrieve
- `DEVICEUPDATE_UPDATE_NAME`: Update name to retrieve
- `DEVICEUPDATE_UPDATE_VERSION`: Update version to retrieve

## Sample

The sample will enumerate already imported device updates from Device Update for IoT Hub.

### Get update client

First we need to instantiate service client (using environment variables):

``` python
endpoint = os.environ["DEVICEUPDATE_ENDPOINT"]
instance = os.environ["DEVICEUPDATE_INSTANCE_ID"]
client = DeviceUpdateClient(credential=DefaultAzureCredential(), endpoint=endpoint, instance_id=instance)
```

### Enumerate update providers

Let's start by enumerating all update providers:

``` python
response = client.device_update.list_providers()
for item in response:
    print(f"  {item}")
```

### Enumerate update names

Let's enumerate all update names for a given update provider:

``` python
update_provider = os.environ["DEVICEUPDATE_UPDATE_PROVIDER"]
response = client.device_update.list_names(update_provider)
for item in response:
    print(f"  {item}")
```

### Enumerate update versions

Let's enumerate all update version for a given update provider and update name:

``` python
update_name = os.environ["DEVICEUPDATE_UPDATE_NAME"]
response = client.device_update.list_versions(update_provider, update_name)
for item in response:
    print(f"  {item}")
```