class ConsulApi::DNS
Public Class Methods
resolve_node(host)
click to toggle source
# File lib/consul_api/dns.rb, line 12 def self.resolve_node(host) resolver.getaddress(host).to_s end
resolve_service(host)
click to toggle source
# File lib/consul_api/dns.rb, line 4 def self.resolve_service(host) srv = [] srv = resolver.getresources(host, Resolv::DNS::Resource::IN::SRV) # Sort SRV records: lowest priority first, highest weight first srv.sort! { |a,b| (a.priority != b.priority) ? (a.priority <=> b.priority) : (b.weight <=> a.weight) } "#{resolve_node(srv.first.target)}:#{srv.first.port}" end
resolver()
click to toggle source
# File lib/consul_api/dns.rb, line 16 def self.resolver Resolv::DNS.new( nameserver_port: [[consul_ip, consul_dns_port]], search: [], ndots: 1 ) end