Created
January 22, 2021 16:45
-
-
Save minherz/66d7a4b7325d5e618d26259e8217a258 to your computer and use it in GitHub Desktop.
set GCE instance labels using Google client library in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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