facter 4.0.52 → 4.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +202 -0
  3. data/lib/facter.rb +21 -21
  4. data/lib/facter/config.rb +2 -0
  5. data/lib/facter/custom_facts/core/execution/base.rb +7 -3
  6. data/lib/facter/custom_facts/core/execution/popen3.rb +13 -1
  7. data/lib/facter/custom_facts/core/execution/posix.rb +2 -2
  8. data/lib/facter/custom_facts/core/execution/windows.rb +1 -1
  9. data/lib/facter/custom_facts/util/collection.rb +5 -0
  10. data/lib/facter/custom_facts/util/directory_loader.rb +1 -1
  11. data/lib/facter/custom_facts/util/normalization.rb +7 -2
  12. data/lib/facter/custom_facts/util/windows_root.rb +2 -1
  13. data/lib/facter/facts/aix/processors/cores.rb +16 -0
  14. data/lib/facter/facts/aix/processors/threads.rb +16 -0
  15. data/lib/facter/facts/freebsd/is_virtual.rb +1 -5
  16. data/lib/facter/facts/freebsd/virtual.rb +1 -2
  17. data/lib/facter/facts/linux/az_metadata.rb +1 -5
  18. data/lib/facter/facts/linux/cloud/provider.rb +5 -2
  19. data/lib/facter/facts/linux/ec2_metadata.rb +1 -5
  20. data/lib/facter/facts/linux/ec2_userdata.rb +1 -5
  21. data/lib/facter/facts/linux/hypervisors/xen.rb +1 -4
  22. data/lib/facter/facts/linux/is_virtual.rb +1 -5
  23. data/lib/facter/facts/linux/processors/cores.rb +16 -0
  24. data/lib/facter/facts/linux/processors/threads.rb +16 -0
  25. data/lib/facter/facts/linux/virtual.rb +1 -2
  26. data/lib/facter/facts/macosx/os/macosx/version.rb +15 -4
  27. data/lib/facter/facts/macosx/processors/cores.rb +16 -0
  28. data/lib/facter/facts/macosx/processors/threads.rb +16 -0
  29. data/lib/facter/facts/solaris/hypervisors/ldom.rb +1 -1
  30. data/lib/facter/facts/solaris/hypervisors/zone.rb +1 -1
  31. data/lib/facter/facts/solaris/mountpoints.rb +1 -1
  32. data/lib/facter/facts/solaris/processors/cores.rb +16 -0
  33. data/lib/facter/facts/solaris/processors/threads.rb +16 -0
  34. data/lib/facter/facts/windows/az_metadata.rb +1 -5
  35. data/lib/facter/facts/windows/cloud/provider.rb +6 -2
  36. data/lib/facter/facts/windows/ec2_metadata.rb +1 -1
  37. data/lib/facter/facts/windows/ec2_userdata.rb +1 -1
  38. data/lib/facter/facts/windows/gce.rb +1 -1
  39. data/lib/facter/facts/windows/hypervisors/hyperv.rb +1 -1
  40. data/lib/facter/facts/windows/hypervisors/kvm.rb +2 -1
  41. data/lib/facter/facts/windows/hypervisors/virtualbox.rb +2 -2
  42. data/lib/facter/facts/windows/hypervisors/vmware.rb +1 -1
  43. data/lib/facter/facts/windows/hypervisors/xen.rb +3 -1
  44. data/lib/facter/facts/windows/is_virtual.rb +15 -0
  45. data/lib/facter/facts/windows/{virtualization/is_virtual.rb → processors/cores.rb} +4 -4
  46. data/lib/facter/facts/windows/{virtualization/virtual.rb → processors/threads.rb} +4 -4
  47. data/lib/facter/facts/windows/virtual.rb +15 -0
  48. data/lib/facter/framework/cli/cli.rb +13 -15
  49. data/lib/facter/framework/core/cache_manager.rb +2 -2
  50. data/lib/facter/framework/core/fact/external/external_fact_manager.rb +0 -1
  51. data/lib/facter/framework/core/fact/internal/internal_fact_manager.rb +41 -39
  52. data/lib/facter/framework/core/fact_filter.rb +4 -14
  53. data/lib/facter/framework/core/fact_loaders/external_fact_loader.rb +9 -6
  54. data/lib/facter/framework/core/fact_loaders/fact_loader.rb +39 -36
  55. data/lib/facter/framework/core/fact_manager.rb +82 -14
  56. data/lib/facter/framework/core/file_loader.rb +1 -1
  57. data/lib/facter/framework/core/options/config_file_options.rb +7 -0
  58. data/lib/facter/framework/core/options/option_store.rb +3 -1
  59. data/lib/facter/framework/formatters/formatter_helper.rb +3 -5
  60. data/lib/facter/framework/parsers/query_parser.rb +10 -24
  61. data/lib/facter/models/fact_collection.rb +48 -5
  62. data/lib/facter/models/resolved_fact.rb +2 -3
  63. data/lib/facter/models/searched_fact.rb +2 -3
  64. data/lib/facter/resolvers/aix/ffi/ffi_helper.rb +1 -1
  65. data/lib/facter/resolvers/aix/processors.rb +4 -0
  66. data/lib/facter/resolvers/base_resolver.rb +2 -2
  67. data/lib/facter/resolvers/dmi_decode.rb +0 -1
  68. data/lib/facter/resolvers/ec2.rb +8 -1
  69. data/lib/facter/resolvers/linux/hostname.rb +16 -5
  70. data/lib/facter/resolvers/linux/networking.rb +18 -1
  71. data/lib/facter/resolvers/lsb_release.rb +1 -2
  72. data/lib/facter/resolvers/macosx/mountpoints.rb +14 -1
  73. data/lib/facter/resolvers/macosx/processor.rb +16 -1
  74. data/lib/facter/resolvers/mountpoints.rb +16 -8
  75. data/lib/facter/resolvers/networking.rb +6 -3
  76. data/lib/facter/resolvers/partitions.rb +1 -3
  77. data/lib/facter/resolvers/processors_lscpu.rb +44 -0
  78. data/lib/facter/resolvers/ruby.rb +1 -1
  79. data/lib/facter/resolvers/selinux.rb +5 -7
  80. data/lib/facter/resolvers/solaris/ffi/structs.rb +12 -0
  81. data/lib/facter/resolvers/solaris/mountpoints.rb +22 -16
  82. data/lib/facter/resolvers/solaris/networking.rb +20 -5
  83. data/lib/facter/resolvers/solaris/processors.rb +7 -0
  84. data/lib/facter/resolvers/solaris/zone.rb +0 -1
  85. data/lib/facter/resolvers/windows/ffi/identity_ffi.rb +5 -0
  86. data/lib/facter/resolvers/windows/ffi/kernel_ffi.rb +1 -1
  87. data/lib/facter/resolvers/windows/identity.rb +1 -6
  88. data/lib/facter/resolvers/windows/processors.rb +41 -4
  89. data/lib/facter/resolvers/windows/uptime.rb +3 -22
  90. data/lib/facter/resolvers/windows/virtualization.rb +46 -44
  91. data/lib/facter/resolvers/xen.rb +6 -1
  92. data/lib/facter/templates/man.erb +6 -6
  93. data/lib/facter/util/facts/posix/virtual_detector.rb +74 -0
  94. data/lib/facter/util/facts/unit_converter.rb +2 -2
  95. data/lib/facter/util/linux/dhcp.rb +4 -1
  96. data/lib/facter/util/linux/if_inet6.rb +73 -0
  97. data/lib/facter/util/linux/socket_parser.rb +18 -3
  98. data/lib/facter/util/resolvers/http.rb +7 -1
  99. data/lib/facter/util/resolvers/networking/primary_interface.rb +11 -5
  100. data/lib/facter/util/utils.rb +18 -1
  101. data/lib/facter/version.rb +1 -1
  102. metadata +60 -11
  103. data/lib/facter/framework/core/fact_augmenter.rb +0 -37
  104. data/lib/facter/util/facts/virtual_detector.rb +0 -90
