facter 4.0.50 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +4 -4
  2. data/lib/docs/generate_cli.rb +7 -0
  3. data/lib/facter.rb +90 -56
  4. data/lib/facter/config.rb +2 -0
  5. data/lib/facter/custom_facts/core/aggregate.rb +9 -0
  6. data/lib/facter/custom_facts/core/execution/base.rb +7 -3
  7. data/lib/facter/custom_facts/core/execution/popen3.rb +13 -1
  8. data/lib/facter/custom_facts/core/execution/posix.rb +2 -2
  9. data/lib/facter/custom_facts/core/execution/windows.rb +1 -1
  10. data/lib/facter/custom_facts/core/resolvable.rb +11 -0
  11. data/lib/facter/custom_facts/util/collection.rb +5 -0
  12. data/lib/facter/custom_facts/util/directory_loader.rb +1 -1
  13. data/lib/facter/custom_facts/util/normalization.rb +7 -2
  14. data/lib/facter/custom_facts/util/resolution.rb +2 -0
  15. data/lib/facter/custom_facts/util/windows_root.rb +2 -1
  16. data/lib/facter/facts/aix/processors/cores.rb +16 -0
  17. data/lib/facter/facts/aix/processors/threads.rb +16 -0
  18. data/lib/facter/facts/amzn/lsbdistcodename.rb +16 -0
  19. data/lib/facter/facts/amzn/lsbdistdescription.rb +16 -0
  20. data/lib/facter/facts/amzn/lsbdistid.rb +16 -0
  21. data/lib/facter/facts/amzn/os/distro/codename.rb +24 -0
  22. data/lib/facter/facts/amzn/os/distro/description.rb +21 -0
  23. data/lib/facter/facts/amzn/os/distro/id.rb +21 -0
  24. data/lib/facter/facts/amzn/os/distro/release.rb +32 -0
  25. data/lib/facter/facts/freebsd/is_virtual.rb +1 -5
  26. data/lib/facter/facts/freebsd/virtual.rb +1 -2
  27. data/lib/facter/facts/linux/az_metadata.rb +23 -0
  28. data/lib/facter/facts/linux/cloud/provider.rb +20 -0
  29. data/lib/facter/facts/linux/dhcp_servers.rb +2 -2
  30. data/lib/facter/facts/linux/ec2_metadata.rb +1 -5
  31. data/lib/facter/facts/linux/ec2_userdata.rb +1 -5
  32. data/lib/facter/facts/linux/hypervisors/xen.rb +1 -4
  33. data/lib/facter/facts/linux/interfaces.rb +1 -1
  34. data/lib/facter/facts/linux/ipaddress6_interfaces.rb +1 -1
  35. data/lib/facter/facts/linux/ipaddress_interfaces.rb +1 -1
  36. data/lib/facter/facts/linux/is_virtual.rb +1 -5
  37. data/lib/facter/facts/linux/macaddress_interfaces.rb +1 -1
  38. data/lib/facter/facts/linux/mtu_interfaces.rb +1 -1
  39. data/lib/facter/facts/linux/netmask6_interfaces.rb +1 -1
  40. data/lib/facter/facts/linux/netmask_interfaces.rb +1 -1
  41. data/lib/facter/facts/linux/network6_interfaces.rb +1 -1
  42. data/lib/facter/facts/linux/network_interfaces.rb +1 -1
  43. data/lib/facter/facts/linux/networking/dhcp.rb +1 -1
  44. data/lib/facter/facts/linux/networking/domain.rb +1 -1
  45. data/lib/facter/facts/linux/networking/fqdn.rb +1 -1
  46. data/lib/facter/facts/linux/networking/hostname.rb +1 -1
  47. data/lib/facter/facts/linux/networking/interfaces.rb +1 -1
  48. data/lib/facter/facts/linux/networking/ip.rb +1 -1
  49. data/lib/facter/facts/linux/networking/ip6.rb +1 -1
  50. data/lib/facter/facts/linux/networking/mac.rb +1 -1
  51. data/lib/facter/facts/linux/networking/mtu.rb +1 -1
  52. data/lib/facter/facts/linux/networking/netmask.rb +1 -1
  53. data/lib/facter/facts/linux/networking/netmask6.rb +1 -1
  54. data/lib/facter/facts/linux/networking/network.rb +1 -1
  55. data/lib/facter/facts/linux/networking/network6.rb +1 -1
  56. data/lib/facter/facts/linux/networking/primary.rb +1 -1
  57. data/lib/facter/facts/linux/networking/scope6.rb +1 -1
  58. data/lib/facter/facts/linux/processors/cores.rb +16 -0
  59. data/lib/facter/facts/linux/processors/threads.rb +16 -0
  60. data/lib/facter/facts/linux/scope6_interfaces.rb +1 -1
  61. data/lib/facter/facts/linux/virtual.rb +1 -2
  62. data/lib/facter/facts/macosx/os/macosx/version.rb +15 -4
  63. data/lib/facter/facts/macosx/processors/cores.rb +16 -0
  64. data/lib/facter/facts/macosx/processors/threads.rb +16 -0
  65. data/lib/facter/facts/rhel/lsbdistcodename.rb +16 -0
  66. data/lib/facter/facts/rhel/lsbdistdescription.rb +16 -0
  67. data/lib/facter/facts/rhel/lsbdistid.rb +16 -0
  68. data/lib/facter/facts/rhel/os/distro/codename.rb +2 -4
  69. data/lib/facter/facts/rhel/os/distro/description.rb +2 -4
  70. data/lib/facter/facts/rhel/os/distro/id.rb +2 -4
  71. data/lib/facter/facts/rhel/os/distro/release.rb +13 -12
  72. data/lib/facter/facts/sles/lsbdistcodename.rb +16 -0
  73. data/lib/facter/facts/sles/lsbdistdescription.rb +16 -0
  74. data/lib/facter/facts/sles/lsbdistid.rb +16 -0
  75. data/lib/facter/facts/sles/os/distro/codename.rb +3 -4
  76. data/lib/facter/facts/sles/os/distro/description.rb +2 -5
  77. data/lib/facter/facts/sles/os/distro/id.rb +6 -5
  78. data/lib/facter/facts/sles/os/distro/release.rb +17 -12
  79. data/lib/facter/facts/solaris/hypervisors/ldom.rb +1 -1
  80. data/lib/facter/facts/solaris/hypervisors/zone.rb +1 -1
  81. data/lib/facter/facts/solaris/mountpoints.rb +1 -1
  82. data/lib/facter/facts/solaris/processors/cores.rb +16 -0
  83. data/lib/facter/facts/solaris/processors/threads.rb +16 -0
  84. data/lib/facter/facts/ubuntu/lsbdistrelease.rb +2 -2
  85. data/lib/facter/facts/windows/az_metadata.rb +23 -0
  86. data/lib/facter/facts/windows/cloud/provider.rb +21 -0
  87. data/lib/facter/facts/windows/ec2_metadata.rb +1 -1
  88. data/lib/facter/facts/windows/ec2_userdata.rb +1 -1
  89. data/lib/facter/facts/windows/gce.rb +1 -1
  90. data/lib/facter/facts/windows/hypervisors/hyperv.rb +1 -1
  91. data/lib/facter/facts/windows/hypervisors/kvm.rb +2 -1
  92. data/lib/facter/facts/windows/hypervisors/virtualbox.rb +2 -2
  93. data/lib/facter/facts/windows/hypervisors/vmware.rb +1 -1
  94. data/lib/facter/facts/windows/hypervisors/xen.rb +3 -1
  95. data/lib/facter/facts/windows/is_virtual.rb +15 -0
  96. data/lib/facter/facts/windows/{virtualization/is_virtual.rb → processors/cores.rb} +4 -4
  97. data/lib/facter/facts/windows/{virtualization/virtual.rb → processors/threads.rb} +4 -4
  98. data/lib/facter/facts/windows/virtual.rb +15 -0
  99. data/lib/facter/framework/cli/cli.rb +6 -8
  100. data/lib/facter/framework/config/config_reader.rb +2 -0
  101. data/lib/facter/framework/config/fact_groups.rb +25 -2
  102. data/lib/facter/framework/core/cache_manager.rb +7 -3
  103. data/lib/facter/framework/core/fact/external/external_fact_manager.rb +0 -1
  104. data/lib/facter/framework/core/fact/internal/internal_fact_manager.rb +41 -39
  105. data/lib/facter/framework/core/fact_filter.rb +5 -15
  106. data/lib/facter/framework/core/fact_loaders/external_fact_loader.rb +9 -6
  107. data/lib/facter/framework/core/fact_loaders/fact_loader.rb +39 -37
  108. data/lib/facter/framework/core/fact_manager.rb +84 -14
  109. data/lib/facter/framework/core/file_loader.rb +1 -1
  110. data/lib/facter/framework/core/options.rb +1 -2
  111. data/lib/facter/framework/core/options/config_file_options.rb +7 -0
  112. data/lib/facter/framework/core/options/option_store.rb +12 -6
  113. data/lib/facter/framework/formatters/formatter_helper.rb +3 -5
  114. data/lib/facter/framework/logging/logger.rb +4 -4
  115. data/lib/facter/framework/parsers/query_parser.rb +5 -12
  116. data/lib/facter/models/fact_collection.rb +48 -5
  117. data/lib/facter/models/resolved_fact.rb +2 -3
  118. data/lib/facter/models/searched_fact.rb +2 -3
  119. data/lib/facter/resolvers/aix/ffi/ffi_helper.rb +1 -1
  120. data/lib/facter/resolvers/aix/processors.rb +4 -0
  121. data/lib/facter/resolvers/az.rb +39 -0
  122. data/lib/facter/resolvers/base_resolver.rb +2 -2
  123. data/lib/facter/resolvers/dmi_decode.rb +0 -1
  124. data/lib/facter/resolvers/linux/hostname.rb +126 -0
  125. data/lib/facter/resolvers/linux/networking.rb +124 -0
  126. data/lib/facter/resolvers/macosx/mountpoints.rb +14 -1
  127. data/lib/facter/resolvers/macosx/processor.rb +16 -1
  128. data/lib/facter/resolvers/mountpoints.rb +16 -8
  129. data/lib/facter/resolvers/networking.rb +3 -2
  130. data/lib/facter/resolvers/partitions.rb +1 -1
  131. data/lib/facter/resolvers/processors_lscpu.rb +44 -0
  132. data/lib/facter/resolvers/redhat_release.rb +28 -12
  133. data/lib/facter/resolvers/ruby.rb +1 -1
  134. data/lib/facter/resolvers/selinux.rb +5 -7
  135. data/lib/facter/resolvers/solaris/ffi/functions.rb +1 -1
  136. data/lib/facter/resolvers/solaris/ffi/structs.rb +12 -0
  137. data/lib/facter/resolvers/solaris/mountpoints.rb +22 -16
  138. data/lib/facter/resolvers/solaris/networking.rb +20 -5
  139. data/lib/facter/resolvers/solaris/processors.rb +7 -0
  140. data/lib/facter/resolvers/solaris/zone.rb +0 -1
  141. data/lib/facter/resolvers/windows/ffi/identity_ffi.rb +5 -0
  142. data/lib/facter/resolvers/windows/identity.rb +1 -6
  143. data/lib/facter/resolvers/windows/processors.rb +41 -4
  144. data/lib/facter/resolvers/windows/uptime.rb +3 -22
  145. data/lib/facter/resolvers/windows/virtualization.rb +46 -44
  146. data/lib/facter/resolvers/xen.rb +6 -1
  147. data/lib/facter/templates/man.erb +13 -5
  148. data/lib/facter/util/facts/posix/virtual_detector.rb +74 -0
  149. data/lib/facter/util/facts/unit_converter.rb +2 -2
  150. data/lib/facter/util/linux/dhcp.rb +86 -0
  151. data/lib/facter/util/linux/if_inet6.rb +73 -0
  152. data/lib/facter/util/linux/routing_table.rb +60 -0
  153. data/lib/facter/util/linux/socket_parser.rb +114 -0
  154. data/lib/facter/util/resolvers/ffi/hostname.rb +70 -0
  155. data/lib/facter/util/resolvers/http.rb +7 -1
  156. data/lib/facter/util/resolvers/networking/primary_interface.rb +11 -5
  157. data/lib/facter/util/utils.rb +18 -1
  158. data/lib/facter/version.rb +1 -1
  159. metadata +63 -13
  160. data/lib/facter/facts/linux/cloud.rb +0 -15
  161. data/lib/facter/framework/core/fact_augmenter.rb +0 -37
  162. data/lib/facter/resolvers/cloud.rb +0 -39
  163. data/lib/facter/resolvers/networking_linux.rb +0 -296
  164. data/lib/facter/util/facts/virtual_detector.rb +0 -90
