facter 4.0.46 → 4.0.47

Sign up to get free protection for your applications and to get access to all the features.
Files changed (208) hide show
  1. checksums.yaml +4 -4
  2. data/lib/docs/generate.rb +32 -0
  3. data/lib/docs/template.erb +34 -0
  4. data/lib/facter.rb +38 -6
  5. data/lib/facter/config.rb +32 -1
  6. data/lib/facter/custom_facts/util/collection.rb +1 -2
  7. data/lib/facter/custom_facts/util/directory_loader.rb +1 -1
  8. data/lib/facter/custom_facts/util/fact.rb +18 -1
  9. data/lib/facter/custom_facts/util/loader.rb +1 -1
  10. data/lib/facter/custom_facts/util/resolution.rb +1 -1
  11. data/lib/facter/facts/aix/interfaces.rb +1 -0
  12. data/lib/facter/facts/aix/memory/swap/available.rb +1 -1
  13. data/lib/facter/facts/aix/memory/swap/available_bytes.rb +1 -1
  14. data/lib/facter/facts/aix/memory/swap/total.rb +1 -1
  15. data/lib/facter/facts/aix/memory/swap/total_bytes.rb +1 -1
  16. data/lib/facter/facts/aix/memory/swap/used.rb +1 -1
  17. data/lib/facter/facts/aix/memory/system/available.rb +1 -1
  18. data/lib/facter/facts/aix/memory/system/available_bytes.rb +1 -1
  19. data/lib/facter/facts/aix/memory/system/total.rb +1 -1
  20. data/lib/facter/facts/aix/memory/system/total_bytes.rb +1 -1
  21. data/lib/facter/facts/aix/memory/system/used.rb +1 -1
  22. data/lib/facter/facts/aix/processors/speed.rb +1 -1
  23. data/lib/facter/facts/bsd/processors/speed.rb +1 -1
  24. data/lib/facter/facts/freebsd/is_virtual.rb +25 -0
  25. data/lib/facter/facts/freebsd/memory/swap/available.rb +1 -1
  26. data/lib/facter/facts/freebsd/memory/swap/available_bytes.rb +1 -1
  27. data/lib/facter/facts/freebsd/memory/swap/total.rb +1 -1
  28. data/lib/facter/facts/freebsd/memory/swap/total_bytes.rb +1 -1
  29. data/lib/facter/facts/freebsd/memory/swap/used.rb +1 -1
  30. data/lib/facter/facts/freebsd/memory/system/available.rb +1 -1
  31. data/lib/facter/facts/freebsd/memory/system/available_bytes.rb +1 -1
  32. data/lib/facter/facts/freebsd/memory/system/total.rb +1 -1
  33. data/lib/facter/facts/freebsd/memory/system/total_bytes.rb +1 -1
  34. data/lib/facter/facts/freebsd/memory/system/used.rb +1 -1
  35. data/lib/facter/facts/freebsd/processors/speed.rb +1 -1
  36. data/lib/facter/facts/freebsd/virtual.rb +22 -0
  37. data/lib/facter/facts/linux/dhcp_servers.rb +1 -0
  38. data/lib/facter/facts/linux/ec2_metadata.rb +1 -1
  39. data/lib/facter/facts/linux/ec2_userdata.rb +1 -1
  40. data/lib/facter/facts/linux/hypervisors/kvm.rb +1 -1
  41. data/lib/facter/facts/linux/hypervisors/xen.rb +1 -1
  42. data/lib/facter/facts/linux/interfaces.rb +1 -0
  43. data/lib/facter/facts/linux/is_virtual.rb +2 -2
  44. data/lib/facter/facts/linux/memory/swap/available.rb +1 -1
  45. data/lib/facter/facts/linux/memory/swap/available_bytes.rb +1 -1
  46. data/lib/facter/facts/linux/memory/swap/total.rb +1 -1
  47. data/lib/facter/facts/linux/memory/swap/total_bytes.rb +1 -1
  48. data/lib/facter/facts/linux/memory/swap/used.rb +1 -1
  49. data/lib/facter/facts/linux/memory/system/available.rb +1 -1
  50. data/lib/facter/facts/linux/memory/system/available_bytes.rb +1 -1
  51. data/lib/facter/facts/linux/memory/system/total.rb +1 -1
  52. data/lib/facter/facts/linux/memory/system/total_bytes.rb +1 -1
  53. data/lib/facter/facts/linux/memory/system/used.rb +1 -1
  54. data/lib/facter/facts/linux/processors/speed.rb +1 -1
  55. data/lib/facter/facts/linux/virtual.rb +1 -1
  56. data/lib/facter/facts/macosx/dhcp_servers.rb +1 -0
  57. data/lib/facter/facts/macosx/interfaces.rb +1 -0
  58. data/lib/facter/facts/macosx/memory/swap/available.rb +1 -1
  59. data/lib/facter/facts/macosx/memory/swap/available_bytes.rb +1 -1
  60. data/lib/facter/facts/macosx/memory/swap/total.rb +1 -1
  61. data/lib/facter/facts/macosx/memory/swap/total_bytes.rb +1 -1
  62. data/lib/facter/facts/macosx/memory/swap/used.rb +1 -1
  63. data/lib/facter/facts/macosx/memory/system/available.rb +1 -1
  64. data/lib/facter/facts/macosx/memory/system/available_bytes.rb +1 -1
  65. data/lib/facter/facts/macosx/memory/system/total.rb +1 -1
  66. data/lib/facter/facts/macosx/memory/system/total_bytes.rb +1 -1
  67. data/lib/facter/facts/macosx/memory/system/used.rb +1 -1
  68. data/lib/facter/facts/macosx/processors/speed.rb +1 -1
  69. data/lib/facter/facts/solaris/dhcp_servers.rb +1 -0
  70. data/lib/facter/facts/solaris/interfaces.rb +1 -0
  71. data/lib/facter/facts/solaris/is_virtual.rb +2 -2
  72. data/lib/facter/facts/solaris/ldom.rb +31 -4
  73. data/lib/facter/facts/solaris/memory/swap/available.rb +1 -1
  74. data/lib/facter/facts/solaris/memory/swap/available_bytes.rb +1 -1
  75. data/lib/facter/facts/solaris/memory/swap/total.rb +1 -1
  76. data/lib/facter/facts/solaris/memory/swap/total_bytes.rb +1 -1
  77. data/lib/facter/facts/solaris/memory/swap/used.rb +1 -1
  78. data/lib/facter/facts/solaris/memory/system/available.rb +1 -1
  79. data/lib/facter/facts/solaris/memory/system/available_bytes.rb +1 -1
  80. data/lib/facter/facts/solaris/memory/system/total.rb +1 -1
  81. data/lib/facter/facts/solaris/memory/system/total_bytes.rb +1 -1
  82. data/lib/facter/facts/solaris/memory/system/used.rb +1 -1
  83. data/lib/facter/facts/solaris/processors/speed.rb +1 -1
  84. data/lib/facter/facts/solaris/virtual.rb +1 -1
  85. data/lib/facter/facts/windows/dhcp_servers.rb +1 -0
  86. data/lib/facter/facts/windows/interfaces.rb +1 -0
  87. data/lib/facter/facts/windows/memory/system/available.rb +1 -1
  88. data/lib/facter/facts/windows/memory/system/available_bytes.rb +1 -1
  89. data/lib/facter/facts/windows/memory/system/total.rb +1 -1
  90. data/lib/facter/facts/windows/memory/system/total_bytes.rb +1 -1
  91. data/lib/facter/facts/windows/memory/system/used.rb +1 -1
  92. data/lib/facter/facts/windows/os/release.rb +1 -1
  93. data/lib/facter/framework/cli/cli.rb +1 -1
  94. data/lib/facter/framework/core/cache_manager.rb +1 -1
  95. data/lib/facter/framework/core/fact_loaders/external_fact_loader.rb +4 -2
  96. data/lib/facter/framework/core/fact_loaders/fact_loader.rb +16 -0
  97. data/lib/facter/framework/core/fact_manager.rb +14 -2
  98. data/lib/facter/framework/core/file_loader.rb +6 -2
  99. data/lib/facter/framework/core/options/option_store.rb +2 -2
  100. data/lib/facter/framework/logging/logger.rb +3 -3
  101. data/lib/facter/models/fact_collection.rb +11 -1
  102. data/lib/facter/models/loaded_fact.rb +2 -1
  103. data/lib/facter/resolvers/aio_agent_version.rb +1 -1
  104. data/lib/facter/resolvers/aix/architecture_resolver.rb +3 -3
  105. data/lib/facter/resolvers/aix/disks.rb +4 -4
  106. data/lib/facter/resolvers/aix/filesystem_resolver.rb +1 -1
  107. data/lib/facter/resolvers/aix/hardware_resolver.rb +2 -2
  108. data/lib/facter/resolvers/aix/memory.rb +2 -2
  109. data/lib/facter/resolvers/aix/mountpoints.rb +4 -4
  110. data/lib/facter/resolvers/aix/networking_resolver.rb +3 -2
  111. data/lib/facter/resolvers/aix/partitions.rb +5 -5
  112. data/lib/facter/resolvers/aix/processors.rb +3 -3
  113. data/lib/facter/resolvers/aix/serialnumber.rb +1 -1
  114. data/lib/facter/resolvers/base_resolver.rb +3 -0
  115. data/lib/facter/resolvers/cloud.rb +1 -1
  116. data/lib/facter/resolvers/containers.rb +3 -3
  117. data/lib/facter/resolvers/debian_version.rb +1 -1
  118. data/lib/facter/resolvers/disk_resolver.rb +2 -2
  119. data/lib/facter/resolvers/dmi_resolver.rb +1 -1
  120. data/lib/facter/resolvers/ec2.rb +3 -1
  121. data/lib/facter/resolvers/eos_release_resolver.rb +1 -1
  122. data/lib/facter/resolvers/filesystems_resolver.rb +1 -1
  123. data/lib/facter/resolvers/fips_enabled_resolver.rb +1 -1
  124. data/lib/facter/resolvers/freebsd/geom_resolver.rb +1 -1
  125. data/lib/facter/resolvers/freebsd/swap_memory_resolver.rb +3 -2
  126. data/lib/facter/resolvers/freebsd/system_memory_resolver.rb +2 -1
  127. data/lib/facter/resolvers/freebsd/virtual_resolver.rb +45 -0
  128. data/lib/facter/resolvers/gce.rb +1 -1
  129. data/lib/facter/resolvers/hostname_resolver.rb +67 -20
  130. data/lib/facter/resolvers/linux/docker_uptime.rb +1 -1
  131. data/lib/facter/resolvers/linux/load_averages.rb +1 -1
  132. data/lib/facter/resolvers/load_averages.rb +3 -2
  133. data/lib/facter/resolvers/macosx/mountpoints_resolver.rb +7 -7
  134. data/lib/facter/resolvers/macosx/system_profiler_resolver.rb +3 -3
  135. data/lib/facter/resolvers/memory_resolver.rb +1 -1
  136. data/lib/facter/resolvers/mountpoints_resolver.rb +8 -8
  137. data/lib/facter/resolvers/networking_linux_resolver.rb +183 -85
  138. data/lib/facter/resolvers/networking_resolver.rb +8 -5
  139. data/lib/facter/resolvers/open_vz.rb +1 -3
  140. data/lib/facter/resolvers/os_release_resolver.rb +1 -1
  141. data/lib/facter/resolvers/partitions.rb +5 -5
  142. data/lib/facter/resolvers/processors_resolver.rb +2 -2
  143. data/lib/facter/resolvers/redhat_release_resolver.rb +1 -1
  144. data/lib/facter/resolvers/selinux_resolver.rb +3 -3
  145. data/lib/facter/resolvers/solaris/disks.rb +1 -1
  146. data/lib/facter/resolvers/solaris/memory.rb +2 -2
  147. data/lib/facter/resolvers/solaris/mountpoints.rb +11 -10
  148. data/lib/facter/resolvers/solaris/networking.rb +49 -41
  149. data/lib/facter/resolvers/solaris/os_release.rb +1 -1
  150. data/lib/facter/resolvers/ssh_resolver.rb +3 -2
  151. data/lib/facter/resolvers/suse_release_resolver.rb +1 -1
  152. data/lib/facter/resolvers/uptime_resolver.rb +2 -2
  153. data/lib/facter/resolvers/windows/aio_agent_version.rb +1 -1
  154. data/lib/facter/resolvers/windows/dmi_bios_resolver.rb +1 -1
  155. data/lib/facter/resolvers/windows/dmi_computersystem_resolver.rb +1 -1
  156. data/lib/facter/resolvers/windows/memory_resolver.rb +4 -0
  157. data/lib/facter/resolvers/windows/networking_resolver.rb +3 -3
  158. data/lib/facter/resolvers/windows/processors_resolver.rb +1 -1
  159. data/lib/facter/resolvers/windows/ssh.rb +2 -2
  160. data/lib/facter/resolvers/windows/uptime_resolver.rb +1 -1
  161. data/lib/facter/resolvers/windows/virtualization_resolver.rb +1 -1
  162. data/lib/facter/resolvers/windows/win_os_description_resolver.rb +1 -1
  163. data/lib/facter/resolvers/xen.rb +1 -1
  164. data/lib/facter/util/aix/info_extractor.rb +24 -0
  165. data/lib/facter/util/aix/odm_query.rb +46 -0
  166. data/lib/facter/util/api_debugger.rb +33 -29
  167. data/lib/facter/util/facts/facts_utils.rb +14 -0
  168. data/lib/facter/util/facts/unit_converter.rb +61 -0
  169. data/lib/facter/util/facts/uptime_parser.rb +128 -0
  170. data/lib/facter/util/facts/virtual_detector.rb +90 -0
  171. data/lib/facter/util/facts/windows_release_finder.rb +55 -0
  172. data/lib/facter/{resolvers/macosx/utils → util/macosx}/system_profile_executor.rb +1 -1
  173. data/lib/facter/util/resolvers/aws_token.rb +37 -0
  174. data/lib/facter/{resolvers/utils → util/resolvers}/ffi/load_averages.rb +2 -2
  175. data/lib/facter/util/resolvers/filesystem_helper.rb +47 -0
  176. data/lib/facter/util/resolvers/fingerprint.rb +15 -0
  177. data/lib/facter/{resolvers/utils → util/resolvers}/http.rb +17 -10
  178. data/lib/facter/util/resolvers/networking.rb +90 -0
  179. data/lib/facter/util/resolvers/networking/dhcp.rb +21 -0
  180. data/lib/facter/util/resolvers/networking/networking.rb +109 -0
  181. data/lib/facter/util/resolvers/networking/primary_interface.rb +82 -0
  182. data/lib/facter/util/resolvers/ssh.rb +17 -0
  183. data/lib/facter/util/resolvers/ssh_helper.rb +31 -0
  184. data/lib/facter/{resolvers/utils → util/resolvers}/uptime_helper.rb +2 -2
  185. data/lib/facter/{framework/utils → util}/utils.rb +0 -0
  186. data/lib/facter/util/windows/win32ole.rb +30 -0
  187. data/lib/facter/version.rb +1 -1
  188. metadata +29 -41
  189. data/lib/facter/facts/aix/puppet_version.rb +0 -15
  190. data/lib/facter/facts/freebsd/puppet_version.rb +0 -15
  191. data/lib/facter/facts/linux/puppet_version.rb +0 -15
  192. data/lib/facter/facts/macosx/puppet_version.rb +0 -15
  193. data/lib/facter/facts/solaris/puppet_version.rb +0 -15
  194. data/lib/facter/facts/windows/puppet_version.rb +0 -15
  195. data/lib/facter/facts_utils/facts_utils.rb +0 -12
  196. data/lib/facter/facts_utils/unit_converter.rb +0 -59
  197. data/lib/facter/facts_utils/uptime_parser.rb +0 -124
  198. data/lib/facter/facts_utils/virtual_detector.rb +0 -78
  199. data/lib/facter/facts_utils/windows_release_finder.rb +0 -51
  200. data/lib/facter/resolvers/aix/utils/info_extractor.rb +0 -20
  201. data/lib/facter/resolvers/aix/utils/odm_query.rb +0 -42
  202. data/lib/facter/resolvers/puppet_version_resolver.rb +0 -26
  203. data/lib/facter/resolvers/utils/filesystem_helper.rb +0 -43
  204. data/lib/facter/resolvers/utils/fingerprint.rb +0 -11
  205. data/lib/facter/resolvers/utils/networking.rb +0 -88
  206. data/lib/facter/resolvers/utils/ssh.rb +0 -13
  207. data/lib/facter/resolvers/utils/ssh_helper.rb +0 -27
  208. data/lib/facter/resolvers/windows/utils/win32ole.rb +0 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71eb4894f5e565033d547ffb64d562aee98c6b6a082bca7387259f9a779830d8