@@ -101,16 +101,31 @@ module Facter
101
101
  end
102
102
 
103
103
  def inet_ntop(lifreq, ss_family)
104
- sockaddr = FFI::Sockaddr.new(lifreq.lifru_addr.to_ptr)
105
- sockaddr_in = FFI::SockaddrIn.new(sockaddr.to_ptr)
106
- ip = FFI::InAddr.new(sockaddr_in[:sin_addr].to_ptr)
107
- buffer_size = FFI::INET_ADDRSTRLEN
108
- buffer_size = FFI::INET6_ADDRSTRLEN if ss_family == FFI::AF_INET6
104
+ if ss_family == FFI::AF_INET
105
+ buffer_size = FFI::INET_ADDRSTRLEN
106
+ ip = get_ipv4(lifreq)
107
+ else # FFI::AF_INET6
108
+ buffer_size = FFI::INET6_ADDRSTRLEN
109
+ ip = get_ipv6(lifreq)
110
+ end
111
+
109
112
  buffer = ::FFI::MemoryPointer.new(:char, buffer_size)
110
113
 
111
114
  FFI::Ioctl.inet_ntop(ss_family, ip.to_ptr, buffer.to_ptr, buffer.size)
112
115
  end
113
116
 
117
+ def get_ipv4(lifreq)
118
+ sockaddr = FFI::Sockaddr.new(lifreq.lifru_addr.to_ptr)
119
+ sockaddr_in = FFI::SockaddrIn.new(sockaddr.to_ptr)
120
+ FFI::InAddr.new(sockaddr_in[:sin_addr].to_ptr)
121
+ end
122
+
123
+ def get_ipv6(lifreq)
124
+ sockaddr = FFI::Sockaddr.new(lifreq.lifru_addr.to_ptr)
125
+ sockaddr_in6 = FFI::SockaddrIn6.new(sockaddr.to_ptr)
126
+ FFI::In6Addr.new(sockaddr_in6[:sin6_addr].to_ptr)
127
+ end
128
+
114
129
  def count_interfaces
