Building Google Cloud Platform Solutions
上QQ阅读APP看书,第一时间看更新

Filtering

Suppose we want to find only the services related to vision. We can do this using filters. As with projections, filters in gcloud can be very expressive. To filter the previously mentioned result to only services related to vision, we can use a simple pattern matcher on the serviceConfig.name property, as follows:

gcloud services list --available --format="json" --filter='serviceConfig.name:vision'

By combining flags such as sorting and filtering, results can be heavily modified to suit specific use cases, meaning much of the heavy lifting of automating tasks can be offloaded to gcloud itself. This allows developers to spend more time solving the problems at hand. In practice, this could be used to do any number of useful things like identifying all Compute Engine instances running a specific image or identifying all App Engine services that have nonrunning instances.

The topic of formatting and filtering data in gcloud is very deep. To learn more and see other examples, see the gcloud topics for formats, filters, projections, and resource keys. For more information on scripting with gcloud in general, visit https://cloud.google.com/sdk/docs/scripting-gcloud.