Skip to content

Instantly share code, notes, and snippets.

@minherz
Created January 22, 2021 16:45
Show Gist options
  • Save minherz/66d7a4b7325d5e618d26259e8217a258 to your computer and use it in GitHub Desktop.
Save minherz/66d7a4b7325d5e618d26259e8217a258 to your computer and use it in GitHub Desktop.
set GCE instance labels using Google client library in Python
resp = compute.instances().get(project=project_id, zone=zone, instance=instance_name).execute()
if 'error' in resp:
print('Failed to get GCE instance info')
exit(1)
fingerprint = resp['labelFingerprint']
resp = compute.instances().setLabels(project=project_id, zone=zone, instance=instance_name,
body={'labelFingerprint': fingerprint,
'labels': labels}).execute()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment