You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Google Python API客户端中仅查询运行状态的GCP实例

你可以通过filter请求参数实现仅拉取运行中的实例,你提到的按status筛选的思路是正确的,只需要按接口要求调整参数写法即可。

GCP Compute Engine的实例状态中,运行中实例的状态值为全大写的RUNNING,调整后的代码如下:

project_id = 'company1'
zone = 'us-east1-b'
compute = googleapiclient.discovery.build('compute', 'v1')
result = compute.instances().list(
    project=project_id,
    zone=zone,
    filter='status=RUNNING'
).execute()

如果后续需要多条件组合筛选,也可以直接在filter参数中拼接规则,比如筛选名称前缀为prod-的运行实例,可以写成filter='status=RUNNING AND name:prod-*'。

内容的提问来源于stack exchange,提问作者bluethundr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.20 08:24:04