4
- data.tar.gz: 95331a72cf0dc86fabbcad33447724a3a55b536c366bb8ba356428fddefd1587
3
+ metadata.gz: 87e1b483df51f967d4e88c90f67ddfef304184d235d08746500c61619c56dee2
4
+ data.tar.gz: d573d4d221bc71e512c36a2f8218b0d70512ace56cb0eaa37dba3a9eee27bcde
5
5
  SHA512:
6
- metadata.gz: 24caa700190be726fa0a7dc0f7dbbac290e073fab078c32b2b67d8a79c336daeab4c3254389a58e7bb4538706c8b8114d609173b78c31e7d676ca50d21a3bcb7
7
- data.tar.gz: 9edcd692bfe2b0de59a6a6bf6f1700387e25da56127148ffd656edb901fc7fa47db7fe61eae3e4bf17ac8ddaa17e655c65ed366ef3fcc79db2a28e20ab1e6a37
6
+ metadata.gz: 49f5a8c11e45cdc6e9550e6fa50335700b8c43c048b46b1f091ea4b4a1f66588865a36c2ca1b447bea72c80a1548ca37d6f998eca4187047c6f2e95b2daf87d5
7
+ data.tar.gz: b6b21071a59dbfedc1499b6464e2556aa272f9fc99feb1674c6961a1a3a564570e9a7df127ad80140703ee320f73b1e41c82deec41dfb4160814544f1a0ae2d4
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Generates a markdown file containing fact documentation.
5
+ # usage: ruby generate.rb > facts.md
6
+
7
+ require 'yaml'
8
+ require 'erb'
9
+ require 'ostruct'
10
+
11
+ PATH_TO_SCHEMA = File.join(File.dirname(__FILE__), '../schema/facter.yaml')
12
+ PATH_TO_TEMPLATE = File.join(File.dirname(__FILE__), 'template.erb')
13
+
14
+ schema = YAML.load_file(PATH_TO_SCHEMA)
15
+
16
+ def format_facts(fact_hash)
17
+ scope = OpenStruct.new({
18
+ facts: fact_hash
19
+ })
20
+
21
+ erb = if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
22
+ ERB.new(File.read(PATH_TO_TEMPLATE), trim_mode: '-')
23
+ else
24
+ ERB.new(File.read(PATH_TO_TEMPLATE), nil, '-')
25
+ end
26
+ erb.result(scope.instance_eval { binding })
27
+ end
28
+
29
+ print "## Modern Facts\n\n"
30
+ print format_facts(schema.reject { |_name, info| info['hidden'] == true })
31
+ print "## Legacy Facts\n\n"
32
+ print format_facts(schema.reject { |_name, info| info['hidden'].nil? || info['hidden'] == false })
@@ -0,0 +1,34 @@
1
+ <%# This template is used to generate a markdown file documenting facts. -%>
2
+ <%# Run 'ruby generate.rb > facts.md' to generate the markdown file. -%>
3
+ <%
4
+ def format_fact_element(name, info, indent = '')
5
+ subelements = (info['elements'] || {}).map{|n, i| format_fact_element(n, i, "#{indent} ")}.join('')
6
+
7
+ "#{indent}* `#{name}` (#{info['type']}) --- #{info['description']}\n#{subelements}"
8
+ end
9
+ -%>
10
+ <% facts.each do |name, schema| -%>
11
+ ### `<%= name %>`
12
+
13
+ <% if schema['hidden'] -%>
14
+ This legacy fact is hidden by default in Facter's command-line output.
15
+
16
+ <% end -%>
17
+ **Type:** <%= schema['type'] %>
18
+
19
+ **Purpose:**
20
+
21
+ <%= schema['description'] %>
22
+
23
+ <% if schema['elements'] -%>
24
+ **Elements:**
25
+
26
+ <%= schema['elements'].map{|name, info| format_fact_element(name, info)}.join('') %>
27
+ <% end -%>
28
+
29
+ <% if schema['details'] -%>
30
+ **Details:**
31
+
32
+ <%= schema['details'] %>
33
+ <% end -%>
34
+ <% end -%>
@@ -261,6 +261,26 @@ module Facter
261
261
  nil
