本文整理汇总了Java中com.amazonaws.services.ec2.model.Address.getAssociationId方法的典型用法代码示例。如果您正苦于以下问题:Java Address.getAssociationId方法的具体用法?Java Address.getAssociationId怎么用?Java Address.getAssociationId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.ec2.model.Address
的用法示例。
在下文中一共展示了Address.getAssociationId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: releaseReservedIp
import com.amazonaws.services.ec2.model.Address; //导入方法依赖的package包/类
private void releaseReservedIp(AmazonEC2Client client, List<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()));
}
}
示例2: createNATGateway
import com.amazonaws.services.ec2.model.Address; //导入方法依赖的package包/类
public NatGateway createNATGateway(String subnetId, String ip) {
logger.info("create nat gateway, subnetId={}, ip={}", subnetId, ip);
List<Address> addresses = AWS.vpc.ec2.describeAddresses(new DescribeAddressesRequest().withPublicIps(ip)).getAddresses();
if (addresses.isEmpty()) throw new Error("cannot find eip, ip=" + ip);
Address address = addresses.get(0);
if (address.getAssociationId() != null) throw new Error("eip must not associated with other resource, ip=" + ip);
CreateNatGatewayRequest request = new CreateNatGatewayRequest()
.withSubnetId(subnetId)
.withAllocationId(address.getAllocationId());
String gatewayId = ec2.createNatGateway(request).getNatGateway().getNatGatewayId();
NatGateway gateway;
while (true) {
Threads.sleepRoughly(Duration.ofSeconds(30));
gateway = describeNATGateway(gatewayId);
String state = gateway.getState();
if ("pending".equals(state)) continue;
if ("available".equals(state)) {
break;
} else {
throw new Error("failed to create nat gateway, gatewayId=" + gatewayId + ", state=" + state);
}
}
return gateway;
}
示例3: disassociateAddress
import com.amazonaws.services.ec2.model.Address; //导入方法依赖的package包/类
public static void disassociateAddress(AmazonEC2 ec2, Address address) {
String associationId = address.getAssociationId();
DisassociateAddressRequest disassociateAddressRequest = new DisassociateAddressRequest();
disassociateAddressRequest.setAssociationId(associationId);
ec2.disassociateAddress(disassociateAddressRequest);
}