Announcements
This site is in read only until July 22 as we migrate to a new platform; refer to this community post for more details.
Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Create similar VM from API to multiple users

Based on this option

https://cloud.google.com/compute/docs/instances/create-vm-from-similar-instance

 

Is there a way to clone or copy a VM using API?

I need to assign multiple users a VM similar than the one I work it, and we are trying to do this from firebase app with the google API. But can't find the API or console option for this.

Thanks.

Solved Solved
0 3 246
1 ACCEPTED SOLUTION

All the commands that can be executed by the gcloud command line tool can also be executed by API.  This means that if we can find a recipe using gcloud, we can do the same thing using API.  It looks like we can use

gcloud compute disk snapshot

to create a snapshot of a VM disk.  Once we have a snapshot, we can create a new VM disk using that as a base image using:

gcloud compute disks create --souce-snapshot

when you create your new VM, you can then use this newly created disk as the attached disk to your VM and we should have achieved the goal.

View solution in original post

3 REPLIES 3

I think the trick to this puzzle will be to ask "What does it mean to create a VM similar to the one I have".  From what I glean reading the page, it seems that the new VM will basically be one that is created with similar/identical configuration to the one you already have.  Since there are APIs and command line tools that can retrieve the configuration of one VM and create a new VM with arbitrary configurations, it would appear that the solution would be use two APIs. One to query a VMs current settings and a second API to create a new VM with specific settings.

Not just the configuration, but what the user have done in it. Every software installed and SO changes. We want to clone the VM and give it to someone else.

All the commands that can be executed by the gcloud command line tool can also be executed by API.  This means that if we can find a recipe using gcloud, we can do the same thing using API.  It looks like we can use

gcloud compute disk snapshot

to create a snapshot of a VM disk.  Once we have a snapshot, we can create a new VM disk using that as a base image using:

gcloud compute disks create --souce-snapshot

when you create your new VM, you can then use this newly created disk as the attached disk to your VM and we should have achieved the goal.