Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2622d2e

Browse filesBrowse files
noerogJon Wayne Parrott
authored andcommitted
Add sample to get config versions for a device. (GoogleCloudPlatform#1310)
1 parent c24e025 commit 2622d2e
Copy full SHA for 2622d2e

File tree

Expand file treeCollapse file tree

1 file changed

+29
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+29
-0
lines changed

‎iot/api-client/manager/manager.py

Copy file name to clipboardExpand all lines: iot/api-client/manager/manager.py
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,29 @@ def set_config(
399399
name=device_path, body=config_body).execute()
400400

401401

402+
def get_config_versions(
403+
service_account_json, project_id, cloud_region, registry_id,
404+
device_id):
405+
"""Lists versions of a device config in descending order (newest first)."""
406+
client = get_client(service_account_json)
407+
registry_name = 'projects/{}/locations/{}/registries/{}'.format(
408+
project_id, cloud_region, registry_id)
409+
410+
device_name = '{}/devices/{}'.format(registry_name, device_id)
411+
devices = client.projects().locations().registries().devices()
412+
configs = devices.configVersions().list(
413+
name=device_name).execute().get(
414+
'deviceConfigs', [])
415+
416+
for config in configs:
417+
print('version: {}\n\tcloudUpdateTime: {}\n\t binaryData: {}'.format(
418+
config.get('version'),
419+
config.get('cloudUpdateTime'),
420+
config.get('binaryData')))
421+
422+
return configs
423+
424+
402425
def parse_command_line_args():
403426
"""Parse command line arguments."""
404427
default_registry = 'cloudiot_device_manager_example_registry_{}'.format(
@@ -469,6 +492,7 @@ def parse_command_line_args():
469492
command.add_parser('patch-es256', help=patch_es256_auth.__doc__)
470493
command.add_parser('patch-rs256', help=patch_rsa256_auth.__doc__)
471494
command.add_parser('set-config', help=patch_rsa256_auth.__doc__)
495+
command.add_parser('get-config-versions', help=get_config_versions.__doc__)
472496

473497
return parser.parse_args()
474498

@@ -571,6 +595,11 @@ def run_command(args):
571595
args.cloud_region, args.registry_id, args.device_id,
572596
args.version, args.config)
573597

598+
elif args.command == 'get-config-versions':
599+
get_device(
600+
args.service_account_json, args.project_id,
601+
args.cloud_region, args.registry_id, args.device_id)
602+
574603

575604
def main():
576605
args = parse_command_line_args()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.