Google compute engine 谷歌云从图像创建虚拟机

Google compute engine 谷歌云从图像创建虚拟机,google-compute-engine,Google Compute Engine,我在谷歌云上的虚拟机有问题。 我尝试用java启动vm,但我不知道如何从映像启动vm。我的意思是如何设置为源图像。 我的代码是: Instance instance = new Instance(); compute.machineTypes(); String machine = "https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/g1-s

我在谷歌云上的虚拟机有问题。 我尝试用java启动vm,但我不知道如何从映像启动vm。我的意思是如何设置为源图像。 我的代码是:

    Instance instance = new Instance();

    compute.machineTypes();
    String machine = "https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/g1-small";
    instance.setMachineType(machine);

    String name = "newinstance";
    instance.setName(name);
    List<NetworkInterface> networkInterfaces = new ArrayList<NetworkInterface>();
    NetworkInterface iface = new NetworkInterface();
    iface.setName("eth0");

    iface.setNetwork("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default");
    networkInterfaces.add(iface);
    instance.setNetworkInterfaces(networkInterfaces);

    Disk disk = new Disk();
    disk.setSizeGb(10L);
    disk.setName("mydisk");


    Compute.Disks.Insert insDisk = compute.disks().insert(projectId, zoneName, disk);
    insDisk.execute();

    AttachedDisk diskToInsert = new AttachedDisk();
    diskToInsert.setBoot(true);
    diskToInsert.setType("PERSISTENT");
    diskToInsert.setMode("READ_WRITE");
    diskToInsert.setDeviceName("newinstancedisk");
    diskToInsert.setSource("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/" + disk.getName());

    List<AttachedDisk> listOfDisks = new ArrayList<AttachedDisk>();
    listOfDisks.add(diskToInsert);

    instance.setDisks(listOfDisks);

    Compute.Instances.Insert ins = compute.instances().insert(projectId, zoneName, instance);
    Operation op = ins.execute();
    System.out.println(op.toPrettyString());
    System.out.println(instance.toPrettyString());
实例实例=新实例();
compute.machineTypes();
字符串机器=”https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/g1-small";
setMachineType(machine);
String name=“newinstance”;
instance.setName(name);
List networkInterfaces=new ArrayList();
NetworkInterface iface=新的NetworkInterface();
iface.setName(“eth0”);
iface.setNetwork(“https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default");
网络接口。添加(iface);
实例.setNetworkInterfaces(networkInterfaces);
Disk Disk=新磁盘();
磁盘。setSizeGb(10L);
disk.setName(“mydisk”);
Compute.Disks.Insert insDisk=Compute.Disks();
insDisk.execute();
AttachedDiskToInsert=新的AttachedDisk();
diskToInsert.setBoot(true);
diskToInsert.setType(“持久”);
设置模式(“读写”);
diskToInsert.setDeviceName(“newinstancedisk”);
diskToInsert.setSource(“https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/“+disk.getName());
List listOfDisks=new ArrayList();
添加(diskToInsert);
setDisks(listOfDisks);
Compute.Instances.Insert ins=Compute.Instances().Insert(projectId,zoneName,instance);
操作op=ins.execute();
System.out.println(op.toPrettyString());
System.out.println(instance.toPrettyString());

您需要使用选项“disks[].initializeParams.sourceImage”,在该选项中,您可以提供用于创建根磁盘的映像的完整URL

看看这些链接,然后。在最后一个链接中,您可以看到可以为磁盘[]提供的值。initializeParams