class Cassandra::AddressResolution::Policies::EC2MultiRegion
This policy resolves private ips of the hosts in the same datacenter and public ips of hosts in other datacenters.
@note Initializing this policy is not necessary, you should just pass
`:ec_multi_region` to the `:address_resolution` option of {Cassandra.cluster}
Public Class Methods
new(resolver = Resolv)
click to toggle source
@private
# File lib/cassandra/address_resolution/policies/ec2_multi_region.rb 30 def initialize(resolver = Resolv) 31 @resolver = resolver 32 end
Public Instance Methods
resolve(address)
click to toggle source
Returns ip address after a double DNS lookup. First, it will get hostname from a given ip, then resolve the resulting hostname. This policy works because AWS public hostnames resolve to a private ip address within the same datacenter.
@param address [IPAddr] node ip address from Cassandra's system table
@return [IPAddr] private ip withing the same datacenter, public ip
otherwise. Returns original address if DNS lookups fail.
# File lib/cassandra/address_resolution/policies/ec2_multi_region.rb 43 def resolve(address) 44 @resolver.each_name(Resolv::DNS::Name.create(address.reverse)) do |name| 45 @resolver.each_address(name) do |addr| 46 return ::IPAddr.new(addr) 47 end 48 end 49 50 # default to original address if reverse DNS lookup failed 51 address 52 end