use of com.amazonaws.services.ec2.model.DeleteNetworkInterfaceRequest 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 com.amazonaws.services.ec2.model.DeleteNetworkInterfaceRequest in project photon-model by vmware.
the class TestAWSSetupUtils method deleteNICDirectlyWithEC2Client.
/**
* Delete an AWS Nic by id
*/
public static void deleteNICDirectlyWithEC2Client(AmazonEC2Client client, VerificationHost host, String nicId) {
if (nicId == null) {
return;
}
DeleteNetworkInterfaceRequest deleteNicRequest = new DeleteNetworkInterfaceRequest().withNetworkInterfaceId(nicId);
host.log("Clean-up NIC with id: %s", nicId);
client.deleteNetworkInterface(deleteNicRequest);
}
Aggregations