2014-07-23 37 views
0

我的虛擬機在Google雲上出現問題。 我嘗試在java中啓動虛擬機,但我不知道如何從圖像啓動虛擬機。我的意思是我如何設置來源圖像。 我的代碼是:「盤[] initializeParams.sourceImage」Google雲從圖像創建虛擬現實

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()); 

回答