Example usage for com.amazonaws.services.ec2.model BlockDeviceMapping withEbs

List of usage examples for com.amazonaws.services.ec2.model BlockDeviceMapping withEbs

Introduction

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

Prototype


public BlockDeviceMapping withEbs(EbsBlockDevice ebs) 

Source Link

Document

Parameters used to automatically set up EBS volumes when the instance is launched.

Usage

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

License:Open Source License

protected List<BlockDeviceMapping> createImageBlockDeviceMappings(AwsProcessClient awsProcessClient,
        ImageAws imageAws, AwsInstance awsInstance, com.amazonaws.services.ec2.model.Image image) {
    // ?BlockDeviceMapping?
    List<BlockDeviceMapping> mappings = new ArrayList<BlockDeviceMapping>();
    for (BlockDeviceMapping originalMapping : image.getBlockDeviceMappings()) {
        BlockDeviceMapping mapping = originalMapping.clone();
        if (originalMapping.getEbs() != null) {
            mapping.withEbs(originalMapping.getEbs().clone());
        }//  w  w  w  .  j a v  a2  s  .  c o m
        mappings.add(mapping);
    }

    for (BlockDeviceMapping mapping : mappings) {
        if (mapping.getEbs() == null) {
            continue;
        }

        // ?EBS?????
        mapping.getEbs().withDeleteOnTermination(true);

        // ???Encrypted??????
        if (StringUtils.isNotEmpty(mapping.getEbs().getSnapshotId())) {
            mapping.getEbs().withEncrypted(null);
        }

        // ?
        String volumeType = Config.getProperty("aws.volumeType");
        if (StringUtils.isNotEmpty(volumeType)) {
            mapping.getEbs().setVolumeType(volumeType);
        }
    }

    // ???
    if (awsInstance.getRootSize() != null) {
        for (BlockDeviceMapping mapping : mappings) {
            if (image.getRootDeviceName().equals(mapping.getDeviceName())) {
                mapping.getEbs().setVolumeSize(awsInstance.getRootSize());
                break;
            }
        }
    }

    return mappings;
}