@@ -14,23 +14,26 @@ module Facter
14
14
  @fact_list.fetch(fact_name) { read_mounts(fact_name) }
15
15
  end
16
16
 
17
- def root_device
18
- cmdline = Facter::Util::FileHelper.safe_read('/proc/cmdline')
19
- match = cmdline.match(/root=([^\s]+)/)
20
- match&.captures&.first
21
- end
22
-
23
- def compute_device(device)
24
- # If the "root" device, lookup the actual device from the kernel options
25
- # This is done because not all systems symlink /dev/root
26
- device = root_device if device == '/dev/root'
27
- device
17
+ def exclude_auto_home_mounts!
18
+ @mounts.reject! do |mount|
19
+ parent = mount[:path].rpartition('/').first
20
+ @auto_home_paths.include?(parent)
21
+ end
28
22
  end
29
23
 
30
24
  def read_mounts(fact_name) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
31
- mounts = []
25
+ @mounts = []
26
+ @auto_home_paths = []
27
+
32
28
  Facter::Util::Resolvers::FilesystemHelper.read_mountpoints.each do |fs|
33
- device = compute_device(fs.name)
29
+ if fs.name == 'auto_home'
30
+ @auto_home_paths << fs.mount_point
31
+ next
32
+ end
33
+
34
+ next if fs.mount_type == 'autofs'
35
+
36
+ device = fs.name
34
37
  filesystem = fs.mount_type
