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

是否有对应Google OS补丁管理GUI的gcloud或Python API查询可用补丁?

等价于Google OS补丁管理GUI的gcloud命令与Python API方案

gcloud命令实现

  • 查看实例补丁状态(批量/单个)
    • 批量获取实例补丁详情并筛选有可用更新的实例:
      gcloud compute os-config patch-jobs list-instance-details --filter="instance_update_state=PENDING"
      
      该命令会返回所有处于待更新状态的实例,和GUI中“有可用软件包更新”的实例列表对应。
    • 查看单个实例的详细补丁报告(包含可用更新包信息):
      gcloud compute os-config instance-reports describe INSTANCE_NAME --zone=YOUR_ZONE
      
      报告里的available_package_updates字段会列出所有可安装的软件包更新。

Python API实现

使用Google Cloud OS Config API直接获取实例补丁状态,核心示例代码如下:

from google.cloud import osconfig_v1

# 初始化客户端
client = osconfig_v1.OsConfigServiceClient()

# 单个实例报告查询
instance_full_name = "projects/[PROJECT_ID]/zones/[ZONE]/instances/[INSTANCE_NAME]"
report = client.get_instance_report(name=instance_full_name)

# 提取可用补丁信息
if report.available_package_updates:
    print("可用软件包更新:")
    for update in report.available_package_updates:
        print(f"- 包名: {update.package_name} | 当前版本: {update.current_version} | 可用版本: {update.available_version}")

# 批量实例报告查询(筛选有可用更新的实例)
parent = "projects/[PROJECT_ID]/locations/[LOCATION]"
for instance_report in client.list_instance_reports(parent=parent):
    if instance_report.available_package_updates:
        print(f"\n实例 {instance_report.name} 存在可用更新")

权限说明

需要为操作账号分配OS Config Viewer或更高权限的IAM角色,才能正常访问补丁状态数据。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 12:30:43