Skip to content

Commit

Permalink
Add sample to get config versions for a device. (#1310)
Browse files Browse the repository at this point in the history
  • Loading branch information
noerog authored and Jon Wayne Parrott committed Jan 11, 2018
1 parent c24e025 commit 2622d2e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions iot/api-client/manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,29 @@ def set_config(
name=device_path, body=config_body).execute()


def get_config_versions(
service_account_json, project_id, cloud_region, registry_id,
device_id):
"""Lists versions of a device config in descending order (newest first)."""
client = get_client(service_account_json)
registry_name = 'projects/{}/locations/{}/registries/{}'.format(
project_id, cloud_region, registry_id)

device_name = '{}/devices/{}'.format(registry_name, device_id)
devices = client.projects().locations().registries().devices()
configs = devices.configVersions().list(
name=device_name).execute().get(
'deviceConfigs', [])

for config in configs:
print('version: {}\n\tcloudUpdateTime: {}\n\t binaryData: {}'.format(
config.get('version'),
config.get('cloudUpdateTime'),
config.get('binaryData')))

return configs


def parse_command_line_args():
"""Parse command line arguments."""
default_registry = 'cloudiot_device_manager_example_registry_{}'.format(
Expand Down Expand Up @@ -469,6 +492,7 @@ def parse_command_line_args():
command.add_parser('patch-es256', help=patch_es256_auth.__doc__)
command.add_parser('patch-rs256', help=patch_rsa256_auth.__doc__)
command.add_parser('set-config', help=patch_rsa256_auth.__doc__)
command.add_parser('get-config-versions', help=get_config_versions.__doc__)

return parser.parse_args()

Expand Down Expand Up @@ -571,6 +595,11 @@ def run_command(args):
args.cloud_region, args.registry_id, args.device_id,
args.version, args.config)

elif args.command == 'get-config-versions':
get_device(
args.service_account_json, args.project_id,
args.cloud_region, args.registry_id, args.device_id)


def main():
args = parse_command_line_args()
Expand Down

0 comments on commit 2622d2e

Please sign in to comment.