115
130
  lifnum = FFI::Lifnum.new
116
131
  lifnum[:lifn_family] = FFI::AF_UNSPEC
@@ -28,6 +28,13 @@ module Facter
28
28
  @fact_list[:physical_count] = output.scan(/chip_id .*/).uniq.size
29
29
  @fact_list[:speed] = output.scan(/current_clock_Hz .*/).first.gsub(/[a-zA-z\s]+/, '').to_i
30
30
  @fact_list[:models] = output.scan(/brand .*/).map { |elem| elem.gsub(/brand(\s+)/, '') }
31
+ calculate_threads_cores(output)
32
+ end
33
+
34
+ def calculate_threads_cores(output)
35
+ @fact_list[:core_count] = output.scan(/\score_id .*/).uniq.size
36
+ @fact_list[:threads_per_core] = @fact_list[:logical_count] / @fact_list[:core_count]
37
+ @fact_list[:cores_per_socket] = @fact_list[:core_count] / @fact_list[:physical_count]
31
38
  end
32
39
  end
33
40
  end
@@ -38,7 +38,6 @@ module Facter
38
38
  uuid: uuid,
39
39
  status: status,
40
40
  path: path
41
-
42
41
  }
43
42
  end
44
43
  zones_fact
@@ -12,4 +12,9 @@ module IdentityFFI
12
12
  ffi_convention :stdcall
13
13
  ffi_lib :shell32
14
14
  attach_function :IsUserAnAdmin, [], :win32_bool
15
+
16
+ def self.privileged?
17
+ result = self.IsUserAnAdmin()
18
+ result && result != FFI::WIN32FALSE
19
+ end
15
20
  end
@@ -7,7 +7,7 @@ module KernelFFI
7
7
  extend FFI::Library
8
8
 
9
9
  ffi_convention :stdcall
10
- ffi_lib [FFI::CURRENT_PROCESS, :ntdll]
10
+ ffi_lib :ntdll
11
11
  attach_function :RtlGetVersion, [:pointer], :int32
12
12
 
13
13
  STATUS_SUCCESS = 0
@@ -31,12 +31,7 @@ module Facter
31
31
  return
