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

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

Introduction

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

Prototype

@Override
    public BlockDeviceMapping clone() 

Source Link

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());
        }/*from ww w  .j  a  v a  2s.  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;
}