Reputation: 25
I am trying to find the Google Cloud Compute Virtual Machine Name, using the gcloud command while logged in to the VM.
Me searching in the documentation didn't yield a result...
Thanks!
Upvotes: 0
Views: 1726
Reputation: 40091
See Metadata service.
Specifically:
curl \
--header "Metadata-Flavor: Google" \
http://metadata.google.internal/computeMetadata/v1/instance/name
The Metadata service is a well-implemented API, you can navigate up-down the tree of resources, for example, dropping the final name
from the above URL, enumerates all the resources under instance
:
curl \
--header "Metadata-Flavor: Google" \
http://metadata.google.internal/computeMetadata/v1/instance/
returns:
attributes/
cpu-platform
description
disks/
guest-attributes/
hostname
id
image
legacy-endpoint-access/
licenses/
machine-type
maintenance-event
name
network-interfaces/
preempted
remaining-cpu-time
scheduling/
service-accounts/
tags
virtual-clock/
zone
You can then pick any of the above, append it to the URL to continue browsing.
The documentation in the link is similarly comprehensive and, in the case of instance metadata, as expected, reflects the response from GET'ing
https://compute.googleapis.com/compute/v1/.../instances/...
i.e.:
https://cloud.google.com/compute/docs/reference/rest/v1/instances/get#response-body
Upvotes: 2