google cloud platform - How to filter by tags in gcloud python client -


i using gcloud python client library(https://github.com/google/google-api-python-client) list of instances. able use filters name, status can't figure out way filter tags. able via gcloud cli tool.

getting list of machines works fine

instance_list = compute.instances().list(project=project,zone=zone).execute() 

even filter status works

instance_list = compute.instances().list(project=project,zone=zone,filter='status eq running').execute() 

but, filtering tags doesn't work

instance_list = compute.instances().list(project=project,zone=zone,filter='tags.items eq dev').execute() 

it returns http status 400. but, using gcloud cli tool, can succesfully run

gcloud compute instances list --filter="tags.items=dev" 

how can manage using python client library?

if @ gcloud compute instances describe instance-name output instance expect match you'll see relationship between tags , labels attributes. many google cloud api resources, including compute.instances, support labels. list of name=value pairs. compute.instances each tag label empty value.

--filter="labels.name:*" existence check label or tag name. compute api filter equivalent "labels.name eq '.*'".

for specific example use gcloud flag --filter="labels.dev:*" and/or compute api filter="labels.dev eq '.*'".

you can use google apis explorer play compute.instances filter expressions.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -