Example usage for com.amazonaws.services.ec2.model AllocateAddressRequest AllocateAddressRequest

List of usage examples for com.amazonaws.services.ec2.model AllocateAddressRequest AllocateAddressRequest

Introduction

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

Prototype

AllocateAddressRequest

Source Link

Usage

From source file:aws.example.ec2.AllocateAddress.java

License:Open Source License

public static void main(String[] args) {
    final String USAGE = "To run this example, supply an instance id\n" + "Ex: AllocateAddress <instance_id>\n";

    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);//from   ww w.  jav  a 2s. c  om
    }

    String instance_id = args[0];

    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    AllocateAddressRequest allocate_request = new AllocateAddressRequest().withDomain(DomainType.Vpc);

    AllocateAddressResult allocate_response = ec2.allocateAddress(allocate_request);

    String allocation_id = allocate_response.getAllocationId();

    AssociateAddressRequest associate_request = new AssociateAddressRequest().withInstanceId(instance_id)
            .withAllocationId(allocation_id);

    AssociateAddressResult associate_response = ec2.associateAddress(associate_request);

    System.out.printf("Successfully associated Elastic IP address %s " + "with instance %s",
            associate_response.getAssociationId(), instance_id);
}

From source file:com.urbancode.terraform.tasks.aws.helpers.AWSHelper.java

License:Apache License

/**
 * This will request a new elastic IP from Amazon and return the AllocationId
 * associated with that new elasticIp.//  w w w  .ja v  a 2  s.c  o m
 *
 * @param ec2Client
 * @return allocationId
 */
public String requestElasticIp(AmazonEC2 ec2Client) {
    String result = null;
    ;

    AllocateAddressRequest allReq = new AllocateAddressRequest().withDomain(DomainType.Vpc);
    AllocateAddressResult allRes = ec2Client.allocateAddress(allReq);
    result = allRes.getAllocationId();

    log.info("Elastic Ip allocated: " + allRes.getPublicIp());
    log.info("Allocation Id: " + result);

    return result;
}

From source file:com.zotoh.cloudapi.aws.ElasticIP.java

License:Open Source License

@Override
public String request(AddressType t) throws InternalException, CloudException {
    if (!AddressType.PUBLIC.equals(t)) {
        throw new IllegalArgumentException("Expecting type: PUBLIC, got: " + t);
    }/*  w w  w  .  java 2 s  . co  m*/
    String rg = _svc.getCloud().getContext().getRegionId();
    _svc.getCloud().setAWSSite(rg);
    AllocateAddressResult res = _svc.getCloud().getEC2().allocateAddress(new AllocateAddressRequest());
    return res == null ? null : res.getPublicIp();
}

From source file:ec2.AllocateAddress.java

License:Open Source License

public static void main(String[] args) {

    final String USAGE = "To run this example, supply an instance id\n" + "Ex: AllocateAddress <instance-id>\n";

    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);/*from   www . j  a va2s . c o m*/
    }

    String instanceId = args[0];

    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    AllocateAddressRequest allocateAddressRequest = new AllocateAddressRequest().withDomain(DomainType.Vpc);

    AllocateAddressResult allocateAddressResponsee = ec2.allocateAddress(allocateAddressRequest);

    String allocationId = allocateAddressResponsee.getAllocationId();

    AssociateAddressRequest request = new AssociateAddressRequest().withInstanceId(instanceId)
            .withAllocationId(allocationId);

    AssociateAddressResult response = ec2.associateAddress(request);

    System.out.printf("Successfully associated elastic ip address %s with instance %s",
            response.getAssociationId(), instanceId);
}

From source file:jp.primecloud.auto.aws.typica.EucaEc2Client.java

License:Open Source License

@Override
public AllocateAddressResult allocateAddress() {
    return allocateAddress(new AllocateAddressRequest());
}

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

License:Open Source License

/**
 * TODO: /*from w w w.ja  v a  2 s . com*/
 * 
 * @param awsProcessClient
 * @return
 */
public AwsAddress createAddress(AwsProcessClient awsProcessClient) {
    // Elastic IP??
    AllocateAddressRequest request = new AllocateAddressRequest();
    if (BooleanUtils.isTrue(awsProcessClient.getPlatformAws().getVpc())) {
        request.withDomain(DomainType.Vpc);
    }

    String publicIp;
    try {
        AllocateAddressResult result = awsProcessClient.getEc2Client().allocateAddress(request);
        publicIp = result.getPublicIp();

    } catch (AutoException e) {
        // Elastic IP?????
        if (e.getCause() instanceof AmazonServiceException
                && "AddressLimitExceeded".equals(((AmazonServiceException) e.getCause()).getErrorCode())) {
            throw new AutoApplicationException("EPROCESS-000134");
        }

        throw e;
    }

    // 
    processLogger.debug(null, null, "AwsElasticIpAllocate",
            new Object[] { awsProcessClient.getPlatform().getPlatformName(), publicIp });

    // AWS?
    AwsAddress awsAddress = new AwsAddress();
    awsAddress.setUserNo(awsProcessClient.getUserNo());
    awsAddress.setPlatformNo(awsProcessClient.getPlatform().getPlatformNo());
    awsAddress.setPublicIp(publicIp);
    awsAddress.setComment("Allocate at " + DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
    awsAddressDao.create(awsAddress);

    return awsAddress;
}