【问题标题】:Fetching List public VM Images in Google Cloud获取 Google Cloud 中的公共 VM 映像列表
【发布时间】:2020-12-18 17:34:21
【问题描述】:

我正在使用 C# Google SDK 来获取 Google Cloud 中可用的公共 ubuntu 或 debian VM 映像列表。 响应是一长串 VM',主要将弃用状态设为“OBSOLETE”。

当为 ACTIVE 状态应用过滤器时,响应为 null ,任何人都可以帮助了解如何获取活动图像,或者如果没有过滤器返回的结果是正确的。

场景 1 。未应用过滤器时

var lstRequest = new ImagesResource.ListRequest(_computeClient, ""); var images = lstRequest.Execute();

示例响应

{ "id": "projects/windows-cloud/global/images", “项目”: [ { “archiveSizeBytes”:77493158912, "creationTimestamp": "2017-11-06T11:38:00.859-08:00", “弃用”:{ “已删除”:空, “弃用”:空, “过时”:空, “替换”:空, “状态”:“过时”, “ETag”:空 }, "description": "Microsoft, Windows Server, version 1709 Core for Containers (Beta), Server Core, x64 build on 2017-10-30", "diskSizeGb": 32, "family": "windows-1709-core-for-containers", “guestOsFeatures”:[ { “类型”:“MULTI_IP_SUBNET”, “ETag”:空 }, { “类型”:“VIRTIO_SCSI_MULTIQUEUE”, “ETag”:空 }, { “类型”:“窗口”, “ETag”:空 } ], “身份证”:7068044754301027575, “imageEncryptionKey”:空, “种类”:“计算#图像”, "labelFingerprint": "42WmSpB8rSM=", “标签”:空, “许可证代码”:[ 5194306116883728686, 1000226, 2643967004807329741 ], “许可证”:[ "https://www.googleapis.com/compute/v1/projects/windows-cloud/global/licenses/windows-server-1709-dc", "https://www.googleapis.com/compute/v1/projects/windows-cloud/global/licenses/windows-server-core", “https://www.googleapis.com/compute/v1/projects/windows-cloud/global/licenses/windows-for-containers” ], “名称”:“windows-server-1709-dc-core-for-containers-v20171030”, “原始磁盘”:{ "containerType": "TAR", “sha1Checksum”:空, “来源”: ”” }, "selfLink": "https://www.googleapis.com/compute/v1/projects/windows-cloud/global/images/windows-server-1709-dc-core-for-containers-v20171030", “shieldedInstanceInitialState”:空, “sourceDisk”:空, “sourceDiskEncryptionKey”:空, “sourceDiskId”:空, “源图像”:空, “sourceImageEncryptionKey”:空, “sourceImageId”:空, “源快照”:空, “sourceSnapshotEncryptionKey”:空, “sourceSnapshotId”:空, "sourceType": "RAW", “状态”:“就绪”, “存储位置”:[ “我们”, “我们”, “欧洲联盟”, “亚洲”, “亚洲”, “欧洲联盟”, “亚洲”, “我们”, “我们”, “我们”, “亚洲”, “亚洲”, “欧洲联盟” ], “ETag”:空 }, { “archiveSizeBytes”:79706428672, "creationTimestamp": "2017-11-16T12:14:33.128-08:00", “弃用”:{ “已删除”:空, “弃用”:空, “过时”:空, “替换”:空, “状态”:“过时”, “ETag”:空 }, "description": "Microsoft, Windows Server, version 1709 Core for Containers (Beta), Server Core, x64 build on 2017-11-14", "diskSizeGb": 32, "family": "windows-1709-core-for-containers", “guestOsFeatures”:[ { “类型”:“MULTI_IP_SUBNET”, “ETag”:空 }, { “类型”:“VIRTIO_SCSI_MULTIQUEUE”, “ETag”:空 }, { “类型”:“窗口”, “ETag”:空 } ], “身份证”:1572352838839848774, “imageEncryptionKey”:空, “种类”:“计算#图像”, "labelFingerprint": "42WmSpB8rSM=", “标签”:空, “许可证代码”:[ 5194306116883728686, 1000226, 2643967004807329741 ], “许可证”:[ "https://www.googleapis.com/compute/v1/projects/windows-cloud/global/licenses/windows-server-1709-dc", "https://www.googleapis.com/compute/v1/projects/windows-cloud/global/licenses/windows-server-core", “https://www.googleapis.com/compute/v1/projects/windows-cloud/global/licenses/windows-for-containers” ], “名称”:“windows-server-1709-dc-core-for-containers-v20171114”, “原始磁盘”:{ "containerType": "TAR", “sha1Checksum”:空, “来源”: ”” }, "selfLink": "https://www.googleapis.com/compute/v1/projects/windows-cloud/global/images/windows-server-1709-dc-core-for-containers-v20171114", “shieldedInstanceInitialState”:空, “sourceDisk”:空, “sourceDiskEncryptionKey”:空, “sourceDiskId”:空, “源图像”:空, “sourceImageEncryptionKey”:空, “sourceImageId”:空, “源快照”:空, “sourceSnapshotEncryptionKey”:空, “sourceSnapshotId”:空, "sourceType": "RAW", “状态”:“就绪”, “存储位置”:[ “我们”, “我们”, “亚洲”, “亚洲”, “欧洲联盟”, “亚洲”, “亚洲”, “我们”, “亚洲”, “我们”, “我们”, “欧洲联盟”, “欧洲联盟” ], “ETag”:空 },


================================================ ==============

场景 2:应用过滤器

var lstRequest = new ImagesResource.ListRequest(_computeClient, "ubuntu-os-cloud"); lstRequest.Filter = "deprecated.state=ACTIVE"; var images = lstRequest.Execute();

响应

我正在使用 Google.Apis.Compute.v1 命名空间

【问题讨论】:

    标签: google-cloud-platform gcloud google-compute-api gcloud-compute


    【解决方案1】:

    更新:正如 Sam 指出的那样,ACTIVE 是一个有效状态 (link),但它在示例列表中未使用,因此是 null 结果。

    我认为是因为ACTIVE 的值无效。

    gcloud compute images list \
    --project=${PROJECT} \
    --show-deprecated \
    --format="value(deprecated.state)" \
    | sort \
    | uniq
    
    DEPRECATED
    OBSOLETE
    

    我得到的结果都没有:

    request.Filter="deprecated.state=\"DEPRECATED\"";
    request.Filter="deprecated.state=\"OBSOLETE\"";
    

    注意图像项目与 GCP 项目不同

    Compute Engine API v1 仅将图像项目作为图像selfLink 的一部分显示

    当你computeService.Images.List(project);

    project 的值应该是您的 GCP 项目,而不是 ubuntu-os-cloud

    使用ubuntu-os-cloud 有效,但它不会过滤ubuntu-os-cloud 图像项目的结果。

    另外,APIs Explorer 是测试 Google API 服务调用以确保您得到正确调用的绝佳机制,例如:

    https://cloud.google.com/compute/docs/reference/rest/v1/images/list?apix=true&apix_params=%7B%22project%22%3A%22ubuntu-os-cloud%22%2C%22filter%22%3A%22deprecated.state%3DOBSOLETE%22%7D

    【讨论】:

    • 检查此链接,状态状态可以是 ACTIVE、OBSOLETE、DEPRECATED、DELETED。
    • 很好的发现。尽管在这种情况下似乎没有使用它。 gcloud 命令没有返回带有该值的图像,这就解释了为什么您在代码中得到 null
    猜你喜欢
    • 1970-01-01
    • 2020-03-24
    • 2017-12-29
    • 1970-01-01
    • 1970-01-01
    • 2020-01-17
    • 1970-01-01
    • 2014-01-18
    • 1970-01-01
    相关资源
    最近更新 更多