32
32
  end
33
33
 
34
- { user: name_ptr.read_wide_string_with_length(size_ptr.read_uint32), privileged: privileged? }
35
- end
36
-
37
- def privileged?
38
- result = IdentityFFI::IsUserAnAdmin()
39
- result && result != FFI::WIN32FALSE
34
+ { user: name_ptr.read_wide_string_with_length(size_ptr.read_uint32), privileged: IdentityFFI.privileged? }
40
35
  end
41
36
 
42
37
  def retrieve_facts(fact_name)
@@ -19,14 +19,19 @@ module Facter
19
19
 
20
20
  def read_fact_from_win32_processor(fact_name)
21
21
  win = Facter::Util::Windows::Win32Ole.new
22
- proc = win.exec_query('SELECT Name,Architecture,NumberOfLogicalProcessors FROM Win32_Processor')
22
+ query_string = 'SELECT Name,'\
23
+ 'Architecture,'\
24
+ 'NumberOfLogicalProcessors,'\
25
+ 'NumberOfCores FROM Win32_Processor'
26
+ proc = win.exec_query(query_string)
23
27
  unless proc
24
28
  log.debug 'WMI query returned no results'\
25
29
  'for Win32_Processor with values Name, Architecture and NumberOfLogicalProcessors.'
26
30
  return
27
31
  end
28
32
  result = iterate_proc(proc)
29
- build_fact_list(result)
33
+ cores_threads = calculate_cores_threads(proc, result)
34
+ build_fact_list(result, cores_threads)
30
35
  @fact_list[fact_name]
31
36
  end
32
37
 
@@ -40,7 +45,29 @@ module Facter
40
45
  isa ||= find_isa(proc.Architecture)
41
46
  end
42
47
 
43
- { models: models, isa: isa, logical_count: logical_count.zero? ? models.count : logical_count }
48
+ { models: models,
49
+ isa: isa,
50
+ logical_count: logical_processors_count(logical_count, models.count) }
51
+ end
52
+
53
+ def calculate_cores_threads(result_proc, data_proc)
54
+ cores = 0
55
+ threads_per_core = 0
56
+ result_proc.each do |proc|
57
+ cores = proc.NumberOfCores
58
+ threads_per_core = if check_hyperthreading(data_proc[:logical_count], cores) ||
59
+ cores > data_proc[:logical_count]
60
+ 1
61
+ else
62
+ data_proc[:logical_count] / (cores * data_proc[:models].size)
63
+ end
64
+ end
65
+ { cores_per_socket: cores,
66
+ threads_per_core: threads_per_core }
67
+ end
68
+
69
+ def check_hyperthreading(cores, logical_processors)
70
+ cores == logical_processors
44
71
  end
45
72
 
46
73
  def find_isa(arch)
@@ -52,11 +79,21 @@ module Facter
52
79
  log.debug 'Unable to determine processor type: unknown architecture'
53
80
  end
54
81
 
55
- def build_fact_list(result)
82
+ def logical_processors_count(logical_count, models_count)
83
+ if logical_count.zero?
84
+ models_count
85
+ else
86
+ logical_count
87
+ end
88
+ end
89
+
90
+ def build_fact_list(result, cores_threads)
56
91
  @fact_list[:count] = result[:logical_count]
57
92
  @fact_list[:isa] = result[:isa]
58
93
  @fact_list[:models] = result[:models]
59
94
  @fact_list[:physicalcount] = result[:models].size
95
+ @fact_list[:cores_per_socket] = cores_threads[:cores_per_socket]
96
+ @fact_list[:threads_per_core] = cores_threads[:threads_per_core]
60
97
  end
61
98
  end
62
99
  end
@@ -17,7 +17,7 @@ module Facter
17
17
  @fact_list.fetch(fact_name) { calculate_system_uptime(fact_name) }
18
18
  end
19
19
 
20
- def substract_system_uptime_from_ole
20
+ def subtract_system_uptime_from_ole
21
21
  win = Facter::Util::Windows::Win32Ole.new
22
22
  opsystem = win.return_first('SELECT LocalDateTime,LastBootUpTime FROM Win32_OperatingSystem')
