Class: Facter::Util::Facts::VirtualDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/facter/util/facts/virtual_detector.rb

Overview

Since:

  • 2.0.0

Instance Method Summary collapse

Constructor Details

#initializeVirtualDetector

Returns a new instance of VirtualDetector.

Since:

  • 2.0.0



7
8
9
# File 'lib/facter/util/facts/virtual_detector.rb', line 7

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

Instance Method Details

#check_dmiObject

Since:

  • 2.0.0



24
25
26
27
28
29
30
31
# File 'lib/facter/util/facts/virtual_detector.rb', line 24

def check_dmi
  @log.debug('Checking DMI')
  vendor = Facter::Resolvers::DmiDecode.resolve(:vendor)
  @log.debug("dmi detected vendor: #{vendor}")
  return 'kvm' if vendor =~ /Amazon/

  'xen' if vendor =~ /Xen/
end

#check_docker_lxcObject

Since:

  • 2.0.0



19
20
21
22
# File 'lib/facter/util/facts/virtual_detector.rb', line 19

def check_docker_lxc
  @log.debug('Checking Docker and LXC')
  Facter::Resolvers::Containers.resolve(:vm)
end

#check_freebsdObject

Since:

  • 2.0.0



64
65
66
67
68
69
# File 'lib/facter/util/facts/virtual_detector.rb', line 64

def check_freebsd
  return unless Object.const_defined?('Facter::Resolvers::Freebsd::Virtual')

  @log.debug('Checking if jailed')
  Facter::Resolvers::Freebsd::Virtual.resolve(:vm)
end

#check_gceObject

Since:

  • 2.0.0



33
34
35
36
37
# File 'lib/facter/util/facts/virtual_detector.rb', line 33

def check_gce
  @log.debug('Checking GCE')
  bios_vendor = Facter::Resolvers::Linux::DmiBios.resolve(:bios_vendor)
  'gce' if bios_vendor&.include?('Google')
end

#check_lspciObject

Since:

  • 2.0.0



83
84
85
86
# File 'lib/facter/util/facts/virtual_detector.rb', line 83

def check_lspci
  @log.debug('Checking lspci')
  Facter::Resolvers::Lspci.resolve(:vm)
end

#check_open_vzObject

Since:

  • 2.0.0



49
50
51
52
# File 'lib/facter/util/facts/virtual_detector.rb', line 49

def check_open_vz
  @log.debug('Checking OpenVZ')
  Facter::Resolvers::OpenVz.resolve(:vm)
end

#check_other_factsObject

Since:

  • 2.0.0



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/facter/util/facts/virtual_detector.rb', line 71

def check_other_facts
  @log.debug('Checking others')
  product_name = Facter::Resolvers::Linux::DmiBios.resolve(:product_name)
  bios_vendor =  Facter::Resolvers::Linux::DmiBios.resolve(:bios_vendor)
  return 'kvm' if bios_vendor&.include?('Amazon EC2')
  return unless product_name

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

  nil
end

#check_vmwareObject

Since:

  • 2.0.0



39
40
41
42
# File 'lib/facter/util/facts/virtual_detector.rb', line 39

def check_vmware
  @log.debug('Checking VMware')
  Facter::Resolvers::Vmware.resolve(:vm)
end

#check_vserverObject

Since:

  • 2.0.0



54
55
56
57
# File 'lib/facter/util/facts/virtual_detector.rb', line 54

def check_vserver
  @log.debug('Checking VServer')
  Facter::Resolvers::VirtWhat.resolve(:vserver)
end

#check_xenObject

Since:

  • 2.0.0



59
60
61
62
# File 'lib/facter/util/facts/virtual_detector.rb', line 59

def check_xen
  @log.debug('Checking XEN')
  Facter::Resolvers::Xen.resolve(:vm)
end

#platformObject

Since:

  • 2.0.0



11
12
13
14
15
16
17
# File 'lib/facter/util/facts/virtual_detector.rb', line 11

def platform
  fact_value = check_docker_lxc || check_dmi || check_freebsd || check_gce || retrieve_from_virt_what
  fact_value ||= check_vmware || check_open_vz || check_vserver || check_xen || check_other_facts
  fact_value ||= check_lspci || 'physical'

  fact_value
end

#retrieve_from_virt_whatObject

Since:

  • 2.0.0



44
45
46
47
# File 'lib/facter/util/facts/virtual_detector.rb', line 44

def retrieve_from_virt_what
  @log.debug('Checking virtual_what')
  Facter::Resolvers::VirtWhat.resolve(:vm)
end