262
262
  end
263
263
 
264
+ # Enables/Disables external facts.
265
+ # @param enable_external [boolean]
266
+ #
267
+ # @return nil
268
+ #
269
+ # @api public
270
+ def load_external(enable_external)
271
+ # enable_external param needs negation because behind the scene
272
+ # no_external_facts= method is negating the parameter again.
273
+ Options[:no_external_facts] = !enable_external
274
+
275
+ if enable_external
276
+ logger.debug('Facter.load_external(true) called. External facts will be loaded')
277
+ else
278
+ logger.debug('Facter.load_external(false) called. External facts will NOT be loaded')
279
+ end
280
+
281
+ nil
282
+ end
283
+
264
284
  # Register directories to be searched for custom facts. The registered directories
265
285
  # must be absolute paths or they will be ignored.
266
286
  # @param dirs [Array<String>] An array of searched directories
@@ -310,9 +330,12 @@ module Facter
310
330
  # @api public
311
331
  def to_hash
312
332
  log_blocked_facts
333
+ logger.debug("Facter version: #{Facter::VERSION}")
313
334
 
314
335
  resolved_facts = Facter::FactManager.instance.resolve_facts
315
- Facter::FactCollection.new.build_fact_collection!(resolved_facts)
336
+ resolved_facts.reject! { |fact| fact.type == :custom && fact.value.nil? }
337
+ collection = Facter::FactCollection.new.build_fact_collection!(resolved_facts)
338
+ Hash[collection]
316
339
  end
