Class: Facter::Util::Facts::VirtualDetector
- Inherits:
-
Object
- Object
- Facter::Util::Facts::VirtualDetector
- Defined in:
- lib/facter/util/facts/virtual_detector.rb
Overview
Instance Method Summary collapse
- #check_dmi ⇒ Object
- #check_docker_lxc ⇒ Object
- #check_freebsd ⇒ Object
- #check_gce ⇒ Object
- #check_lspci ⇒ Object
- #check_open_vz ⇒ Object
- #check_other_facts ⇒ Object
- #check_vmware ⇒ Object
- #check_vserver ⇒ Object
- #check_xen ⇒ Object
-
#initialize ⇒ VirtualDetector
constructor
A new instance of VirtualDetector.
- #platform ⇒ Object
- #retrieve_from_virt_what ⇒ Object
Constructor Details
#initialize ⇒ VirtualDetector
Returns a new instance of VirtualDetector.
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_dmi ⇒ Object
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_lxc ⇒ Object
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_freebsd ⇒ Object
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_gce ⇒ Object
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_lspci ⇒ Object
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_vz ⇒ Object
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_facts ⇒ Object
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_vmware ⇒ Object
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_vserver ⇒ Object
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_xen ⇒ Object
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 |
#platform ⇒ Object
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 |