Class: NicIpResolver
Overview
converts a name into ip address using DNS in the interface scope if we are managing DNS, we can query the correct DNS server otherwise, use normal systems dns settings to resolv
Instance Attribute Summary collapse
-
#nic ⇒ Object
Returns the value of attribute nic.
Instance Method Summary collapse
-
#initialize(opts) ⇒ NicIpResolver
constructor
A new instance of NicIpResolver.
- #to_ip_address(name_or_ip) ⇒ Object
Constructor Details
#initialize(opts) ⇒ NicIpResolver
Returns a new instance of NicIpResolver.
10 11 12 |
# File 'app/services/nic_ip_resolver.rb', line 10 def initialize(opts) @nic = opts.fetch(:nic) end |
Instance Attribute Details
#nic ⇒ Object
Returns the value of attribute nic
5 6 7 |
# File 'app/services/nic_ip_resolver.rb', line 5 def nic @nic end |
Instance Method Details
#to_ip_address(name_or_ip) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/services/nic_ip_resolver.rb', line 14 def to_ip_address(name_or_ip) return name_or_ip if name_or_ip =~ Net::Validations::IP_REGEXP if dns_record(:ptr4) lookup = dns_record(:ptr4).dns_lookup(name_or_ip) return lookup.ip unless lookup.nil? end # fall back to normal dns resolution domain.resolver.getaddress(name_or_ip).to_s rescue => e logger.warn "Unable to find IP address for '#{name_or_ip}': #{e}" raise ::Foreman::WrappedException.new(e, N_("Unable to find IP address for '%s'"), name_or_ip) end |