GCP Classroom Series – 18/Apr/2021

Automating tasks with gcloud

Modifying output and behavior

  • gcloud tool offers many configuration properties and global flags to customize user experience and modify behavior
Global flags Description
–quiet Disable prompts
–log-http Record all network requests & responses
–verbosity <LEVEL> one of critical, debug, error, info, warningg none
–format Modify the output format for the command
–flatten Modifies the command outputt by separiting nested lists into distinct elements
List-Specific tags Description
–filter <Expression> Filter list results based on given expression
–limit <LIMIT> Limit number of results
–sort-by [FIELD, ..] One or more fields to sort results by
  • Lets use some of the expressions
gcloud services list --available 
gcloud services list --available --format="json"
gcloud services list --format="table[box, title= 'Services List'](name, state)"

Preview

  • Some other formats
gcloud compute zones list --format="csv(name,region)"
gcloud compute networks subnets list --network=default --filter="region:(us-west1 us-central1)" --format=json

gcloud compute networks subnets list --format="json" --filter="name=default AND region ~ us-central1"

Sample Shell Script to iterate through vm instances

  • Shell script to stop all vm instances
  • Refer Here for the script
  • Exercise: Modify the script to stop the vms only having specific labels

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Network Widget by Acurax Small Business Website Designers

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube