Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud, compute.instances.aggregatedList with filter fails

The google cloud API for compute.instances.aggregatedList includes filter argument. https://cloud.google.com/compute/docs/reference/rest/beta/instances/aggregatedList

I use (status eq "RUNNING") as a filter to view all my running instances.

I would like to have a more elaborate criteria, such as one that uses labels and or other terms, however even the Google documentation terms (that use OR operator) returns an error, For example - even Google documentation example: (cpuPlatform = "Intel Skylake") OR (cpuPlatform = "Intel Broadwell") fails with error 400:

"message": "Invalid value for field 'filter': ' (cpuPlatform = \"Intel Skylake\") OR (cpuPlatform = \"Intel Broadwell\")'. Invalid list filter expression."

it looks as if the '=' signs are not accepted, and AND/OR operators are not accepted. What is the correct format for this API.

like image 805
Jackie Assa Avatar asked May 21 '18 16:05

Jackie Assa


People also ask

Are we charged for stopped instances in GCP?

A stopped instance does not incur charges, but all of the resources that are attached to the instance will still be charged. For example, you are charged for persistent disks and external IP addresses according to the price sheet, even if an instance is stopped.

How do I stop instances on Google Cloud?

In the Google Cloud console, go to the VM instances page. Select one or more VMs that you want to stop. Click Stop.

What is number of instances in Google Cloud?

By default, Cloud Run services are configured to scale out to a maximum of 100 instances. You can change the maximum instances setting using the Google Cloud console, the gcloud command line, or a YAML file when you create a new service or deploy a new revision.


1 Answers

I had the same issue when I used "=" instead of "eq" in google-api-python-client. I required to use labels to filter the aggregated instances list. At first I used

filter="labels.projectid=test-project"

which returned 400 error in aggregated list but was successful if it was queried for instances of specific zone.

I achieved the list successfully when I used filter as

filter="labels.projectid eq \"test-project\""

or

filter = "labels.projectid eq test-project"

I even tested it using REST-Client provided by google and it worked. Reference: https://issuetracker.google.com/80238913

like image 178
Laxmi Prasad Avatar answered Sep 30 '22 18:09

Laxmi Prasad