Sha256: cd133b9bd3c5e322910e1e432dd6539085fb32104e9e9ea292567a8866593c87

Contents?: true

Size: 1.06 KB

Versions: 29

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    module Freebsd
      class Virtual < BaseResolver
        init_resolver

        class << self
          #:model

          VM_GUEST_SYSCTL_NAMES = {
            'hv' => 'hyperv',
            'microsoft' => 'hyperv',
            'oracle' => 'virtualbox',
            'xen' => 'xenu',
            'none' => nil
          }.freeze

          private

          def post_resolve(fact_name, _options)
            @fact_list.fetch(fact_name) { read_facts(fact_name) }
          end

          def read_facts(fact_name)
            require_relative 'ffi/ffi_helper'

            if Facter::Freebsd::FfiHelper.sysctl_by_name(:long, 'security.jail.jailed').zero?
              vm = Facter::Freebsd::FfiHelper.sysctl_by_name(:string, 'kern.vm_guest')

              vm = VM_GUEST_SYSCTL_NAMES[vm] if VM_GUEST_SYSCTL_NAMES.key?(vm)

              @fact_list[:vm] = vm
            else
              @fact_list[:vm] = 'jail'
            end

            @fact_list[fact_name]
          end
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
facter-4.2.3 lib/facter/resolvers/freebsd/virtual.rb
facter-4.2.2 lib/facter/resolvers/freebsd/virtual.rb
facter-4.2.1 lib/facter/resolvers/freebsd/virtual.rb
facter-4.2.0 lib/facter/resolvers/freebsd/virtual.rb
facter-4.1.1 lib/facter/resolvers/freebsd/virtual.rb
facter-4.1.0 lib/facter/resolvers/freebsd/virtual.rb
facter-4.0.52 lib/facter/resolvers/freebsd/virtual.rb
facter-4.0.51 lib/facter/resolvers/freebsd/virtual.rb
facter-4.0.50 lib/facter/resolvers/freebsd/virtual.rb