Skip to content

Instantly share code, notes, and snippets.

@gguuss
Created July 11, 2018 00:04
Show Gist options
  • Save gguuss/051e9a12d68fc5330fbc010a2e0c2085 to your computer and use it in GitHub Desktop.
Save gguuss/051e9a12d68fc5330fbc010a2e0c2085 to your computer and use it in GitHub Desktop.
def updateConfig(project_id, region, registry_id, device_id, data):
"""Push the data to the given device as configuration."""
config_data_json = json.dumps(data)
body = {
'version_to_update': 0,
'binary_data': base64.b64encode(
config_data_json.encode('utf-8')).decode('ascii')
}
device_name = ('projects/{}/locations/{}/registries/{}/'
'devices/{}'.format(
project_id,
region,
registry_id,
device_id))
request = service.projects().locations().registries().devices(
).modifyCloudToDeviceConfig(name=device_name, body=body)
update_config_mutex.acquire()
try:
request.execute()
except HttpError as e:
print('Error executing ModifyCloudToDeviceConfig: {}'.format(e))
finally:
update_config_mutex.release()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment