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

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

Introduction

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

Prototype

public ReleaseAddressRequest() 

Source Link

Document

Default constructor for ReleaseAddressRequest object.

Usage

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

License:Open Source License

public static void main(String[] args) {
    final String USAGE = "To run this example, supply an allocation ID.\n"
            + "Ex: ReleaseAddress <allocation_id>\n";

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

    String alloc_id = args[0];

    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    ReleaseAddressRequest request = new ReleaseAddressRequest().withAllocationId(alloc_id);

    ReleaseAddressResult response = ec2.releaseAddress(request);

    System.out.printf("Successfully released elastic IP address %s", alloc_id);
}

From source file:com.hpcloud.daas.ec2.AwsConsoleApp.java

License:Open Source License

public static void cleanupPublicIPs() {
    DescribeAddressesResult result = ec2.describeAddresses();
    List<Address> addresses = result.getAddresses();

    for (Address address : addresses) {

        ReleaseAddressRequest releaseReq = new ReleaseAddressRequest();
        releaseReq.setAllocationId(address.getAllocationId());
        releaseReq.setPublicIp(address.getPublicIp());

        if (address.getInstanceId() == null || address.getInstanceId().equals("")) {
            ec2.releaseAddress(releaseReq);
        }/*from ww w  . java2s.  c om*/
    }
}

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

License:Apache License

/**
 * Releases an elastic IP with the given allocation id.
 *
 * @param allocationId/*from  w  ww.j  a  v a 2 s . c  o m*/
 * @param ec2Client
 */
public void releaseElasticIp(String allocationId, AmazonEC2 ec2Client) {
    ReleaseAddressRequest request = new ReleaseAddressRequest().withAllocationId(allocationId);
    ec2Client.releaseAddress(request);
    log.info("Elastic IP with allocation ID = " + allocationId + " released.");
}

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

License:Apache License

/**
 * Cleans up any elastic ips that are not associated with anything (via associationId).
 * The addresses are released./*  w  w  w .j  av  a2 s  .c  o  m*/
 *
 * @param ec2Client
 */
public void cleanupElasticIps(AmazonEC2 ec2Client) {
    DescribeAddressesResult result = ec2Client.describeAddresses();
    List<Address> addresses = result.getAddresses();
    if (addresses != null) {
        for (Address address : addresses) {
            if (address.getAssociationId() != null && !address.getAssociationId().equals("")) {
                ReleaseAddressRequest request = new ReleaseAddressRequest()
                        .withAllocationId(address.getAllocationId());
                ec2Client.releaseAddress(request);
            }
        }
    }
}

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

License:Open Source License

@Override
public void releaseFromPool(String addr) throws InternalException, CloudException {
    tstEStrArg("public-ip", addr);
    _svc.getCloud().getEC2().releaseAddress(new ReleaseAddressRequest().withPublicIp(addr));
}

From source file:ec2.ReleaseAddress.java

License:Open Source License

public static void main(String[] args) {

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

    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);//from   w  w w  .  j a v  a2s. c om
    }

    String allocationId = args[0];

    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    ReleaseAddressRequest request = new ReleaseAddressRequest().withAllocationId(allocationId);

    ReleaseAddressResult response = ec2.releaseAddress(request);

    System.out.printf("Successfully released elastic IP address %s", allocationId);
}

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

License:Open Source License

/**
 * TODO: //from  www .j  a  va 2s.c  om
 * 
 * @param awsProcessClient
 * @param addressNo
 */
public void deleteAddress(AwsProcessClient awsProcessClient, Long addressNo) {
    // AWS??
    AwsAddress awsAddress = awsAddressDao.read(addressNo);
    if (awsAddress == null) {
        return;
    }

    // Elastic IP??
    if (StringUtils.isEmpty(awsAddress.getPublicIp())) {
        // Elastic IP??AWS??
        awsAddressDao.delete(awsAddress);
        return;
    }

    // Elastic IP
    try {
        ReleaseAddressRequest request = new ReleaseAddressRequest();

        // VPC??
        if (BooleanUtils.isTrue(awsProcessClient.getPlatformAws().getVpc())) {
            // ?ID??
            Address address = awsCommonProcess.describeAddress(awsProcessClient, awsAddress.getPublicIp());
            request.withAllocationId(address.getAllocationId());
        }
        // ?VPC??
        else {
            request.withPublicIp(awsAddress.getPublicIp());
        }

        awsProcessClient.getEc2Client().releaseAddress(request);

        // 
        processLogger.debug(null, null, "AwsElasticIpRelease",
                new Object[] { awsProcessClient.getPlatform().getPlatformName(), awsAddress.getPublicIp() });

    } catch (Exception ignore) {
        // Elastic IP???????????????????
        log.warn(ignore.getMessage());
    }

    // AWS
    awsAddressDao.delete(awsAddress);
}