23
23
  unless opsystem
@@ -35,35 +35,16 @@ module Facter
35
35
  end
36
36
 
37
37
  def calculate_system_uptime(fact_name)
38
- seconds = substract_system_uptime_from_ole.to_i if substract_system_uptime_from_ole
38
+ seconds = subtract_system_uptime_from_ole&.to_i
39
39
  if !seconds || seconds.negative?
40
40
  @log.debug 'Unable to determine system uptime!'
41
41
  return
42
42
  end
43
43
 
44
- hours = seconds / 3600
45
- days = hours / 24
46
-
47
- result = { seconds: seconds, hours: hours, days: days }
48
-
49
- result[:uptime] = determine_uptime(result)
50
- build_fact_list(result)
51
-
44
+ @fact_list = Facter::Util::Resolvers::UptimeHelper.create_uptime_hash(seconds)
52
45
  @fact_list[fact_name]
53
46
  end
54
47
 
55
- def determine_uptime(result_hash)
56
- minutes = (result_hash[:seconds] - result_hash[:hours] * 3600) / 60
57
-
58
- if result_hash[:days].zero?
59
- "#{result_hash[:hours]}:#{minutes} hours"
60
- elsif result_hash[:days] == 1
61
- "#{result_hash[:days]} day"
62
- else
63
- "#{result_hash[:days]} days"
64
- end
65
- end
66
-
67
48
  def build_fact_list(system_uptime)
68
49
  @fact_list[:days] = system_uptime[:days]
69
50
  @fact_list[:hours] = system_uptime[:hours]
@@ -2,63 +2,65 @@
2
2
 
3
3
  module Facter
4
4
  module Resolvers
5
- class Virtualization < BaseResolver
6
- @log = Facter::Log.new(self)
5
+ module Windows
6
+ class Virtualization < BaseResolver
7
+ @log = Facter::Log.new(self)
7
8
 
8
- init_resolver
9
+ init_resolver
9
10
 
10
- class << self
11
- # Virtual
12
- # Is_Virtual
11
+ class << self
12
+ # Virtual
13
+ # Is_Virtual
13
14
 
14
- MODEL_HASH = { 'VirtualBox' => 'virtualbox', 'VMware' => 'vmware', 'KVM' => 'kvm',
15
- 'Bochs' => 'bochs', 'Google' => 'gce', 'OpenStack' => 'openstack' }.freeze
15
+ MODEL_HASH = { 'VirtualBox' => 'virtualbox', 'VMware' => 'vmware', 'KVM' => 'kvm',
16
+ 'Bochs' => 'bochs', 'Google' => 'gce', 'OpenStack' => 'openstack' }.freeze
16
17
 
17
- private
18
+ private
18
19
 
19
- def post_resolve(fact_name, _options)
20
- @fact_list.fetch(fact_name) { read_fact_from_computer_system(fact_name) }
21
- end
22
-
23
- def read_fact_from_computer_system(fact_name)
24
- win = Facter::Util::Windows::Win32Ole.new
25
- comp = win.exec_query('SELECT Manufacturer,Model,OEMStringArray FROM Win32_ComputerSystem')
26
- unless comp
27
- @log.debug 'WMI query returned no results for Win32_ComputerSystem with values'\
28
- ' Manufacturer, Model and OEMStringArray.'
29
- return
20
+ def post_resolve(fact_name, _options)
21
+ @fact_list.fetch(fact_name) { read_fact_from_computer_system(fact_name) }
30
22
  end
31
23
 
32
- build_fact_list(comp)
33
- @fact_list[fact_name]
34
- end
24
+ def read_fact_from_computer_system(fact_name)
25
+ win = Facter::Util::Windows::Win32Ole.new
26
+ comp = win.exec_query('SELECT Manufacturer,Model,OEMStringArray FROM Win32_ComputerSystem')
27
+ unless comp
28
+ @log.debug 'WMI query returned no results for Win32_ComputerSystem with values'\
29
+ ' Manufacturer, Model and OEMStringArray.'
30
+ return
31
+ end
35
32
 
