【问题标题】:How do list instances with specific label using Compute API in GCP?如何在 GCP 中使用 Compute API 列出具有特定标签的实例?
【发布时间】:2020-08-30 12:06:07
【问题描述】:

我正在使用 Python 的 GCP Compute API 方法并尝试获取具有特定标签的所有实例的列表。列出实例的语法是:

service.instances().list(project=project, zone=zone).execute()

但是,每当我添加 filter=my-label:label 或任何类似内容时,我都会收到错误消息。 想知道其他人是否能够获得一份清单,如果可以,如何获得?

【问题讨论】:

    标签: python api google-cloud-platform python-requests instance


    【解决方案1】:

    您可以使用以下语法:

    request = service.instances().list(project=project, zone=zone, filter='labels.my-label=my-value')
    

    确保至少有一个实例符合过滤条件,否则response[items] 将不会被定义。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-13
    • 2022-10-02
    • 1970-01-01
    • 2018-06-12
    • 1970-01-01
    • 2022-11-03
    • 1970-01-01
    相关资源
    最近更新 更多