Hi Ignasi,

Thanks for pointing me in the right direction. This is the proof of code
that I created to create an instance and attach an disk with the
instanceAPI. If anyone sees a way to enhance it please let me know. When I
have some time I will add it to JClouds Examples.

GoogleComputeEngineApi gce = context.unwrapApi(GoogleComputeEngineApi.class);
URI machineType = new
URI("https://www.googleapis.com/compute/v1/projects/soy-sound-613/zones/asia-east1-a/machineTypes/f1-micro";);
URI networkType = new
URI("https://www.googleapis.com/compute/v1/projects/soy-sound-613/global/networks/default";);
URI uriImage = new
URI("https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-1404-trusty-v20150128";);

String INSTANCE_NAME = "test";
NewInstance instance = NewInstance.create(INSTANCE_NAME, machineType,
networkType, uriImage);
InstanceApi instanceApi = gce.instancesInZone("asia-east1-a");
DiskApi diskApi = gce.disksInZone("asia-east1-a");

instanceApi.create(instance);
Instance instanceBuilding = instanceApi.get(INSTANCE_NAME);
while ( instanceBuilding == null || instanceBuilding.status() !=
Instance.Status.RUNNING ){
    if (instanceBuilding == null ) {
        System.out.println("Instance is null. Waiting for it to exist ... ");
    } else {
        System.out.println("Instance not running yet. Status: " +
instanceBuilding.status());
    }
    Thread.sleep(1000);
    instanceBuilding = instanceApi.get(INSTANCE_NAME);

}

String ATTACH_DISK_NAME = "diskname";
URI diskType = new
URI("https://www.googleapis.com/compute/v1/projects/soy-sound-613/zones/asia-east1-a/diskTypes/pd-ssd";);
diskApi.create(ATTACH_DISK_NAME, new
DiskCreationOptions().sizeGb(1).type(diskType));

Disk diskBuilding = diskApi.get(ATTACH_DISK_NAME);
while ( diskBuilding == null || diskBuilding.status() !=  Disk.Status.READY){
    if ( diskBuilding == null ) {
        System.out.println("Disk is null. Waiting for it to exist ... ");
    } else {
        System.out.println("Disk not ready yet. Status: " +
diskBuilding.status());
    }
    Thread.sleep(1000);
    diskBuilding = diskApi.get(ATTACH_DISK_NAME);

}

System.out.println("ATTACHING DISK");
URI diskUrl = new
URI("https://www.googleapis.com/compute/v1/projects/soy-sound-613/zones/asia-east1-a/disks/";
+ ATTACH_DISK_NAME);
instanceApi.attachDisk(INSTANCE_NAME,
        AttachDisk.create(AttachDisk.Type.PERSISTENT, // type
                AttachDisk.Mode.READ_WRITE, // mode
                diskUrl, // source
                "myattacheddisk", // deviceName
                false, // boot
                null, // initializeParams
                true, // autoDelete
                null, // licenses
                null // interface
        ));





On Wed, Feb 18, 2015 at 9:23 PM, Ignasi Barrera <[email protected]> wrote:

> This was discussed on the IRC, but let's make sure the thread gets
> answered.
>
> Currently there is no way to do that using the ComputeService, but the
> GCE provider specific API supports it. The InstanceApi [1] has the
> "create" and "attachDisk" method, that can be used to create instances
> with custom disks and attach disks to existing ones.
>
> The former gets a NewInstance object that has a list of AttachDisk
> objects. There you cans et the size of the disk and their type. The
> same applies to the "attachDisk" method, thich gets an AttachDisk
> object. Using those methods you should be able to create instances
> with custom disks.
>
> If you have the ComputeServiceContext instance, you can get the
> InstanceApi as follows:
>
> GoogleComputeEngineApi gce =
> context.unwrapApi(GoogleComputeEngineApi.class);
> InstanceApi instanceApi = gce.instancesInZone("zone name");
>
>
> HTH!
>
> I.
>
>
> [1]
> https://github.com/jclouds/jclouds-labs-google/blob/master/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/InstanceApi.java
>
> On 16 February 2015 at 04:49, Ruben Rubio Rey <[email protected]> wrote:
> > Hi,
> >
> > I am not able to find any sample in Internet. GCE has Standard Disk and
> SSD
> > disks. I have a few questions.
> >
> >  - When you are creating an instance, how can you choose SSD instead
> > Standard Disk ?
> >  - How can you customize the size of the root volume ?
> >  - How can you add additional volumes ?
> >
> > I hope someone can point me into the right direction.
> >
> > Regards,
> > Ruben
>

Reply via email to