Example usage for com.amazonaws.services.ec2.model Placement withTenancy

List of usage examples for com.amazonaws.services.ec2.model Placement withTenancy

Introduction

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

Prototype


public Placement withTenancy(Tenancy tenancy) 

Source Link

Document

The tenancy of the instance (if the instance is running in a VPC).

Usage

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

License:Apache License

/**
 * Builds a {@code RunInstancesRequest} starting from a template and a set of
 * virtual IDs./*from w w w  .j av a2 s  . co m*/
 *
 * @param template           the instance template
 * @param virtualInstanceIds the virtual instance IDs
 */
@SuppressWarnings("ConstantConditions")
private RunInstancesRequest newRunInstancesRequest(EC2InstanceTemplate template,
        Collection<String> virtualInstanceIds, int minCount) {

    LOG.info(">> Building instance requests");

    int groupSize = virtualInstanceIds.size();
    String image = template.getImage();
    String type = template.getType();

    InstanceNetworkInterfaceSpecification network = getInstanceNetworkInterfaceSpecification(template);

    List<BlockDeviceMapping> deviceMappings = getBlockDeviceMappings(template);

    LOG.info(">> Instance request type: {}, image: {}, group size: {}", type, image, groupSize);

    RunInstancesRequest request = new RunInstancesRequest().withImageId(image).withInstanceType(type)
            .withMaxCount(groupSize).withMinCount(minCount)
            .withClientToken(
                    getHashOfVirtualInstanceIdsForClientToken(virtualInstanceIds, Optional.<Long>absent()))
            .withNetworkInterfaces(network).withBlockDeviceMappings(deviceMappings);

    if (template.getIamProfileName().isPresent()) {
        request.withIamInstanceProfile(
                new IamInstanceProfileSpecification().withName(template.getIamProfileName().get()));
    }

    if (template.getKeyName().isPresent()) {
        request.withKeyName(template.getKeyName().get());
    }

    Placement placement = null;
    if (template.getAvailabilityZone().isPresent()) {
        placement = new Placement().withAvailabilityZone(template.getAvailabilityZone().get());
    }
    if (template.getPlacementGroup().isPresent()) {
        placement = (placement == null) ? new Placement().withGroupName(template.getPlacementGroup().get())
                : placement.withGroupName(template.getPlacementGroup().get());
    }
    placement = (placement == null) ? new Placement().withTenancy(template.getTenancy())
            : placement.withTenancy(template.getTenancy());

    request.withPlacement(placement);

    return request;
}