我正在使用C#谷歌SDK获取谷歌云中可用的公共ubuntu或debian虚拟机映像的列表。响应是VM’的长列表,其主要具有被否决的状态为";废弃";。
当为ACTIVE状态应用过滤器时,响应为null,任何人都可以帮助如何获取活动图像,或者在没有过滤器的情况下返回的结果是否正确。
场景1。当没有应用过滤器时
var lstRequest=新的ImagesSource.ListRequest(_computeClient,");var images=lstRequest.Execute();
样本响应
{"id":"projects/windowscloud/global/images";,"项目":[{"archiveSizeBytes":77493158912,"creationTimestamp":"2017-11-06T11:38:00.859-08:00";,"不赞成":{"删除":无效的"不赞成":无效的"过时":无效的"替换":无效的"状态":"废弃";,"ETag":无效的},"描述":"Microsoft,Windows Server,1709版Core for Containers(Beta),Server Core,x64 builded on 2017-10-30";,"diskSizeGb":32,"家族":"windows-1709-core-for-containers";,"留言功能":[{"类型":"MULTI_IP_ SUBNET";,"ETag":无效的},{"类型":"VIRTIO_SCSI_MULTIQUEUE";,"ETag":无效的},{"类型":"WINDOWS";,"ETag":无效的}],"id":7068044754301027575,"imageEncryptionKey":无效的"种类":"计算#图像";,"labelFingerprint":"42WmSpB8rSM=";,"标签":无效的"licenseCodes":[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"],"name":"windows-server-1709-dc-core-for-containers-v20171030";,"rawDisk":{"containerType":"TAR";,"sha1Checksum":无效的"源":"quot;},"selfLink":"https://www.googleapis.com/compute/v1/projects/windows-cloud/global/images/windows-server-1709-dc-core-for-containers-v20171030","屏蔽实例初始状态":无效的"sourceDisk":无效的"sourceDiskEncryptionKey":无效的"sourceDiskId":无效的"sourceImage":无效的"sourceImageEncryptionKey":无效的"sourceImageId":无效的"sourceSnapshot":无效的"sourceSnapshotEncryptionKey":无效的"sourceSnapshotId":无效的"sourceType":"RAW";,"状态":"READY";,"storageLocations":["我们";,"我们";,"eu";,"亚洲";,"亚洲";,"eu";,"亚洲";,"我们";,"我们";,"我们";,"亚洲";,"亚洲";,"eu";],"ETag":无效的},{"archiveSizeBytes":79706428672,"creationTimestamp":"2017-11-16T12:14:33.228-08:00";,"不赞成":{"删除":无效的"不赞成":无效的"过时":无效的"替换":无效的"状态":"废弃";,"ETag":无效的},"描述":"Microsoft,Windows Server,1709版Core for Containers(Beta),Server Core,x64 builded on 2017-11-14";,"diskSizeGb":32,"家族":"windows-1709-core-for-containers";,"留言功能":[{"类型":"MULTI_IP_ SUBNET";,"ETag":无效的},{"类型":"VIRTIO_SCSI_MULTIQUEUE";,"ETag":无效的},{"类型":"WINDOWS";,"ETag":无效的}],"id":1572352838839848774,"imageEncryptionKey":无效的"种类":"计算#图像";,"labelFingerprint":"42WmSpB8rSM=";,"标签":无效的"licenseCodes":[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"],"name":"windows-server-1709-dc-core-for-containers-v20171114";,"rawDisk":{"containerType":"TAR";,"sha1Checksum":无效的"源":"quot;},"selfLink":"https://www.googleapis.com/compute/v1/projects/windows-cloud/global/images/windows-server-1709-dc-core-for-containers-v20171114","屏蔽实例初始状态":无效的"sourceDisk":无效的"sourceDiskEncryptionKey":无效的"sourceDiskId":无效的"sourceImage":无效的"sourceImageEncryptionKey":无效的"sourceImageId":无效的"sourceSnapshot":无效的"sourceSnapshotEncryptionKey":无效的"sourceSnapshotId":无效的"sourceType":"RAW";,"状态":"READY";,"storageLocations":["我们";,"我们";,"亚洲";,"亚洲";,"eu";,"亚洲";,"亚洲";,"我们";,"亚洲";,"我们";,"我们";,"eu";,"eu";],"ETag":无效的},
=============================================
场景2:应用过滤器
var lstRequest=新图像资源。ListRequest(_computeClient,"ubuntu os cloud");lstRequest。Filter=";state=ACTIVE";;var images=lstRequest。执行();
响应
空
我在用谷歌。Apis。Compute.v1命名空间
更新:正如Sam所指出的,ACTIVE
是一个有效的状态(链接),但它在示例列表中未使用,因此产生了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项目不同
计算引擎API v1仅将图像项目作为图像的
selfLink
的一部分进行表面处理当你
computeService.Images.List(project);
project
的值应该是您的GCP项目,而不是ubuntu-os-cloud
。使用
ubuntu-os-cloud
是可行的,但它不通过ubuntu-os-cloud
图像项目过滤结果。
此外,API资源管理器是测试Google API服务调用的优秀机制,以确保您得到正确的调用,例如:
https://cloud.google.com/compute/docs/reference/rest/v1/images/list?apix=true&apix_params=%7B%22项目%22%3A%22 ubuntu os云%22%2C%22过滤器%22%3A/22已弃用。状态%3OBSOLATE%22%7D