use of software.amazon.awssdk.services.ec2.model.ReleaseAddressRequest in project photon-model by vmware.
the class AWSRemoteCleanup method deleteNetworkInterfaces.
private void deleteNetworkInterfaces(String vpcId, AmazonEC2 usEastEc2Client) {
DescribeNetworkInterfacesRequest networkInterfacesRequest = new DescribeNetworkInterfacesRequest().withFilters(new Filter(VPC_KEY, Collections.singletonList(vpcId)));
DescribeNetworkInterfacesResult networkInterfacesResult = usEastEc2Client.describeNetworkInterfaces(networkInterfacesRequest);
networkInterfacesResult.getNetworkInterfaces().forEach(networkInterface -> {
DescribeAddressesRequest addressesRequest = new DescribeAddressesRequest().withFilters(new Filter(NETWORK_INTERFACE_KEY, Collections.singletonList(networkInterface.getNetworkInterfaceId())));
DescribeAddressesResult addressResult = usEastEc2Client.describeAddresses(addressesRequest);
addressResult.getAddresses().forEach(address -> {
// There is no hardcore dependency on EIP, but we may run out of addresses and
// would be good to disassociate followed by releasing them.
DisassociateAddressRequest disassociateAddressRequest = new DisassociateAddressRequest().withAssociationId(address.getAssociationId());
usEastEc2Client.disassociateAddress(disassociateAddressRequest);
ReleaseAddressRequest releaseAddressRequest = new ReleaseAddressRequest().withAllocationId(address.getAllocationId());
usEastEc2Client.releaseAddress(releaseAddressRequest);
});
// Deleting Network Interfaces
DeleteNetworkInterfaceRequest deleteNetworkInterfaceRequest = new DeleteNetworkInterfaceRequest().withNetworkInterfaceId(networkInterface.getNetworkInterfaceId());
this.host.log("Terminating stale NIC: %s", networkInterface.getNetworkInterfaceId());
usEastEc2Client.deleteNetworkInterface(deleteNetworkInterfaceRequest);
});
}
use of software.amazon.awssdk.services.ec2.model.ReleaseAddressRequest in project photon-model by vmware.
the class AWSNetworkClient method releaseElasticIPAddress.
/**
* Release an elastic IP address
*/
public DeferredResult<Void> releaseElasticIPAddress(String allocationId) {
ReleaseAddressRequest req = new ReleaseAddressRequest().withAllocationId(allocationId);
String message = "Release AWS Elastic IP Address with allocation id [" + allocationId + "].";
AWSDeferredResultAsyncHandler<ReleaseAddressRequest, ReleaseAddressResult> handler = new AWSDeferredResultAsyncHandler<>(this.service, message);
this.client.releaseAddressAsync(req, handler);
return handler.toDeferredResult().thenApply(ignore -> null);
}
use of software.amazon.awssdk.services.ec2.model.ReleaseAddressRequest in project aws-doc-sdk-examples by awsdocs.
the class ReleaseAddress method releaseEC2Address.
// snippet-start:[ec2.java2.release_instance.main]
public static void releaseEC2Address(Ec2Client ec2, String allocId) {
try {
ReleaseAddressRequest request = ReleaseAddressRequest.builder().allocationId(allocId).build();
ReleaseAddressResponse response = ec2.releaseAddress(request);
System.out.printf("Successfully released elastic IP address %s", allocId);
} catch (Ec2Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.ec2.model.ReleaseAddressRequest in project aws-doc-sdk-examples by awsdocs.
the class ReleaseAddress method main.
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);
}
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);
}
use of software.amazon.awssdk.services.ec2.model.ReleaseAddressRequest in project cloudbreak by hortonworks.
the class AwsResourceConnector method releaseReservedIp.
private void releaseReservedIp(AmazonEC2 client, Iterable<CloudResource> resources) {
CloudResource elasticIpResource = getReservedIp(resources);
if (elasticIpResource != null && elasticIpResource.getName() != null) {
Address address;
try {
DescribeAddressesResult describeResult = client.describeAddresses(new DescribeAddressesRequest().withAllocationIds(elasticIpResource.getName()));
address = describeResult.getAddresses().get(0);
} catch (AmazonServiceException e) {
if (e.getErrorMessage().equals("The allocation ID '" + elasticIpResource.getName() + "' does not exist")) {
LOGGER.warn("Elastic IP with allocation ID '{}' not found. Ignoring IP release.", elasticIpResource.getName());
return;
} else {
throw e;
}
}
if (address.getAssociationId() != null) {
client.disassociateAddress(new DisassociateAddressRequest().withAssociationId(elasticIpResource.getName()));
}
client.releaseAddress(new ReleaseAddressRequest().withAllocationId(elasticIpResource.getName()));
}
}
Aggregations