Example usage for com.amazonaws.services.ec2.model DeviceType Ebs

List of usage examples for com.amazonaws.services.ec2.model DeviceType Ebs

Introduction

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

Prototype

DeviceType Ebs

To view the source code for com.amazonaws.services.ec2.model DeviceType Ebs.

Click Source Link

Usage

From source file:com.vb.aws.services.compute.ec2.EC2UtilsImpl.java

/**
 * This method returns all EBS root volumes.
 * @return /*  w w  w . j a v  a2 s. com*/
 */
public List<Volume> getAllEBSRootVolumes() {

    List<Instance> allInstances = getAllInstances();
    List<Volume> allEBSRootVolumes = new ArrayList<>();

    for (Instance instance : allInstances) {

        //We need volumes of type only EBS.
        if (instance.getRootDeviceType().equalsIgnoreCase(DeviceType.Ebs.toString())) {
            String rootDeviceName = instance.getRootDeviceName();
            List<InstanceBlockDeviceMapping> instanceBlockDeviceMappings = instance.getBlockDeviceMappings();
            for (InstanceBlockDeviceMapping instanceBlockDeviceMapping : instanceBlockDeviceMappings) {
                if (instanceBlockDeviceMapping.getDeviceName().equalsIgnoreCase(rootDeviceName)) {
                    String volumeId = instanceBlockDeviceMapping.getEbs().getVolumeId();
                    Volume volume = new Volume().withVolumeId(volumeId);
                    allEBSRootVolumes.add(volume);
                }
            }
        }
    }

    System.out.println("INFO: Number of EBS Root Volumes : " + allEBSRootVolumes.size());
    List<String> volumeIds = allEBSRootVolumes.stream().map(e -> e.getVolumeId()).collect(Collectors.toList());
    System.out.println("INFO: EBS Root Volumes : " + volumeIds);

    return allEBSRootVolumes;
}

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

License:Open Source License

protected List<BlockDeviceMapping> createBlockDeviceMappings(AwsProcessClient awsProcessClient,
        ImageAws imageAws, AwsInstance awsInstance) {
    // ??// w ww . jav  a2  s  .  c om
    com.amazonaws.services.ec2.model.Image image = awsCommonProcess.describeImage(awsProcessClient,
            imageAws.getImageId());

    if (image == null) {
        return null;
    }

    // EBS????BlockDeviceMappings???
    if (!image.getRootDeviceType().equals(DeviceType.Ebs.toString())) {
        return null;
    }

    List<BlockDeviceMapping> mappings = new ArrayList<BlockDeviceMapping>();

    // ?BlockDeviceMapping?
    List<BlockDeviceMapping> imageMappings = createImageBlockDeviceMappings(awsProcessClient, imageAws,
            awsInstance, image);
    if (imageMappings != null) {
        mappings.addAll(imageMappings);
    }

    // ?BlockDeviceMapping?
    List<BlockDeviceMapping> instanceStoreMappings = createInstanceStoreBlockDeviceMappings(awsProcessClient,
            imageAws, awsInstance, image);
    if (instanceStoreMappings != null) {
        mappings.addAll(instanceStoreMappings);
    }

    // ?BlockDeviceMapping?
    List<BlockDeviceMapping> additionalMappings = createAdditionalBlockDeviceMappings(awsProcessClient,
            imageAws, awsInstance, image);
    if (additionalMappings != null) {
        mappings.addAll(additionalMappings);
    }

    return mappings;
}