Search code examples
google-cloud-platformgoogle-cloud-pythongcloud-python

How to filter by networkIP in gcloud python instances


I am using gcloud python client library (https://github.com/google/google-api-python-client) to get a list of instances. I am able to use filters like name, status but I can't figure out how to filter by IP address (networkIP). I'm sure it has something to do with networkInterfaces being a list, but I can't figure the syntax.

Here's what I think should work:

instance_list = compute.instances().list(
        project=project,
        zone=zone,
        filter='networkInterfaces[0].networkIP eq 10.45.128.6'
        ).execute()

It returns a HTTP Status 400: "Invalid value for field 'filter'."

What should the filter look like?

Thank you in advance.


Solution

  • Unfortunately right now it is not posible to filter by networkInterfaces networkIP as the API calls does not support filtering by an array of abject.

    All that being said I went ahead and opened a public feature request [1] so you can keep track of it. Keep in mind that there is no ETA or guaranty that this feature will be implemented.

    As a workaround you could parse the JSON output of the call without filter and then filter it via code.

    [1] https://issuetracker.google.com/73455339