Google Cloud Platform-如何通过标签过滤instances.list? [英] Google Cloud Platform - How to filter instances.list by tag?

查看:61
本文介绍了Google Cloud Platform-如何通过标签过滤instances.list?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过标签名称过滤实例列表

I'm trying to filter list of instances by tag name

与gcloud完美搭配的方法,例如

What works perfectly with gcloud, e.g.

gcloud compute instances list --filter 'tags.items=firewall-client-mongodb'

不适用于始终返回400的API:

Does not work with API, which always returns 400:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalid",
    "message": "Invalid value for field 'filter': 'tags.items = test'. Invalid list filter expression."
   }
  ],
  "code": 400,
  "message": "Invalid value for field 'filter': 'tags.items = test'. Invalid list filter expression."
 }
}

是否可以通过标签或任何用户定义的变量来过滤实例?我正在测试 https://cloud.google.com/compute/docs/reference/rest/v1/instances/list

Is there any way to filter instances by tag, or any user defined variable? I'm testing with https://cloud.google.com/compute/docs/reference/rest/v1/instances/list

推荐答案

似乎 gcloud -filter 实现被破坏.尝试在括号中引用您的搜索模式:

Seems that gcloud --filter implementation is broken. Try quote your search pattern in parentheses:

gcloud ... --filter='term=(item-1 item-2)'

破折号(-)可能会破坏-format ((

Dashes (-) might break DSL of --format ((

官方文档将值广泛地用parethese括起来:

Official docs extensively encloses values in paretheses:

喜欢:

列出带有标签my-tag或my-other-tag的Compute Engine实例资源:

List Compute Engine instance resources with tag my-tag or my-other-tag:

gcloud compute instances list  --filter="tags.items=(my-tag,my-other-tag)"

这篇关于Google Cloud Platform-如何通过标签过滤instances.list?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