3 ms·
Cool! Instead of doing gcloud compute list disks though, you can directly look at the disks attached to the instance via the metadata server (https://cloud.goog
by boulos 11y ago
Cool! Instead of doing gcloud compute list disks though, you can directly look at the disks attached to the instance via the metadata server (https://cloud.google.com/compute/docs/metadata https://cloud.google.com/compute/docs/metadata) and in the case of setting ZONE just do it with instance/zone.
Disclosure: I work on Compute Engine.
- tpryan 11y agoNice catch! But aren't gcloud calls correct info without having to parse JSON in Bash?
- asamarin 11y agoYes, of course they're correct; however, invoking gcloud is comparatively much slower than just curl'ing against the metadata server (you know, no Python code to interpret in the latter case). With regards to JSON, not sure what you mean, since getting e.g. instance zone from metadata server gives you a plain text string like "projects/<PROJECT_NUMBER>/zones/europe-west1-d". AFAIK, the only way to get JSON-like results is by making recursive requests, such as: $ curl -H 'Metadata-Flavor: Google' "http://metadata/computeMetadata/v1/instance/?recursive=true" And even in that case, you can choose plain text format by appending "alt=text" as query string parameter: $ curl -H 'Metadata-Flavor: Google' "http://metadata/computeMetadata/v1/instance/?recursive=true&alt=text"
- tpryan 11y agoAwesome, thanks for that, I'll dive deeper into Metadata.