Reputation: 51
I am using C# Google SDK to fetch the list of public ubuntu or debian VM Images available in Google Cloud. The response is a long list of VM' having primarily the deprecated State as "OBSOLETE".
When applying the filter for ACTIVE state the response is null , Can anyone help on how to fetch the active images, or if the result returned without filter is correct.
Scenario 1 . When no filter is applied
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 Server, version 1709 Core for Containers (Beta), Server Core, x64 built on 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, "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" ], "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": null, "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, version 1709 Core for Containers (Beta), Server Core, x64 built 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" ], "name": "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", "asia", "asia", "eu", "asia", "asia", "us", "asia", "us", "us", "eu", "eu" ], "ETag": null },
============================================================
Scenario 2: On applying filters
var lstRequest = new ImagesResource.ListRequest(_computeClient, "ubuntu-os-cloud"); lstRequest.Filter = "deprecated.state=ACTIVE"; var images = lstRequest.Execute();
Null
I am using Google.Apis.Compute.v1 namespace
Upvotes: 0
Views: 1172
Reputation: 40061
Update: As Sam pointed out ACTIVE
is a valid state (link) but it's unused in the example list, hence the null
result.
I think because the value ACTIVE
is invalid.
gcloud compute images list \
--project=${PROJECT} \
--show-deprecated \
--format="value(deprecated.state)" \
| sort \
| uniq
DEPRECATED
OBSOLETE
I got results with neither then either of:
request.Filter="deprecated.state=\"DEPRECATED\"";
request.Filter="deprecated.state=\"OBSOLETE\"";
NOTE Image Projects are not the same as GCP Projects
Compute Engine API v1 only surfaces the Image Project as part of an image's
selfLink
When you
computeService.Images.List(project);
The value of
project
should be your GCP project notubuntu-os-cloud
.Using
ubuntu-os-cloud
works but it does not filter the results by theubuntu-os-cloud
Image Project.
Also, APIs Explorer is an excellent mechanism to test Google API service calls to ensure you're getting them correct, e.g.:
Upvotes: 1