35
38
  path = fs.mount_point
36
39
  options = fs.options.split(',').map(&:strip)
@@ -47,11 +50,14 @@ module Facter
47
50
  available = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(available_bytes)
48
51
  used = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(used_bytes)
49
52
 
50
- mounts << Hash[Facter::Util::Resolvers::FilesystemHelper::MOUNT_KEYS
51
- .zip(Facter::Util::Resolvers::FilesystemHelper::MOUNT_KEYS
53
+ @mounts << Hash[Facter::Util::Resolvers::FilesystemHelper::MOUNT_KEYS
54
+ .zip(Facter::Util::Resolvers::FilesystemHelper::MOUNT_KEYS
52
55
  .map { |v| binding.local_variable_get(v) })]
53
56
  end
54
- @fact_list[:mountpoints] = mounts
57
+
58
+ exclude_auto_home_mounts!
59
+
60
+ @fact_list[:mountpoints] = @mounts
55
61
  @fact_list[fact_name]
56
62
  end
57
63
  end
@@ -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
@@ -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,18 +13,26 @@ 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| -%>
24
+ * `<%= command.usage %>`:
25
+
26
+ <%= command.description %>
27
+
28
+
29
+ <% end -%>
30
+
23
31
  FILES
24
32
  -----
25
33
  <em>/etc/puppetlabs/facter/facter.conf</em>
26
34
 
27
- 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).
28
36
 
29
37
  EXAMPLES
30
38
  --------
@@ -47,7 +55,7 @@ dmi => {
47
55
  version => "6.00"
48
56
  }
49
57
  }
50
- [\.\.\.]
58
+ [...]
51
59
  ```
52
60
 
53
61
  Display a single structured fact:
@@ -83,7 +91,7 @@ $ facter processorcount
83
91
  Format facts as JSON:
84
92
 
85
93
  ```
86
- $ facter \-\-json os.name os.release.major processors.isa
94
+ $ facter --json os.name os.release.major processors.isa
87
95
  {
88
96
  "os.name": "Ubuntu",
89
97
  "os.release.major": "14.04",
@@ -112,7 +120,7 @@ cli : {
112
120
  verbose : false,
113
121
  log-level : "info"
114
122
  }
115
- # always loaded, fact-sepcific configuration
123
+ # always loaded, fact-specific configuration
116
124
  facts : {
117
125
  # for valid blocklist entries, use --list-block-groups
118
126
  blocklist : [ "file system", "EC2" ],