我正试图在特定项目中找到具有特定标记的所有虚拟机。这适用于
gcloud compute instances list --project myproject --filter="(name=myvm) AND --filter="tags.items~*ngf*"
但是去掉虚拟机名称不起作用
gcloud compute instances list --project myproject --filter="tags.items~*ngf*"
错误消息为
ERROR: (gcloud.compute.instances.list) Filter expression RE pattern [*ngf*]: nothing to repeat at position 0
有什么想法吗?我试着在过滤器中使用标签而不是tags.items,但似乎也不起作用。
您遇到的问题是由于您使用的正则表达式造成的。
*
使生成的RE与前一RE的0次或多次重复匹配,尽可能多地重复。ab*将匹配"a"、"ab"或"a",后跟任意数量的"b"。
您可以查看以下链接以获取有关正则表达式的详细信息。
关于您的请求:
我正在尝试查找特定项目中具有特定标记的所有虚拟机。
请尝试使用以下命令:
gcloud compute instances list --filter="(tags.items ~ <<YOUR-NETWORK-TAG>>*)" --project <<MY-PROJECT>>
或
gcloud compute instances list --filter="(tags.items=<<YOUR-NETWORK-TAG>>)" --project <<MY-PROJECT>>
现在,对于标签,您可以使用以下内容:
gcloud compute instances list --filter="(tags.items=<<YOUR-NETWORK-TAG>>) AND (labels.<<MY-LABEL>>:*)" --project <<MY-PROJECT>>
您可以查看此链接以查找更多示例:gcloud主题过滤器