Is it possible to filter out instances on a wildcard or regex? I essentially just want GCE instances, not GKE or instances provisioned by other services.
I've found that GCP service created instances have a label attached that typically starts with goog-*. From GCP Cloud Logging I can filter these out fine but there's doesn't seem to be any support for regex in the python client.
from googleapiclient.discovery import build
service = build('compute', 'v1', credentials=credentials)
request = service.instances().aggregatedList(project="my-project", filter="labels != goog-*")
While it's not a documented feature that you get those
goog-somethinglabels when deploying a new cluster or even a single VM solution - in most cases it will be true.To get get a nice list of all instances with labels other than
goog-run:Applying it to Python it can look like this:
or you can use
subprocess.run(as described here).If in any doubt you can have a look at the
gcloud compute instances listdocs and how to use a filter option.