Sha256: dbd0aa2cd7af7471f109aa014444671176eeb433de04006f5ecf275e21851ff3

Contents?: true

Size: 1.15 KB

Versions: 14

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    module Solaris
      class Ipaddress < BaseResolver
        @log = Facter::Log.new(self)
        @semaphore = Mutex.new
        @fact_list ||= {}
        class << self
          private

          def post_resolve(fact_name)
            @fact_list.fetch(fact_name) { read_ipaddress(fact_name) }
          end

          def read_ipaddress(fact_name)
            ip = nil
            primary_interface = read_primary_interface
            unless primary_interface.nil?
              output, _status = Open3.capture2("ifconfig #{primary_interface}")
              output.each_line do |str|
                if str.strip =~ /inet\s(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}) .+/
                  @fact_list[:ip] = ip = Regexp.last_match(1)
                  break
                end
              end
            end
            @fact_list[fact_name]
          end

          def read_primary_interface
            output, _status = Open3.capture2('route -n get default | grep interface')
            output.strip =~ /interface:\s(\S+)/ ? Regexp.last_match(1) : nil
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
facter-4.0.20 lib/resolvers/solaris/ipaddress_resolver.rb
facter-4.0.19 lib/resolvers/solaris/ipaddress_resolver.rb
facter-4.0.18 lib/resolvers/solaris/ipaddress_resolver.rb
facter-4.0.17 lib/resolvers/solaris/ipaddress_resolver.rb
facter-4.0.16 lib/resolvers/solaris/ipaddress_resolver.rb
facter-4.0.15 lib/resolvers/solaris/ipaddress_resolver.rb
facter-4.0.14 lib/resolvers/solaris/ipaddress_resolver.rb
facter-4.0.13 lib/resolvers/solaris/ipaddress_resolver.rb
facter-4.0.12 lib/resolvers/solaris/ipaddress_resolver.rb
facter-4.0.11 lib/resolvers/solaris/ipaddress_resolver.rb
facter-4.0.10.pre lib/resolvers/solaris/ipaddress_resolver.rb
facter-4.0.9.pre lib/resolvers/solaris/ipaddress_resolver.rb
facter-4.0.8.pre lib/resolvers/solaris/ipaddress_resolver.rb
facter-4.0.7.pre lib/resolvers/solaris/ipaddress_resolver.rb