-1

我正在使用 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”,“items”:[{“archiveSizeBytes”:77493158912,“creationTimestamp”:“2017-11-06T11:38:00.859-08:00”,“弃用”:{“已删除”:空,“弃用”:空,“过时”:空,“替换”:空,“状态”:“过时”,“ETag”:空},“描述”:“微软, Windows Server,版本 1709 Core for Containers (Beta),Server Core,x64 构建于 2017-10-30","diskSizeGb":32,"family":"windows-1709-core-for-containers","guestOsFeatures" : [ { "type": "MULTI_IP_SUBNET", "ETag": null }, { "type": "VIRTIO_SCSI_MULTIQUEUE", "ETag": null }, { "type":“WINDOWS”,“ETag”:null}],“id”:7068044754301027575,“imageEncryptionKey”:null,“kind”:“compute#image”,“labelFingerprint”:“42WmSpB8rSM=”,“labels”:null, “许可证代码”:[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”,“rawDisk”:{“containerType”:“TAR” , "sha1Checksum": null, "source": "" }, "selfLink": "https://www.googleapis.com/compute/v1/projects/windows-cloud/global/images/windows-server-1709-dc- core-for-containers-v20171030”,“shieldedInstanceInitialState”:null,“sourceDisk”:null,“sourceDiskEncryptionKey”:null,“sourceDiskId”:null,“sourceImage”:null,“sourceImageEncryptionKey”:null,“sourceImageId”:null ,“sourceSnapshot”:null,“sourceSnapshotEncryptionKey”:null,“sourceSnapshotId”:null,“sourceType”:“RAW”,“status”:“READY”,“storageLocations”:[“us”,“us”,“eu ", "亚洲", "亚洲", "欧盟", "亚洲", "我们", "我们”,“我们”,“亚洲”,“亚洲”,“欧盟”],“ETag”:null },{“archiveSizeBytes”:79706428672,“creationTimestamp”:“2017-11-16T12:14:33.128-08 :00", "deprecated": { "deleted": null, "deprecated": null, "obsolete": null, "replacement": null, "state": "OBSOLETE", "ETag": null }, "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": [ { "type": "MULTI_IP_SUBNET", "ETag": null }, { "type": "VIRTIO_SCSI_MULTIQUEUE", "ETag": null },{ "type": "WINDOWS", "ETag": null } ], "id": 1572352838839848774, "imageEncryptionKey": null, "kind": "compute#image", "labelFingerprint": "42WmSpB8rSM=", "labels ": null, "licenseCodes": [5194306116883728686, 1000226, 2643967004807329741], "licenses": ["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”,“rawDisk”:{“containerType” :“TAR”,“sha1Checksum”:null,“source”:“”},“selfLink”:“https://www.googleapis.com/compute/v1/projects/windows-cloud/global/images/windows-server- 1709-dc-core-for-containers-v20171114”,“shieldedInstanceInitialState”:null,“sourceDisk”:null,“sourceDiskEncryptionKey”:null,“sourceDiskId”:null,“sourceImage”:null,“sourceImageEncryptionKey”:null,“ sourceImageId”:null,“sourceSnapshot”:null,“sourceSnapshotEncryptionKey”:null,“sourceSnapshotId”:null,“sourceType”:“RAW”,“status”:“READY”,“storageLocations”:[“us”,“us ", "亚洲", "亚洲", "欧盟", "亚洲", "亚洲", "我们”,“亚洲”,“我们”,“我们”,“欧盟”,“欧盟”],“ETag”:空},


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

场景 2:在应用过滤器时

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

回复

无效的

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

4

1 回答 1

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%22已弃用。状态%3DOBSOLETE%22%7D

于 2020-12-18T22:00:41.480 回答