0

I need to list all the compute instance snapshots successfully created in a project (only for compute instance types), along with the compute engine names.

I am using this API: https://compute.googleapis.com/compute/v1/projects/my-project/global/snapshots

It lists the snapshot and I get the response like this:

"items": [
    {
      "id": "36734343434334343",
      "creationTimestamp": "2020-09-16T11:38:54.780-07:00",
      "name": "backup-data1-us-central1-c-3234234324-202009161",
      "status": "READY",
      "sourceDisk": "https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-c/disks/backup-data1",
      "sourceDiskId": "323434232434970709",
      "diskSizeGb": "10",
      "storageBytes": "452416",
      "storageBytesStatus": "UP_TO_DATE",
      "selfLink": "https://www.googleapis.com/compute/v1/projects/my-project/global/snapshots/amtest-backup-data1-us-central1-c-3234234324-202009161",
      "labelFingerprint": "23WmSpBrSM=",
      "storageLocations": [
        "us-central1"
      ],
      "autoCreated": true,
      "downloadBytes": "456717",
      "kind": "compute#snapshot"
    },
    {
      "id": "343486082509657007",
      "creationTimestamp": "2020-09-17T11:38:56.840-07:00",
      "name": "backup-data1-us-central1-c-3234234324-202009161",
      "status": "READY",
      "sourceDisk": "https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-c/disks/backup-data1",
      "sourceDiskId": "323434232434970709",
      "diskSizeGb": "10",
      "storageBytes": "0",
      "storageBytesStatus": "UP_TO_DATE",
      "selfLink": "https://www.googleapis.com/compute/v1/projects/my-project/global/snapshots/amtest-backup-data1-us-central1-c-20200917183856-n2ipabzb",
      "labelFingerprint": "23WmSpB8rSM=",
      "storageLocations": [
        "us-central1"
      ],
      "autoCreated": true,
      "downloadBytes": "456717",
      "kind": "compute#snapshot"
    }

From this information, I need to find out what is the VM which is associated with this snapshot. How can I find out the compute engine for which this snapshot is created? Is there any REST API for finding the compute engine from the snapshot?

halfer
  • 19,824
  • 17
  • 99
  • 186
user1403505
  • 895
  • 2
  • 19
  • 42
  • 1
    It already showed on "sourceDisk" part on the response you got. In your case, it shows that the source instance is backup-data1. Is this what you are looking for? – Alex G Oct 01 '20 at 09:39
  • Thanks, i am not much aware of that in GCP, yes i wanted to get the vm name from the snapshot, so if the sourceDisk gives the VM Name and not any other name that is what i require then – user1403505 Oct 01 '20 at 12:29

1 Answers1

1

There is a little misunderstanding here: You snapshot a disk, not a VM. Indeed, you can detach the disk and attach it to another VM. You can also set the disk in multi-reader and attach it to several VM.

So, your question is wrong. You can list, among all your VM, the disk attache to them. Then check if a snapshot exists for each of these disks.

guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76
  • Hi Thanks for this information, is there any api from which I can get the snapshots by passing the source disk like https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a/disks/testdisk. – user1403505 Oct 01 '20 at 16:14
  • I tried with the filter parameter and I didn't succeed – guillaume blaquiere Oct 02 '20 at 19:30