317
340
 
318
341
  # Check whether printing stack trace is enabled
@@ -361,6 +384,7 @@ module Facter
361
384
  Options[:show_legacy] = true
362
385
  log_blocked_facts
363
386
  resolved_facts = Facter::FactManager.instance.resolve_facts(user_queries)
387
+ resolved_facts.reject! { |fact| fact.type == :custom && fact.value.nil? }
364
388
 
365
389
  if user_queries.count.zero?
366
390
  Facter::FactCollection.new.build_fact_collection!(resolved_facts)
@@ -386,13 +410,13 @@ module Facter
386
410
  def to_user_output(cli_options, *args)
387
411
  init_cli_options(cli_options, args)
388
412
  logger.info("executed with command line: #{ARGV.drop(1).join(' ')}")
413
+ logger.debug("Facter version: #{Facter::VERSION}")
389
414
  log_blocked_facts
390
- resolved_facts = Facter::FactManager.instance.resolve_facts(args)
415
+ resolved_facts = resolve_facts_for_user_query(args)
391
416
  fact_formatter = Facter::FormatterFactory.build(Facter::Options.get)
392
-
393
417
  status = error_check(resolved_facts)
394
418
 
395
- [fact_formatter.format(resolved_facts), status || 0]
419
+ [fact_formatter.format(resolved_facts), status]
396
420
  end
