public void unbindEIP ( ) throws Exception { InstanceInfo myInfo = applicationInfoManager . getInfo ( ) ; String myPublicIP = null ; if ( myInfo != null && myInfo . getDataCenterInfo ( ) . getName ( ) == Name . Amazon ) { myPublicIP = ( ( AmazonInfo ) myInfo . getDataCenterInfo ( ) ) . get ( MetaDataKey . publicIpv4 ) ; if ( myPublicIP == null ) { logger . info ( "Instance is not associated with an EIP. Will not try to unbind" ) ; return ; } try { AmazonEC2 ec2Service = getEC2Service ( ) ; DescribeAddressesRequest describeAddressRequest = new DescribeAddressesRequest ( ) . withPublicIps ( myPublicIP ) ; DescribeAddressesResult result = ec2Service . describeAddresses ( describeAddressRequest ) ; if ( ( result . getAddresses ( ) != null ) && ( ! result . getAddresses ( ) . isEmpty ( ) ) ) { Address eipAddress = result . getAddresses ( ) . get ( 0 ) ; DisassociateAddressRequest dissociateRequest = new DisassociateAddressRequest ( ) ; String domain = eipAddress . getDomain ( ) ; if ( "vpc" . equals ( domain ) ) { dissociateRequest . setAssociationId ( eipAddress . getAssociationId ( ) ) ; } else { dissociateRequest . setPublicIp ( eipAddress . getPublicIp ( ) ) ; } ec2Service . disassociateAddress ( dissociateRequest ) ; logger . info ( "Dissociated the EIP {} from this instance" , myPublicIP ) ; } } catch ( Throwable e ) { throw new RuntimeException ( "Cannot dissociate address from this instance" , e ) ; } } }
Unbind the EIP that this instance is associated with .