簡體   English   中英

獲取 Google Cloud 中的公共 VM 映像列表

[英]Fetching List public VM Images in Google Cloud

我正在使用 C# Google SDK 來獲取公共 ubuntu 或 Z6E9552C9BD218E601C8F237Z7 VMC2 圖像中可用的列表響應是一長串 VM',主要將已棄用的 State 作為“過時”。

當為 ACTIVE state 應用過濾器時,響應為 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”,“ deprecated": { "deleted": null, "deprecated": null, "obsolete": null, "replacement": null, "state": "OBSOLETE", "ETag": null }, "description": "Microsoft, Windows 服務器,版本 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,“種類”:“compute#image”,“l abelFingerprint": "42WmSpB8rSM=", "labels": null, "licenseCodes": [5194306116883728686, 1000226, 2643967004807329741], "licenses": ["https://1.googles.com. 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": 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": Z37A6259CC0C1DAE29 9A7866489DFF0BDZ, "sourceImage": null, "sourceImageEncryptionKey": null, "sourceImageId": null, "sourceSnapshot": null, "sourceSnapshotEncryptionKey": null, "sourceSnapshotId": null, "sourceType": "RAW", "status": "READY", "storageLocations": [ "us", "us", "eu", "asia", "asia", "eu", "asia", "us", "us", "us", " asia", "asia", "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, v ersion 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-1 709-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”:Z37A6259CC0641DAE299A786 ": null, "sourceDiskId": null, "sourceImage": null, "sourceImageEncryptionKey": null, "sourceImageId": null, "sourceSnapshot": null, "sourceSnapshotEncryptionKey": null, "sourceSnapshotId": null, "sourceType": “RAW”、“狀態”:“READY”、“storageLocations”:[“我們”、“我們”、“亞洲”、“亞洲”、“歐盟”、“亞洲”、“亞洲”、“我們”、“亞洲”、“我們”、“我們 ", "歐盟", "歐盟" ], "ETag": null },


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

場景 2:在應用過濾器時

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

回復

Null

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

更新:正如 Sam 指出的那樣, ACTIVE是一個有效的 state( 鏈接),但它在示例列表中未使用,因此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 Image Project 過濾結果。

此外, 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM