Question

I was wondering how to get the value of a specific metadata for a given instance in GCE.

For now I can view all the instance property with :

gcutil getinstance instance-test

But it returns all the metadata and I can not find a "filter" option in the gcutil documentation.

Any ideas ?

Was it helpful?

Solution

You can have gcutil output into JSON format instead of tabular format by using the --format flag (see gcutil --help):

--format: <table|sparse|json|csv|names>: Format for command output. Options include:
  table: formatted table output
  sparse: simpler table output
  json: raw json output (formerly --print_json)
  csv: csv format with header
  names: list of resource names only, no header
  (default: 'table')

For example:

gcutil --format=json getinstance instance-test

Combine this with the jq for easy, powerful commands:

$ gcutil --format=json --service_version=v1 --project="<project>" \
      --zone="<zone>" getinstance "<instance>" | jq '.metadata.kind'
"compute#metadata"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top