Example usage for com.amazonaws.services.ec2.model CreateVolumeRequest withSnapshotId

List of usage examples for com.amazonaws.services.ec2.model CreateVolumeRequest withSnapshotId

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2.model CreateVolumeRequest withSnapshotId.

Prototype


public CreateVolumeRequest withSnapshotId(String snapshotId) 

Source Link

Document

The snapshot from which to create the volume.

Usage

From source file:com.urbancode.terraform.tasks.aws.helpers.AWSHelper.java

License:Apache License

/**
 *
 * @param availabilityZone -//ww  w .ja  v  a2 s. c om
 * @param size - size (in Gb) of the volume to be created. Must be larger than snapshot if used
 * @param snapshotId - optional if you want to create from a snapshot
 * @param ec2Client
 * @return volumeId - the id of the newly created volume
 */
public String createEbsVolume(String availabilityZone, int size, String snapshotId, AmazonEC2 ec2Client) {
    CreateVolumeRequest request = new CreateVolumeRequest().withAvailabilityZone(availabilityZone)
            .withSize(size);

    // Only create from a snapshot if the snapshotId is not null, otherwise make new volume
    if (snapshotId != null && !snapshotId.equals("")) {
        request = request.withSnapshotId(snapshotId);
    }

    CreateVolumeResult result = ec2Client.createVolume(request);
    String volumeId = result.getVolume().getVolumeId();

    return volumeId;
}

From source file:com.zotoh.cloudapi.aws.EBSVolume.java

License:Open Source License

@Override
public String create(String snapId, int sizeGB, String zone) throws InternalException, CloudException {
    tstEStrArg("datacenter/zone", zone);
    tstPosIntArg("sizeGB", sizeGB);
    CreateVolumeRequest req = new CreateVolumeRequest().withAvailabilityZone(zone).withSize(sizeGB);
    if (!isEmpty(snapId)) {
        req.withSnapshotId(snapId);
    }/*from w w w. j  a v a  2  s .  com*/
    CreateVolumeResult res = _svc.getCloud().getEC2().createVolume(req);
    com.amazonaws.services.ec2.model.Volume v = res == null ? null : res.getVolume();
    return v == null ? null : v.getVolumeId();
}

From source file:jp.primecloud.auto.process.aws.AwsVolumeProcess.java

License:Open Source License

public void createVolume(AwsProcessClient awsProcessClient, Long instanceNo, Long volumeNo) {
    AwsVolume awsVolume = awsVolumeDao.read(volumeNo);
    AwsInstance awsInstance = awsInstanceDao.read(instanceNo);

    // ??//from  w  w  w. j  a va 2s .  c o  m
    CreateVolumeRequest request = new CreateVolumeRequest();
    request.withSize(awsVolume.getSize());
    request.withSnapshotId(awsVolume.getSnapshotId());
    request.withAvailabilityZone(awsInstance.getAvailabilityZone());

    String volumeType = Config.getProperty("aws.volumeType");
    if (StringUtils.isNotEmpty(volumeType)) {
        request.withVolumeType(volumeType);
    }

    CreateVolumeResult result = awsProcessClient.getEc2Client().createVolume(request);
    Volume volume = result.getVolume();

    String volumeId = volume.getVolumeId();

    // 
    if (log.isInfoEnabled()) {
        log.info(MessageUtils.getMessage("IPROCESS-100121", volumeId));
    }

    //
    Component component = null;
    if (awsVolume.getComponentNo() != null) {
        component = componentDao.read(awsVolume.getComponentNo());
    }
    Instance instance = instanceDao.read(instanceNo);
    processLogger.debug(component, instance, "AwsEbsCreate",
            new Object[] { awsProcessClient.getPlatform().getPlatformName() });

    // 
    awsVolume.setVolumeId(volume.getVolumeId());
    awsVolume.setStatus(volume.getState());
    awsVolumeDao.update(awsVolume);
}

From source file:net.roboconf.target.ec2.internal.Ec2MachineConfigurator.java

License:Apache License

/**
 * Creates volume for EBS.// w  w  w .  j  a  v a  2s . c  o m
 * @return volume ID of newly created volume
 */
private String createVolume(String storageId, String snapshotId, int size) {
    String volumeType = Ec2IaasHandler.findStorageProperty(this.targetProperties, storageId,
            VOLUME_TYPE_PREFIX);
    if (volumeType == null)
        volumeType = "standard";

    CreateVolumeRequest createVolumeRequest = new CreateVolumeRequest()
            .withAvailabilityZone(this.availabilityZone).withVolumeType(volumeType).withSize(size); // The size of the volume, in gigabytes.

    // EC2 snapshot IDs start with "snap-"...
    if (!Utils.isEmptyOrWhitespaces(snapshotId) && snapshotId.startsWith("snap-"))
        createVolumeRequest.withSnapshotId(snapshotId);

    CreateVolumeResult createVolumeResult = this.ec2Api.createVolume(createVolumeRequest);
    return createVolumeResult.getVolume().getVolumeId();
}