在GCP中使用标签过滤实例模板失败,并显示“无效的列表过滤器表达式". [英] Filtering instance templates using labels in GCP fails with ''Invalid list filter expression."

查看:58
本文介绍了在GCP中使用标签过滤实例模板失败,并显示“无效的列表过滤器表达式".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行此python代码以列出具有特定标签的实例模板.调用GCP API但失败.

Running this python code to list the instance template which have a specific label . Calling the GCP API but fails .

代码段:

request = service.instanceTemplates().list(project=project,filter=
    {
        labels: {'env':'dmittal-dc'}
    }
)

试图通过多种方式指定过滤器的值,但没有成功:

Tried specifing the value of filter in multiple ways but did not worked:

googleapiclient.errors.HttpError: <HttpError 400 when requesting https://compute.googleapis.com/compute/v1/projects/dlpx-dcoa-dmittal/global/instanceTemplates?filter=%7B%3Cmodule+%27pip._vendor.webencodings.labels%27+from+%27%2FUsers%2Fdeepali.mittal%2Fdevops-gate%2Fdcenter%2Fpython%2Fbuild%2Fdmittal%2Fvirtual-env36%2Flib%2Fpython3.6%2Fsite-packages%2Fpip%2F_vendor%2Fwebencodings%2Flabels.py%27%3E%3A+%7B%27env%27%3A+%27dmittal-dcoa%27%7D%7D&alt=json returned "Invalid value for field 'filter': '{<module 'pip._vendor.webencodings.labels' from '/Users/deepali.mittal/devops-gate/dcenter/python/build/dmittal/virtual-env36/lib/python3.6/site-packages/pip/_vendor/webencodings/labels.py'>: {'env': 'dmittal-dcoa'}}'. Invalid list filter expression.". Details: "Invalid value for field 'filter': '{<module 'pip._vendor.webencodings.labels' from '/Users/deepali.mittal/devops-gate/dcenter/python/build/dmittal/virtual-env36/lib/python3.6/site-packages/pip/_vendor/webencodings/labels.py'>: {'env': 'dmittal-dc'}}'. Invalid list filter expression.">

推荐答案

filter 应该是字符串类型(请参阅 help(service.instanceTemplates().list)链接).我相信,您正在寻找的是这个

The filter is expected to be of a string type (see help(service.instanceTemplates().list) and link). I believe, what you are looking for is this:

req = service.instanceTemplates().list(
  project=project,
  filter='properties.labels.env=dmittal-dc'
)

这篇关于在GCP中使用标签过滤实例模板失败,并显示“无效的列表过滤器表达式".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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