0

How can I get a GCP Instance operating system type?

I need to be able to tell if an instance os type is Linux or Windows using the API / .Net Client SDK.

So far I found answers such as get-guest-attribute: https://cloud.google.com/compute/docs/metadata/manage-guest-attributes

and os-config inventory: https://cloud.google.com/compute/docs/instances/view-os-details

but both require to have options enabled on the instance in advance, whereas in my case I cannot enable any new option/setting/attribute on the instance.

Is there a way to get the instance operating system without enabling any feture in the instance in advance? even if not the full OS Type (like Linux Ubuntu 20.04 or Windows Server 2019) but just a hint (like Linux or Windows)?

shahaf
  • 741
  • 1
  • 8
  • 26
  • os-config is the best one. But you can imagine a script that list the VM, the main disk and get the image name of that disk. From the image name, you can deduce the OS. – guillaume blaquiere May 29 '23 at 18:20
  • 1
    Review the CLI command `gcloud compute instances describe`. That provides a lot of details. Under `disk.licenses` you can figure out the OS type. The SDK provides the same core features as the CLI. The REST API is [here](https://cloud.google.com/compute/docs/reference/rest/v1/instances/get). There will be an equivalent in the .NET SDK. – John Hanley May 29 '23 at 19:07

1 Answers1

0

As per Maninder Chhabra, there is a command gcloud compute instances os-inventory describe VM-NAME to get the OS configs only when VM is in RUNNING state.

Dion V
  • 356
  • 2
  • 7