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())); } }
public void releaseEIP(List<String> instanceIds) { logger.info("release EIP for instances, instanceIds={}", instanceIds); DescribeAddressesResult result = ec2.describeAddresses(new DescribeAddressesRequest().withFilters(new Filter("instance-id").withValues(instanceIds))); for (Address address : result.getAddresses()) { logger.info("release EIP, ip={}, instanceId={}", address.getPublicIp(), address.getInstanceId()); ec2.disassociateAddress(new DisassociateAddressRequest().withAssociationId(address.getAssociationId())); ec2.releaseAddress(new ReleaseAddressRequest().withAllocationId(address.getAllocationId())); } }
public void disassociateAddress(AwsProcessClient awsProcessClient, Long instanceNo, Long addressNo, Address address) { AwsAddress awsAddress = awsAddressDao.read(addressNo); // アドレスの切り離し DisassociateAddressRequest request = new DisassociateAddressRequest(); // VPCの場合 if (BooleanUtils.isTrue(awsProcessClient.getPlatformAws().getVpc())) { // 関連付けIDを指定する request.withAssociationId(address.getAssociationId()); } // 非VPCの場合 else { request.withPublicIp(awsAddress.getPublicIp()); } awsProcessClient.getEc2Client().disassociateAddress(request); // ログ出力 if (log.isInfoEnabled()) { log.info(MessageUtils.getMessage("IPROCESS-100132", awsAddress.getPublicIp(), awsAddress.getInstanceId())); } //イベントログ出力 Instance instance = instanceDao.read(instanceNo); processLogger.debug(null, instance, "AwsElasticIpDisassociate", new Object[] { awsAddress.getInstanceId(), awsAddress.getPublicIp() }); // データベースの更新 awsAddress.setInstanceId(null); awsAddressDao.update(awsAddress); }
@Override public void disassociateAddress(DisassociateAddressRequest disassociateAddressRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); }
public static void disassociateAddress(AmazonEC2 ec2, Address address) { String associationId = address.getAssociationId(); DisassociateAddressRequest disassociateAddressRequest = new DisassociateAddressRequest(); disassociateAddressRequest.setAssociationId(associationId); ec2.disassociateAddress(disassociateAddressRequest); }