I want to get Operating System of the GCP VM instance. Currently I see only the image from which the instance was created. Is there a way of getting that? I see there is OS inventory Management which require some metadata to be set on the VM https://cloud.google.com/compute/docs/instances/view-os-details#api.
- Guest attributes:
Key:
enable-guest-attributesValue:True - OS inventory management:
Key:
enable-os-inventoryValue:True
Moreover there is a command gcloud compute instances os-inventory describe VM-NAME to get the OS configs only when VM is in RUNNING state.
I am looking to fetch the OS details via REST API.
Is there an example to refer for this?
I've edited my answer:
As you have mentioned, you can enable metadata and install OS agent.
This will allow you to use command like this:
gcloud compute instances os-inventory describe INSTANCE-NAME | grep 'LongName\|Kernel'example results:
I've also tested this API proposed by Maninder Chhabra:
Both of these methods work with stopped VMs.