# module Puppet::Network::Resolver

### Public Class Methods

each_srv_record(domain, service_name = :puppet) { |target.to_s, port| ... } click to toggle source

Iterate through the list of servers that service this hostname and yield each server/port since SRV records have ports in them It will override whatever masterport setting is already set.

    # File lib/puppet/network/resolver.rb, line 8
    def self.each_srv_record(domain, service_name = :puppet, &block)
      if (domain.nil? or domain.empty?)
        Puppet.debug "Domain not known; skipping SRV lookup"
        return
      end

      Puppet.debug "Searching for SRV records for domain: #{domain}"

      case service_name
        when :puppet then service = '_x-puppet'
        when :ca     then service = '_x-puppet-ca'
        when :report then service = '_x-puppet-report'
        when :file   then service = '_x-puppet-fileserver'
      end
      srv_record = "#{service}._tcp.#{domain}"

      resolver = Resolv::DNS.new
      records = resolver.getresources(srv_record, Resolv::DNS::Resource::IN::SRV)
      Puppet.debug "Found #{records.size} SRV records for: #{srv_record}"

      if records.size == 0 && service_name != :puppet
        # Try the generic :puppet service if no SRV records were found
        # for the specific service.
        each_srv_record(domain, :puppet, &block)
      else
        each_priority(records) do |priority, records|
          while next_rr = records.delete(find_weighted_server(records))
            Puppet.debug "Yielding next server of #{next_rr.target.to_s}:#{next_rr.port}"
            yield next_rr.target.to_s, next_rr.port
          end
        end
      end
    end