Introduced the "allocationId" to EC2's notion of an IP Address so that the describeAddresssesInRegion method of the IP Client will contain this information.

This commit is contained in:
Gary Teichrow 2024-03-24 14:45:15 -07:00
parent bc43572d65
commit a706e9308e
4 changed files with 45 additions and 4 deletions

View File

@ -34,13 +34,15 @@ public class PublicIpInstanceIdPair implements Comparable<PublicIpInstanceIdPair
private final String region;
@Nullable
private final String instanceId;
private final String allocationId;
private final String publicIp;
private final Map<String, String> tags;
public PublicIpInstanceIdPair(final String region, final String publicIp, @Nullable final String instanceId,
@Nullable final Map<String, String> tags) {
@Nullable final String allocationId, @Nullable final Map<String, String> tags) {
this.region = checkNotNull(region, "region");
this.instanceId = instanceId;
this.allocationId = allocationId;
this.publicIp = checkNotNull(publicIp, "publicIp");
this.tags = tags == null ? ImmutableMap.<String, String> of() : ImmutableMap.copyOf(tags);
}
@ -71,6 +73,13 @@ public class PublicIpInstanceIdPair implements Comparable<PublicIpInstanceIdPair
return instanceId;
}
/**
* The ID of the IP allocation (e.g., eipalloc-0ca038968f2a2c986).
*/
public String getAllocationId() {
return allocationId;
}
/**
* The public IP address.
*/
@ -87,6 +96,7 @@ public class PublicIpInstanceIdPair implements Comparable<PublicIpInstanceIdPair
final int prime = 31;
int result = 1;
result = prime * result + ((instanceId == null) ? 0 : instanceId.hashCode());
result = prime * result + ((allocationId == null) ? 0 : allocationId.hashCode());
result = prime * result + ((publicIp == null) ? 0 : publicIp.hashCode());
result = prime * result + ((region == null) ? 0 : region.hashCode());
result = prime * result + ((tags == null) ? 0 : tags.hashCode());
@ -107,6 +117,11 @@ public class PublicIpInstanceIdPair implements Comparable<PublicIpInstanceIdPair
return false;
} else if (!instanceId.equals(other.instanceId))
return false;
if (allocationId == null) {
if (other.allocationId != null)
return false;
} else if (!allocationId.equals(other.allocationId))
return false;
if (publicIp == null) {
if (other.publicIp != null)
return false;

View File

@ -144,6 +144,28 @@ public interface ElasticIPAddressApi {
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
@FormParam("PublicIp") String publicIp);
/**
* Releases an elastic IP address associated with your identity.
*
* @param region
* Elastic IP addresses are tied to a Region and cannot be mapped across Regions.
* @param allocationId
* The Allocation ID (e.g., eipalloc-0ca038968f2a2c986) of the IP address that you are releasing from your identity.
*
* @see #allocateAddress
* @see #describeAddresses
* @see #associateAddress
* @see #disassociateAddress
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-ReleaseAddress.html"
*/
@Named("ReleaseAddress")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ReleaseAddress")
void releaseAddressInRegionByAllocationId(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
@FormParam("AllocationId") String allocationId);
/**
* Lists elastic IP addresses assigned to your identity or provides information about a specific
* address.

View File

@ -44,6 +44,7 @@ public class DescribeAddressesResponseHandler extends HandlerForGeneratedRequest
@Inject
@Region
Supplier<String> defaultRegion;
private String allocationId;
private String instanceId;
private final TagSetHandler tagSetHandler;
private boolean inTagSet;
@ -80,14 +81,17 @@ public class DescribeAddressesResponseHandler extends HandlerForGeneratedRequest
ipAddress = currentOrNull();
} else if (qName.equals("instanceId")) {
instanceId = currentOrNull();
} else if (qName.equals("allocationId")) {
allocationId = currentOrNull();
} else if (qName.equals("item")) {
String region = AWSUtils.findRegionInArgsOrNull(getRequest());
if (region == null)
region = defaultRegion.get();
pairs.add(new PublicIpInstanceIdPair(region, ipAddress, instanceId, tagResults));
pairs.add(new PublicIpInstanceIdPair(region, ipAddress, instanceId, allocationId, tagResults));
ipAddress = null;
instanceId = null;
allocationId = null;
tagResults = null;
}

View File

@ -41,7 +41,7 @@ public class LoadPublicIpForInstanceOrNullTest {
expect(client.getElasticIPAddressApi()).andReturn((Optional) Optional.of(ipClient)).atLeastOnce();
expect(ipClient.describeAddressesInRegion("region")).andReturn(
ImmutableSet.<PublicIpInstanceIdPair> of(new PublicIpInstanceIdPair("region", "1.1.1.1", "i-blah", null)))
ImmutableSet.<PublicIpInstanceIdPair> of(new PublicIpInstanceIdPair("region", "1.1.1.1", "i-blah", null, null)))
.atLeastOnce();
replay(client);
@ -85,7 +85,7 @@ public class LoadPublicIpForInstanceOrNullTest {
expect(client.getElasticIPAddressApi()).andReturn((Optional) Optional.of(ipClient)).atLeastOnce();
expect(ipClient.describeAddressesInRegion("region")).andReturn(
ImmutableSet.<PublicIpInstanceIdPair> of(new PublicIpInstanceIdPair("region", "1.1.1.1", null, null)))
ImmutableSet.<PublicIpInstanceIdPair> of(new PublicIpInstanceIdPair("region", "1.1.1.1", null, null, null)))
.atLeastOnce();
replay(client);