Sha256: d40ac3813579277c556ef6e0b3a205a7385c53261c2f8703517621fd043caa87

Contents?: true

Size: 1.18 KB

Versions: 31

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module Facts
  module Linux
    module Hypervisors
      class Xen
        FACT_NAME = 'hypervisors.xen'

        def initialize
          @log = Facter::Log.new(self)
        end

        def call_the_resolver
          if xen?
            @log.debug('Xen hypervisor detected')
            fact_value = {}

            fact_value[:context] = hvm? ? 'hvm' : 'pv'
            fact_value[:privileged] = Facter::Resolvers::Xen.resolve(:privileged)

            return Facter::ResolvedFact.new(FACT_NAME, fact_value)
          end

          @log.debug('No Xen hypervisor detected.')
          []
        end

        private

        def xen?
          Facter::Util::Facts::Posix::VirtualDetector.platform =~ /xen/
        end

        def hvm?
          discover_hypervisor == 'xenhvm' || Facter::Resolvers::Lspci.resolve(:vm) == 'xenhvm'
        end

        def discover_hypervisor
          product_name = Facter::Resolvers::Linux::DmiBios.resolve(:product_name)
          return unless product_name

          Facter::Util::Facts::HYPERVISORS_HASH.each { |key, value| return value if product_name.include?(key) }

          product_name
        end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
facter-4.10.0 lib/facter/facts/linux/hypervisors/xen.rb
facter-4.9.0 lib/facter/facts/linux/hypervisors/xen.rb
facter-4.8.0 lib/facter/facts/linux/hypervisors/xen.rb
facter-4.7.1 lib/facter/facts/linux/hypervisors/xen.rb
facter-4.7.0 lib/facter/facts/linux/hypervisors/xen.rb
facter-4.6.1 lib/facter/facts/linux/hypervisors/xen.rb
facter-4.6.0 lib/facter/facts/linux/hypervisors/xen.rb
facter-4.5.2 lib/facter/facts/linux/hypervisors/xen.rb
facter-4.5.1 lib/facter/facts/linux/hypervisors/xen.rb
facter-4.5.0 lib/facter/facts/linux/hypervisors/xen.rb
facter-4.4.3 lib/facter/facts/linux/hypervisors/xen.rb
facter-4.4.2 lib/facter/facts/linux/hypervisors/xen.rb
facter-4.4.1 lib/facter/facts/linux/hypervisors/xen.rb
facter-4.4.0 lib/facter/facts/linux/hypervisors/xen.rb
facter-4.3.1 lib/facter/facts/linux/hypervisors/xen.rb
facter-4.3.0 lib/facter/facts/linux/hypervisors/xen.rb
facter-4.2.14 lib/facter/facts/linux/hypervisors/xen.rb
facter-4.2.13 lib/facter/facts/linux/hypervisors/xen.rb
facter-4.2.12 lib/facter/facts/linux/hypervisors/xen.rb
facter-4.2.11 lib/facter/facts/linux/hypervisors/xen.rb