Sha256: fde900ebd981b592e137da197cdb216c47fe20c6d9086f272a573bd73ee662e9

Contents?: true

Size: 1.02 KB

Versions: 8

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    class Lspci < BaseResolver
      @fact_list ||= {}

      REGEX_VALUES = { 'VirtualBox' => 'virtualbox', 'XenSource' => 'xenhvm',
                       'Microsoft Corporation Hyper-V' => 'hyperv', 'Class 8007: Google, Inc' => 'gce',
                       'VM[wW]are' => 'vmware', '1ab8:' => 'parallels', '[Pp]arallels' => 'parallels',
                       '(?i)(virtio)' => 'kvm' }.freeze

      class << self
        private

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

        def lspci_command(fact_name)
          output = Facter::Core::Execution.execute('lspci', logger: log)
          return if output.empty?

          @fact_list[:vm] = retrieve_vm(output)
          @fact_list[fact_name]
        end

        def retrieve_vm(output)
          output.each_line { |line| REGEX_VALUES.each { |key, value| return value if line =~ /#{key}/ } }

          nil
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
facter-4.0.44 lib/facter/resolvers/lspci.rb
facter-4.0.43 lib/facter/resolvers/lspci.rb
facter-4.0.42 lib/facter/resolvers/lspci.rb
facter-4.0.41 lib/facter/resolvers/lspci.rb
facter-4.0.40 lib/facter/resolvers/lspci.rb
facter-4.0.39 lib/facter/resolvers/lspci.rb
facter-4.0.38 lib/facter/resolvers/lspci.rb
facter-4.0.37 lib/facter/resolvers/lspci.rb