Example usage for com.amazonaws.services.ec2.model EbsInstanceBlockDevice getVolumeId

List of usage examples for com.amazonaws.services.ec2.model EbsInstanceBlockDevice getVolumeId

Introduction

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

Prototype


public String getVolumeId() 

Source Link

Document

The ID of the EBS volume.

Usage

From source file:com.netflix.simianarmy.client.aws.AWSClient.java

License:Apache License

@Override
public List<String> listAttachedVolumes(String instanceId, boolean includeRoot) {
    Validate.notEmpty(instanceId);/*from ww  w.  j  ava 2  s .c  o m*/
    LOGGER.info(String.format("Listing volumes attached to instance %s in region %s.", instanceId, region));
    try {
        List<String> volumeIds = new ArrayList<String>();
        for (Instance instance : describeInstances(instanceId)) {
            String rootDeviceName = instance.getRootDeviceName();

            for (InstanceBlockDeviceMapping ibdm : instance.getBlockDeviceMappings()) {
                EbsInstanceBlockDevice ebs = ibdm.getEbs();
                if (ebs == null) {
                    continue;
                }

                String volumeId = ebs.getVolumeId();
                if (Strings.isNullOrEmpty(volumeId)) {
                    continue;
                }

                if (!includeRoot && rootDeviceName != null && rootDeviceName.equals(ibdm.getDeviceName())) {
                    continue;
                }

                volumeIds.add(volumeId);
            }
        }
        return volumeIds;
    } catch (AmazonServiceException e) {
        if (e.getErrorCode().equals("InvalidInstanceID.NotFound")) {
            throw new NotFoundException("AWS instance " + instanceId + " not found", e);
        }
        throw e;
    }
}

From source file:org.occiware.clouddriver.util.InstanceDataFactory.java

License:Apache License

/**
 *
 * @param instance// ww  w . ja  v  a 2  s  . co  m
 * @return
 */
private static List<InstanceVolumeDO> BuildInstanceVolumeDOs(Instance instance) {
    List<InstanceBlockDeviceMapping> blockDeviceMappings = instance.getBlockDeviceMappings();
    String deviceName;
    InstanceVolumeDO instVolumeDO;
    EbsInstanceBlockDevice ebs;
    List<InstanceVolumeDO> instanceVolumeDOs = new ArrayList<>();
    for (InstanceBlockDeviceMapping blockDeviceMapping : blockDeviceMappings) {
        deviceName = blockDeviceMapping.getDeviceName();
        ebs = blockDeviceMapping.getEbs();

        if (ebs != null) {
            instVolumeDO = new InstanceVolumeDO();
            instVolumeDO.setAttachTime(ebs.getAttachTime());
            instVolumeDO.setDeleteOnTermination(ebs.getDeleteOnTermination());
            instVolumeDO.setStatus(ebs.getStatus());
            instVolumeDO.setVolumeId(ebs.getVolumeId());
            instVolumeDO.setDeviceName(deviceName);
            instanceVolumeDOs.add(instVolumeDO);
        }

    }
    return instanceVolumeDOs;
}

From source file:org.xmlsh.aws.util.AWSEC2Command.java

License:BSD License

public void writeInstanceDeviceMapping(InstanceBlockDeviceMapping device) throws XMLStreamException {
    startElement("device");
    attribute("name", device.getDeviceName());

    EbsInstanceBlockDevice ebs = device.getEbs();
    attribute("status", ebs.getStatus());
    attribute("volume-id", ebs.getVolumeId());
    attribute("attach-date", Util.formatXSDateTime(ebs.getAttachTime()));
    attribute("delete-on-termination", ebs.getDeleteOnTermination().toString());
    endElement();//w w w .j a v a  2 s .  c o m
}