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

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

Introduction

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

Prototype


public String getDeviceName() 

Source Link

Document

The device name (for example, /dev/sdh or xvdh).

Usage

From source file:com.cloudera.director.aws.ec2.EC2Provider.java

License:Apache License

/**
 * Selects the root device from a list of block device mappings based on the
 * root device name for the mappings' image.
 *
 * @param mappings list of block device mappings
 * @param rootDeviceName image root device name
 * @return root device mapping, or null if it could not be determined
 *//*from www.  j ava 2  s  .c o m*/
@VisibleForTesting
static BlockDeviceMapping selectRootDevice(List<BlockDeviceMapping> mappings, String rootDeviceName) {
    /*
     * Heuristic to find the root device:
     * - The best match is the EBS device that matches the root device name for the image, but
     *   this may not happen (/dev/sda1 vs. /dev/sda). See:
     *   http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/device_naming.html
     * - If there isn't a best match, then a device whose name is a prefix for the image's root
     *   device name is selected.
     * - If all else fails, it's the first EBS volume in the list.
     */
    BlockDeviceMapping bestMatch = null;
    BlockDeviceMapping firstEbs = null;
    for (BlockDeviceMapping mapping : mappings) {
        if (mapping.getEbs() == null) {
            continue;
        }
        if (firstEbs == null) {
            firstEbs = mapping;
        }
        if (mapping.getDeviceName() == null) {
            continue;
        }
        if (rootDeviceName.equals(mapping.getDeviceName())) {
            return mapping;
        }
        if (rootDeviceName.startsWith(mapping.getDeviceName())) {
            bestMatch = mapping;
        }
    }

    if (bestMatch != null) {
        return bestMatch;
    } else if (firstEbs != null) {
        return firstEbs;
    } else {
        return null;
    }

}

From source file:hudson.plugins.ec2.SlaveTemplate.java

License:Open Source License

private void setupEphemeralDeviceMapping(RunInstancesRequest riRequest) {

    final List<BlockDeviceMapping> oldDeviceMapping = getAmiBlockDeviceMappings();

    final Set<String> occupiedDevices = new HashSet<String>();
    for (final BlockDeviceMapping mapping : oldDeviceMapping) {

        occupiedDevices.add(mapping.getDeviceName());
    }/*from  ww w.  j  ava 2 s  . com*/

    final List<String> available = new ArrayList<String>(
            Arrays.asList("ephemeral0", "ephemeral1", "ephemeral2", "ephemeral3"));

    final List<BlockDeviceMapping> newDeviceMapping = new ArrayList<BlockDeviceMapping>(4);
    for (char suffix = 'b'; suffix <= 'z' && !available.isEmpty(); suffix++) {

        final String deviceName = String.format("/dev/xvd%s", suffix);

        if (occupiedDevices.contains(deviceName))
            continue;

        final BlockDeviceMapping newMapping = new BlockDeviceMapping().withDeviceName(deviceName)
                .withVirtualName(available.get(0));

        newDeviceMapping.add(newMapping);
        available.remove(0);
    }

    riRequest.withBlockDeviceMappings(newDeviceMapping);
}

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 . ja 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;
}

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

License:Open Source License

protected List<BlockDeviceMapping> createInstanceStoreBlockDeviceMappings(AwsProcessClient awsProcessClient,
        ImageAws imageAws, AwsInstance awsInstance, com.amazonaws.services.ec2.model.Image image) {
    int count = AwsInstanceTypeDefinition.getInstanceStoreCount(awsInstance.getInstanceType());
    if (count == 0) {
        return null;
    }/*from ww  w.  java  2  s  .c  om*/

    // ????????????????
    String maxInstanceStore = Config.getProperty("aws.maxInstanceStore");
    if (StringUtils.isNotEmpty(maxInstanceStore)) {
        int max = Integer.parseInt(maxInstanceStore);
        if (count > max) {
            count = max;
        }
    }

    // ?BlockDeviceMapping????
    Set<String> deviceNames = new HashSet<String>();
    for (BlockDeviceMapping mapping : image.getBlockDeviceMappings()) {
        deviceNames.add(mapping.getDeviceName());
    }

    List<BlockDeviceMapping> mappings = new ArrayList<BlockDeviceMapping>();
    for (int i = 0; i < count; i++) {
        String virtualName = "ephemeral" + i;

        // ?BlockDeviceMapping????????
        boolean exist = false;
        for (BlockDeviceMapping mapping : image.getBlockDeviceMappings()) {
            if (virtualName.equals(mapping.getVirtualName())) {
                exist = true;
                break;
            }
        }
        if (exist) {
            continue;
        }

        // ?????????
        String identifier = null;
        for (int j = 0; j < 25; j++) {
            char id = (char) ('b' + j);
            if (!deviceNames.contains("/dev/sd" + id) && !deviceNames.contains("xvd" + id)) {
                identifier = String.valueOf(id);
                break;
            }
        }

        if (identifier == null) {
            // b ? z ??????????????
            continue;
        }

        String deviceName;
        if (StringUtils.equals(image.getPlatform(), PlatformValues.Windows.toString())) {
            deviceName = "xvd" + identifier;
        } else {
            deviceName = "/dev/sd" + identifier;
        }

        BlockDeviceMapping mapping = new BlockDeviceMapping();
        mapping.withVirtualName(virtualName);
        mapping.withDeviceName(deviceName);
        mappings.add(mapping);

        deviceNames.add(deviceName);
    }

    return mappings;
}

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

License:BSD License

private void writeBlockDeviceMapping(BlockDeviceMapping device) throws XMLStreamException {
    startElement("device");

    attribute("name", device.getDeviceName());

    EbsBlockDevice ebs = device.getEbs();
    if (ebs != null) {

        attribute("shapshot-id", ebs.getSnapshotId());
        attribute("delete-on-termination", ebs.getDeleteOnTermination());
        attribute("volume-size", ebs.getVolumeSize());
        attribute("volume-type", ebs.getVolumeType());
        attribute("encrypted", ebs.getEncrypted());
        attribute("iops", ebs.getIops());
    }/*w w  w  .  j  av  a2 s.c  o  m*/

    endElement();

}