36
- def determine_hypervisor_by_model(comp)
37
- MODEL_HASH[MODEL_HASH.keys.find { |key| comp.Model =~ /^#{key}/ }]
38
- end
33
+ build_fact_list(comp)
34
+ @fact_list[fact_name]
35
+ end
39
36
 
40
- def determine_hypervisor_by_manufacturer(comp)
41
- manufacturer = comp.Manufacturer
42
- if comp.Model =~ /^Virtual Machine/ && manufacturer =~ /^Microsoft/
43
- 'hyperv'
44
- elsif manufacturer =~ /^Xen/
45
- 'xen'
46
- elsif manufacturer =~ /^Amazon EC2/
47
- 'kvm'
48
- else
49
- 'physical'
37
+ def determine_hypervisor_by_model(comp)
38
+ MODEL_HASH[MODEL_HASH.keys.find { |key| comp.Model =~ /^#{key}/ }]
39
+ end
40
+
41
+ def determine_hypervisor_by_manufacturer(comp)
42
+ manufacturer = comp.Manufacturer
43
+ if comp.Model =~ /^Virtual Machine/ && manufacturer =~ /^Microsoft/
44
+ 'hyperv'
45
+ elsif manufacturer =~ /^Xen/
46
+ 'xen'
47
+ elsif manufacturer =~ /^Amazon EC2/
48
+ 'kvm'
49
+ else
50
+ 'physical'
51
+ end
50
52
  end
51
- end
52
53
 
53
- def build_fact_list(comp)
54
- @fact_list[:oem_strings] = []
55
- @fact_list[:oem_strings] += comp.to_enum.map(&:OEMStringArray).flatten
54
+ def build_fact_list(comp)
55
+ @fact_list[:oem_strings] = []
56
+ @fact_list[:oem_strings] += comp.to_enum.map(&:OEMStringArray).flatten
56
57
 
57
- comp = comp.to_enum.first
58
- hypervisor = determine_hypervisor_by_model(comp) || determine_hypervisor_by_manufacturer(comp)
58
+ comp = comp.to_enum.first
59
+ hypervisor = determine_hypervisor_by_model(comp) || determine_hypervisor_by_manufacturer(comp)
59
60
 
60
- @fact_list[:virtual] = hypervisor
61
- @fact_list[:is_virtual] = hypervisor.include?('physical') ? false : true
61
+ @fact_list[:virtual] = hypervisor
62
+ @fact_list[:is_virtual] = hypervisor.include?('physical') ? false : true
63
+ end
62
64
  end
63
65
  end
64
66
  end
@@ -56,7 +56,12 @@ module Facter
56
56
  end
57
57
 
58
58
  def find_command
59
- return XEN_TOOLSTACK if File.exist?(XEN_TOOLSTACK)
59
+ num_stacks = 0
60
+ XEN_COMMANDS.each do |command|
61
+ num_stacks += 1 if File.exist?(command)
62
+ end
63
+
64
+ return XEN_TOOLSTACK if num_stacks > 1 && File.exist?(XEN_TOOLSTACK)
60
65
 
61
66
  XEN_COMMANDS.each { |command| return command if File.exist?(command) }
62
67
  end
@@ -13,14 +13,14 @@ Many of the command line options can also be set via the HOCON config file. This
13
13
 
14
14
  OPTIONS
15
15
  -------
16
- <% @Facter::Cli.class_options.each do |name, option| -%><% next if option.hide%>
16
+ <% Facter::Cli.class_options.each do |name, option| -%><% next if option.hide%>
17
17
  * `<%= option.aliases[0] + '`, `' if option.aliases.any? %>--<%= 'no-' if negate_options.include?(name.to_s)%><%= name.to_s.gsub('_','-') %>`:
18
18
 
19
19
  <%= option.description %>
20
20
 
21
21
  <% end -%>
22
22
 
23
- <% @Facter::Cli.commands.select { |_k, command_class| command_class.instance_of?(Thor::Command) }.each do |_, command| -%>
23
+ <% Facter::Cli.commands.select { |_k, command_class| command_class.instance_of?(Thor::Command) }.each do |_, command| -%>
24
24
  * `<%= command.usage %>`:
25
25
 
26
26
  <%= command.description %>
@@ -32,7 +32,7 @@ FILES
32
32
  -----
33
33
  <em>/etc/puppetlabs/facter/facter.conf</em>
34
34
 
35
- A HOCON config file that can be used to specify directories for custom and external facts, set various command line options, and specify facts to block. See example below for details, or visit the GitHub README.
35
+ A HOCON config file that can be used to specify directories for custom and external facts, set various command line options, and specify facts to block. See example below for details, or visit the [GitHub README](https://github.com/puppetlabs/puppetlabs-hocon#overview).
36
36
 
37
37
  EXAMPLES
38
38
  --------
@@ -55,7 +55,7 @@ dmi => {
55
55
  version => "6.00"
56
56
  }
57
57
  }
58
- [\.\.\.]
58
+ [...]
59
59
  ```
60
60
 
61
61
  Display a single structured fact:
@@ -91,7 +91,7 @@ $ facter processorcount
91
91
  Format facts as JSON:
92
92
 
93
93
  ```
94
- $ facter \-\-json os.name os.release.major processors.isa
94
+ $ facter --json os.name os.release.major processors.isa
95
95
  {
96
96
  "os.name": "Ubuntu",
97
97
  "os.release.major": "14.04",
@@ -120,7 +120,7 @@ cli : {
120
120
  verbose : false,
121
121
  log-level : "info"
122
122
  }
123
- # always loaded, fact-sepcific configuration
123
+ # always loaded, fact-specific configuration
124
124
  facts : {
125
125
  # for valid blocklist entries, use --list-block-groups
126
126
  blocklist : [ "file system", "EC2" ],
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Util
5
+ module Facts
6
+ module Posix
7
+ module VirtualDetector
8
+ class << self
9
+ def platform
10
+ @@fact_value ||= check_docker_lxc || check_freebsd || check_gce || retrieve_from_virt_what
11
+ @@fact_value ||= check_vmware || check_open_vz || check_vserver || check_xen || check_other_facts
12
+ @@fact_value ||= check_lspci || 'physical'
13
+
14
+ @@fact_value
15
+ end
16
+
17
+ private
18
+
19
+ def check_docker_lxc
20
+ Facter::Resolvers::Containers.resolve(:vm)
21
+ end
22
+
23
+ def check_gce
24
+ bios_vendor = Facter::Resolvers::Linux::DmiBios.resolve(:bios_vendor)
25
+ 'gce' if bios_vendor&.include?('Google')
26
+ end
27
+
28
+ def check_vmware
29
+ Facter::Resolvers::Vmware.resolve(:vm)
30
+ end
31
+
32
+ def retrieve_from_virt_what
33
+ Facter::Resolvers::VirtWhat.resolve(:vm)
34
+ end
35
+
36
+ def check_open_vz
37
+ Facter::Resolvers::OpenVz.resolve(:vm)
38
+ end
39
+
40
+ def check_vserver
41
+ Facter::Resolvers::VirtWhat.resolve(:vserver)
42
+ end
43
+
44
+ def check_xen
45
+ Facter::Resolvers::Xen.resolve(:vm)
46
+ end
47
+
48
+ def check_freebsd
49
+ return unless Object.const_defined?('Facter::Resolvers::Freebsd::Virtual')
50
+
51
+ Facter::Resolvers::Freebsd::Virtual.resolve(:vm)
52
+ end
53
+
54
+ def check_other_facts
55
+ bios_vendor = Facter::Resolvers::Linux::DmiBios.resolve(:bios_vendor)
56
+ return 'kvm' if bios_vendor&.include?('Amazon EC2')
57
+
58
+ product_name = Facter::Resolvers::Linux::DmiBios.resolve(:product_name)
59
+ return unless product_name
60
+
61
+ Facter::Util::Facts::HYPERVISORS_HASH.each { |key, value| return value if product_name.include?(key) }
62
+
63
+ nil
64
+ end
65
+
66
+ def check_lspci
67
+ Facter::Resolvers::Lspci.resolve(:vm)
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end