I have two projects in my developer console. I have taken a \"Snapshot\" of one of the VMs in project-1. I want to create a new VM in project-2 using the snapshot created in
This is click only solution through the browser. What you need? You need to have image. To create image from disk, the disk must be detached from any instance.
What are the steps if you have just instance in Project1:
Create snapshot from the instance in Project1.
Create instance from this snapshot in Project1. Untick "Delete boot
disk when instance is deleted". This instance it's used only for
now and gonna be deleted
Delete the instance that you just created
Go to the "Disks" menu and you must see there the disk from the instance.
Go to "Images" menu -> "Create an image". Here you can create image. If you don't have detached disk you won't have any disk available in the dropdown.
Go to Project 2 and create instance using the custom image that you created for Project 1. How? Boot disk -> change -> Custom images-> Select Project 1-> Here you can see your custom image
You don't need an image or a scratch VM, and you don't have to interrupt the source VM. Just create a snapshot in the source project:
$ gcloud compute --project p1 disks snapshot the-snapshot src-disk --snapshot-names=the-snapshot
Created [https://www.googleapis.com/compute/v1/projects/p1/global/snapshots/the-snapshot].
Then create a disk in the destination project with --source-snapshot
pointing at the 'Created' URL returned above:
$ gcloud compute --project p2 disks create the-disk \
--source-snapshot https://www.googleapis.com/compute/v1/projects/p1/global/snapshots/the-snapshot
This usage was not shown in the gcloud
docs, I found it in @krishna praveen's answer, but his explanation is incorrect; you do not need to delete any instances, or use images. And this works even if both source and destination are boot disks:
$ gcloud compute --project p2 instances create the-vm --disk name=the-disk,boot=yes
If for some reason you require an image, you can still restore a snapshot to a disk and use this to create the image without a scratch VM. This is preferable if a scratch VM would automatically start services on boot which could interfere with other running VMs on the same project network.
$ gcloud compute images create image-1 --source-disk=src-disk-image --source-disk-zone=zone1
This image can now be used from another project (as shown by @jiminikiz above).
$ gcloud compute --project p2 instances create <name-of-new-instance> --image image-1 \
--image-project p1 --zone=zone
Instances can be created across the project using images. Now, if you have an image in Project 1, you can select that in Project 2 as well.
But, as of today, you can't see the disks across the project. If you have to migrate an VM with associated additional disks from Project 1 to Project 2, follow the below.
Use the snapshot and create the disk in Project 2 by connecting the gcloud
command interface.
Connect to Project 2, and then execute:
gcloud compute --project "GCPProject2" disks create "myserver-disk1" --size "50" --zone "us-east1-b" --source-snapshot https://www.googleapis.com/compute/v1/projects/GCPProject1/global/snapshots/snapshot-myserver-disk1 --description "DriveName" --type "pd-standard"
Above will create the disk in Project2. Then you need to delete the instance in Project1 by retaining the boot disk.
Then, create the image from the disk myserver-bootdisk
.
Once the image is created, switch over to Project 2 and then create the server from image, use the dropdown and select the image from Project 1.
Add the additional disk which you have crated from the snapshot and create the VM.
AFAIK, it is not possible. To accomplish what you have described, the best course of action is to use this tutorial. You have a few steps for creating a blank disk, attaching it to the machine in question, tarball the boot partition and upload it to cloud storage. Once that is done, download it locally, switch projects and upload to the other project. You will then be able to just select the machine from the list of Images when clicking on New Instance
The answer posted by @chrispomeroy worked for me, but I was able to simplify it a little as I need to do this more and more.
Let's say you have an image in project-1, and need to create an instance using that image in project-2.
gcloud config set project "project-2"
gcloud compute instances create <name-of-new-instance> \
--image <name-of-your-image-from-project-1> \
--image-project "project-1"
This eliminates the need to worry about using a URL
for anything.
EDIT: My answer pretty much looks like his at this point, but the docs for this stuff is here:
gcloud compute instances create
The solution provided by "chrispomeroy" works fine but require to init gcloud with your personal google user account (instead of the project2 service account) first (since it is the one who has permission to access to both project):
gcloud init (and chose [2] Login with new credentials)
Then you can indeed create the VM on project 2 (from a base image on project 1) with :
gcloud compute instances create testimg --image --image-project (no need for URL) I tested today (nov 2015) and works fine