397
421
 
398
422
  # Logs an exception and an optional message
@@ -446,6 +470,15 @@ module Facter
446
470
 
447
471
  private
448
472
 
473
+ def resolve_facts_for_user_query(user_query)
474
+ resolved_facts = Facter::FactManager.instance.resolve_facts(user_query)
475
+ user_querie = resolved_facts.uniq(&:user_query).map(&:user_query).first
476
+
477
+ resolved_facts.reject! { |fact| fact.type == :custom && fact.value.nil? } if user_querie&.empty?
478
+
479
+ resolved_facts
480
+ end
481
+
449
482
  def parse_exception(exception, error_message)
450
483
  if exception.is_a?(Exception)
451
484
  error_message << exception.message if error_message.empty?
@@ -504,14 +537,13 @@ module Facter
504
537
  #
505
538
  # @api private
506
539
  def error_check(resolved_facts)
540
+ status = 0
507
541
  if Options[:strict]
508
542
  missing_names = resolved_facts.select { |fact| fact.type == :nil }.map(&:user_query)
509
543
 
510
544
  if missing_names.count.positive?
511
545
  status = 1
512
546
  log_errors(missing_names)
513
- else
514
- status = nil
515
547
  end
516
548
  end
517
549
 
@@ -42,6 +42,9 @@ module Facter
42
42
  end
43
43
  unless defined? FACT_GROUPS
44
44
  FACT_GROUPS = {
45
+ 'AIX NIM type' => [
46
+ 'nim_type'
47
+ ],
45
48
  'EC2' => %w[
46
49
  ec2_metadata
47
50
  ec2_userdata
@@ -49,6 +52,10 @@ module Facter
49
52
  'GCE' => [
50
53
  'gce'
51
54
  ],
55
+ 'Xen' => %w[
56
+ xen
57
+ xendomains
58
+ ],
52
59
  'augeas' => %w[
53
60
  augeas
54
61
  augeasversion
@@ -69,11 +76,18 @@ module Facter
69
76
  uuid
70
77
  chassistype
71
78
  ],
79
+ 'disks' => %w[
80
+ blockdevices
81
+ disks
82
+ ],
72
83
  'file system' => %w[
73
84
  mountpoints
74
85
  filesystems
75
86
  partitions
76
87
  ],
88
+ 'fips' => [
89
+ 'fips_enabled'
90
+ ],
77
91
  'hypervisors' => [
78
92
  'hypervisors'
79
93
  ],
@@ -112,12 +126,12 @@ module Facter
112
126
  netmask6
113
127
  network
114
128
  network6
129
+ scope6
115
130
  macaddress
116
131
  interfaces
117
132
  domain
118
133
  fqdn
119
134
  dhcp_servers
120
- scope6
121
135
  ],
122
136
  'operating system' => %w[
123
137
  os
@@ -210,6 +224,23 @@ module Facter
210
224
  is_virtual
211
225
  cloud
212
226
  ],
227
+ 'ldom' => [
228
+ 'ldom'
229
+ ],
230
+ 'Solaris zone' => %w[
231
+ zones
232
+ zonename
233
+ solaris_zones
234
+ ],
235
+ 'ZFS' => %w[
236
+ zfs_version
237
+ zfs_featurenumbers
238
+ ],
239
+ 'ZFS storage pool' => %w[
240
+ zpool_version
241
+ zpool_featureflags
242
+ zpool_featurenumbers
243
+ ],
213
244
  'legacy' => [
214
245
  'architecture',
215
246
  'augeasversion',
@@ -115,8 +115,7 @@ module LegacyFacter
115
115
  internal_loader.load_all unless @loaded
116
116
  @loaded = true
117
117
 
118
- custom_facts = @facts.select { |_k, v| v.options[:fact_type] == :custom }
119
- @custom_facts = Facter::Utils.deep_copy(custom_facts.keys)
118
+ @custom_facts = @facts.select { |_k, v| v.options[:fact_type] == :custom }
120
119
  end
121
120
 
122
121
  def load(name)
@@ -109,7 +109,7 @@ module LegacyFacter
109
109
 
110
110
  def entries
111
111
  dirs = @directories.select { |directory| File.directory?(directory) }.map do |directory|
112
- Dir.entries(directory).map { |directory_entry| File.join(directory, directory_entry) }
112
+ Dir.entries(directory).map { |directory_entry| File.join(directory, directory_entry) }.sort.reverse!
113
113
  end
114
114
  dirs.flatten.select { |f| should_parse?(f) }
115
115
  rescue Errno::ENOENT
@@ -173,7 +173,24 @@ module Facter
173
173
  end
174
174
 
175
175
  def sort_by_weight(resolutions)
176
- resolutions.sort { |a, b| b <=> a }
176
+ # sort resolutions:
177
+ # - descending by weight
178
+ # - multiple facts have the same weight but different types, the :external fact take precedence
179
+ # - multiple facts with the same weight and type, the order is preserved.
180
+ # note: sort_by with index is slower than .sort
181
+ # we cannot use .sort because it is not stable: https://bugs.ruby-lang.org/issues/1089
182
+ # solution from: https://bugs.ruby-lang.org/issues/1089#note-10
183
+
184
+ # rubocop:disable Style/NestedTernaryOperator
185
+ idx = 0
186
+ resolutions.sort_by do |x|
187
+ [
188
+ -x.weight,
189
+ x.respond_to?(:fact_type) ? x.fact_type == :external ? 0 : 1 : 1,
190
+ idx += 1
191
+ ]
192
+ end
193
+ # rubocop:enable Style/NestedTernaryOperator
177
194
  end
178
195
 
179
196
  def find_first_real_value(resolutions)
@@ -143,7 +143,7 @@ module LegacyFacter
143
143
  # match it.
144
144
  next if fact && (env_name != fact)
145
145
 
146
- LegacyFacter.add(Regexp.last_match(1), fact_type: :external) do
146
+ LegacyFacter.add(Regexp.last_match(1), fact_type: :external, is_env: true) do
147
147
  has_weight 1_000_000
148
148
  setcode { value }
149
149
  end
@@ -110,7 +110,7 @@ module Facter
110
110
  #
111
111
  # @api private
112
112
  def options(options)
113
- accepted_options = %i[name value timeout weight fact_type file]
113
+ accepted_options = %i[name value timeout weight fact_type file is_env]
114
114
 
115
115
  accepted_options.each do |option_name|
116
116
  instance_variable_set("@#{option_name}", options.delete(option_name)) if options.key?(option_name)
@@ -4,6 +4,7 @@ module Facts
4
4
  module Aix
5
5
  class Interfaces
6
6
  FACT_NAME = 'interfaces'
7
+ TYPE = :legacy
7
8
 
8
9
  def call_the_resolver
9
10
  fact_value = Facter::Resolvers::Aix::Networking.resolve(:interfaces)
@@ -11,7 +11,7 @@ module Facts
11
11
  def call_the_resolver
12
12
  fact_value = Facter::Resolvers::Aix::Memory.resolve(:swap)
13
13
  if fact_value
14
- fact_value = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(fact_value[:available_bytes])
14
+ fact_value = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(fact_value[:available_bytes])
15
15
  end
16
16
  [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
17
17
  end
@@ -13,7 +13,7 @@ module Facts
13
13
  fact_value = fact_value[:available_bytes] if fact_value
14
14
 
15
15
  [Facter::ResolvedFact.new(FACT_NAME, fact_value),
16
- Facter::ResolvedFact.new(ALIASES, Facter::FactsUtils::UnitConverter.bytes_to_mb(fact_value), :legacy)]
16
+ Facter::ResolvedFact.new(ALIASES, Facter::Util::Facts::UnitConverter.bytes_to_mb(fact_value), :legacy)]
17
17
  end
18
18
  end
19
19
  end
@@ -11,7 +11,7 @@ module Facts
11
11
  def call_the_resolver
12
12
  fact_value = Facter::Resolvers::Aix::Memory.resolve(:swap)
13
13
  if fact_value
14
- fact_value = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(fact_value[:total_bytes])
14
+ fact_value = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(fact_value[:total_bytes])
15
15
  end
16
16
  [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
17
17
  end
@@ -13,7 +13,7 @@ module Facts
13
13
  fact_value = fact_value[:total_bytes] if fact_value
14
14
 
15
15
  [Facter::ResolvedFact.new(FACT_NAME, fact_value),
16
- Facter::ResolvedFact.new(ALIASES, Facter::FactsUtils::UnitConverter.bytes_to_mb(fact_value), :legacy)]
16
+ Facter::ResolvedFact.new(ALIASES, Facter::Util::Facts::UnitConverter.bytes_to_mb(fact_value), :legacy)]
17
17
  end
18
18
  end
19
19
  end
@@ -10,7 +10,7 @@ module Facts
10
10
  def call_the_resolver
11
11
  fact_value = Facter::Resolvers::Aix::Memory.resolve(:swap)
12
12
  if fact_value
13
- fact_value = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(fact_value[:used_bytes])
13
+ fact_value = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(fact_value[:used_bytes])
14
14
  end
15
15
  Facter::ResolvedFact.new(FACT_NAME, fact_value)
16
16
  end
@@ -11,7 +11,7 @@ module Facts
11
11
  def call_the_resolver
12
12
  fact_value = Facter::Resolvers::Aix::Memory.resolve(:system)
13
13
  if fact_value
14
- fact_value = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(fact_value[:available_bytes])
14
+ fact_value = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(fact_value[:available_bytes])
15
15
  end
16
16
  [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
17
17
  end
@@ -13,7 +13,7 @@ module Facts
13
13
  fact_value = fact_value[:available_bytes] if fact_value
14
14
 
15
15
  [Facter::ResolvedFact.new(FACT_NAME, fact_value),
16
- Facter::ResolvedFact.new(ALIASES, Facter::FactsUtils::UnitConverter.bytes_to_mb(fact_value), :legacy)]
16
+ Facter::ResolvedFact.new(ALIASES, Facter::Util::Facts::UnitConverter.bytes_to_mb(fact_value), :legacy)]
17
17
  end
18
18
  end
19
19
  end
@@ -11,7 +11,7 @@ module Facts
11
11
  def call_the_resolver
12
12
  fact_value = Facter::Resolvers::Aix::Memory.resolve(:system)
13
13
  if fact_value
14
- fact_value = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(fact_value[:total_bytes])
14
+ fact_value = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(fact_value[:total_bytes])
15
15
  end
16
16
  [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
17
17
  end
@@ -13,7 +13,7 @@ module Facts
13
13
  fact_value = fact_value[:total_bytes] if fact_value
14
14
 
15
15
  [Facter::ResolvedFact.new(FACT_NAME, fact_value),
16
- Facter::ResolvedFact.new(ALIASES, Facter::FactsUtils::UnitConverter.bytes_to_mb(fact_value), :legacy)]
16
+ Facter::ResolvedFact.new(ALIASES, Facter::Util::Facts::UnitConverter.bytes_to_mb(fact_value), :legacy)]
17
17
  end
18
18
  end
19
19
  end
@@ -10,7 +10,7 @@ module Facts
10
10
  def call_the_resolver
11
11
  fact_value = Facter::Resolvers::Aix::Memory.resolve(:system)
12
12
  if fact_value
13
- fact_value = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(fact_value[:used_bytes])
13
+ fact_value = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(fact_value[:used_bytes])
14
14
  end
15
15
  Facter::ResolvedFact.new(FACT_NAME, fact_value)
16
16
  end
@@ -8,7 +8,7 @@ module Facts
8
8
 
9
9
  def call_the_resolver
10
10
  fact_value = Facter::Resolvers::Aix::Processors.resolve(:speed)
11
- speed = Facter::FactsUtils::UnitConverter.hertz_to_human_readable(fact_value)
11
+ speed = Facter::Util::Facts::UnitConverter.hertz_to_human_readable(fact_value)
12
12
  Facter::ResolvedFact.new(FACT_NAME, speed)
13
13
  end
14
14
  end
@@ -8,7 +8,7 @@ module Facts
8
8
 
9
9
  def call_the_resolver
10
10
  fact_value = Facter::Resolvers::Bsd::Processors.resolve(:speed)
11
- speed = Facter::FactsUtils::UnitConverter.hertz_to_human_readable(fact_value)
11
+ speed = Facter::Util::Facts::UnitConverter.hertz_to_human_readable(fact_value)
12
12
  Facter::ResolvedFact.new(FACT_NAME, speed)
13
13
  end
14
14
  end