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
@@ -37,6 +37,7 @@ load_dir(['config'])
37
37
  load_dir(['util'])
38
38
  load_dir(%w[util resolvers])
39
39
  load_dir(%w[util facts])
40
+ load_dir(%w[util facts posix])
40
41
  load_dir(%w[util resolvers networking])
41
42
 
42
43
  load_dir(['resolvers'])
@@ -58,5 +59,4 @@ os_hierarchy.each { |operating_system| load_dir(['resolvers', operating_system.d
58
59
  require 'facter/custom_facts/core/legacy_facter'
59
60
  load_dir(%w[framework utils])
60
61
 
61
- require 'facter/framework/core/fact_augmenter'
62
62
  require 'facter/framework/parsers/query_parser'
@@ -41,10 +41,9 @@ module Facter
41
41
  store(ConfigFileOptions.get)
42
42
  end
43
43
 
44
- def init_from_cli(cli_options = {}, user_query = nil)
44
+ def init_from_cli(cli_options = {})
45
45
  Facter::OptionStore.cli = true
46
46
  Facter::OptionStore.show_legacy = false
47
- Facter::OptionStore.user_query = user_query
48
47
  Facter::OptionStore.trace = cli_options[:trace]
49
48
  OptionStore.set(:config, cli_options[:config])
50
49
  ConfigFileOptions.init(cli_options[:config])
@@ -18,6 +18,12 @@ module Facter
18
18
 
19
19
  private
20
20
 
21
+ def augment_structured_facts(global_conf)
22
+ return if !global_conf || global_conf['force-dot-resolution'].nil?
23
+
24
+ @options[:force_dot_resolution] = global_conf['force-dot-resolution']
25
+ end
26
+
21
27
  def augment_all
22
28
  augment_cli(Facter::ConfigReader.cli) if Options.cli?
23
29
  augment_globals
@@ -27,6 +33,7 @@ module Facter
27
33
  def augment_globals
28
34
  augment_ruby(Facter::ConfigReader.global)
29
35
 
36
+ augment_structured_facts(Facter::ConfigReader.global)
30
37
  augment_custom(Facter::ConfigReader.global)
31
38
  augment_external(Facter::ConfigReader.global)
32
39
  augment_show_legacy(Facter::ConfigReader.global)
@@ -13,7 +13,6 @@ module Facter
13
13
  @ruby = true
14
14
  @external_facts = true
15
15
  @config = nil
16
- @user_query = []
17
16
  @strict = false
18
17
  @json = false
19
18
  @cache = true
@@ -35,15 +34,17 @@ module Facter
35
34
  @external_dir = []
36
35
  @custom_dir = []
37
36
  @hocon = false
37
+ @allow_external_loggers = true
38
+ @force_dot_resolution = false
38
39
 
39
40
  class << self
40
41
  attr_reader :debug, :verbose, :log_level, :show_legacy,
41
42
  :custom_facts, :blocked_facts, :ruby, :external_facts
42
43
 
43
- attr_accessor :config, :user_query, :strict, :json,
44
+ attr_accessor :config, :strict, :json,
44
45
  :cache, :yaml, :puppet, :ttls, :block, :cli, :config_file_custom_dir,
45
- :config_file_external_dir, :default_external_dir, :fact_groups,
46
- :block_list, :color, :trace, :sequential, :timing, :hocon
46
+ :config_file_external_dir, :default_external_dir, :fact_groups, :force_dot_resolution,
47
+ :block_list, :color, :trace, :sequential, :timing, :hocon, :allow_external_loggers
47
48
 
48
49
  attr_writer :external_dir
49
50
 
@@ -170,7 +171,6 @@ module Facter
170
171
  @log_level = :warn
171
172
  @show_legacy = true
172
173
  @ruby = true
173
- @user_query = []
174
174
  @json = false
175
175
  @hocon = false
176
176
  @cache = true
@@ -179,7 +179,6 @@ module Facter
179
179
  @ttls = []
180
180
  @block = true
181
181
  @cli = nil
182
- @custom_facts = true
183
182
  reset_config
184
183
  end
185
184
 
@@ -198,6 +197,13 @@ module Facter
198
197
  @ttls = []
199
198
  @trace = false
200
199
  @timing = false
200
+ @allow_external_loggers = true
201
+ reset_facts
202
+ end
203
+
204
+ def reset_facts
205
+ @custom_facts = true
206
+ @force_dot_resolution = false
201
207
  @external_dir = []
202
208
  @custom_dir = []
203
209
  end
@@ -4,12 +4,11 @@ module Facter
4
4
  class FormatterHelper
5
5
  class << self
6
6
  def retrieve_facts_to_display_for_user_query(user_queries, resolved_facts)
7
- facts_to_display = {}
7
+ facts_to_display = FactCollection.new
8
8
  user_queries.each do |user_query|
9
9
  fact_collection = build_fact_collection_for_user_query(user_query, resolved_facts)
10
10
 
11
- splitted_user_query = Utils.split_user_query(user_query)
12
- printable_value = fact_collection.dig(*splitted_user_query)
11
+ printable_value = fact_collection.dig_fact(user_query)
13
12
  facts_to_display.merge!(user_query => printable_value)
14
13
  end
15
14
 
@@ -24,8 +23,7 @@ module Facter
24
23
  def retrieve_fact_value_for_single_query(user_query, resolved_facts)
25
24
  fact_collection = build_fact_collection_for_user_query(user_query, resolved_facts)
26
25
  fact_collection = Utils.sort_hash_by_key(fact_collection)
27
- splitted_user_query = Utils.split_user_query(user_query)
28
- fact_collection.dig(*splitted_user_query)
26
+ fact_collection.dig_fact(user_query)
29
27
  end
30
28
 
31
29
  private
@@ -60,7 +60,7 @@ module Facter
60
60
  def debug(msg)
61
61
  return unless debugging_active?
62
62
 
63
- if @@message_callback
63
+ if @@message_callback && Options[:allow_external_loggers]
64
64
  @@message_callback.call(:debug, msg)
65
65
  else
66
66
  msg = colorize(msg, CYAN) if Options[:color]
@@ -71,7 +71,7 @@ module Facter
71
71
  def info(msg)
72
72
  if msg.nil? || msg.empty?
73
73
  empty_message_error(msg)
74
- elsif @@message_callback
74
+ elsif @@message_callback && Options[:allow_external_loggers]
75
75
  @@message_callback.call(:info, msg)
76
76
  else
77
77
  msg = colorize(msg, GREEN) if Options[:color]
@@ -80,7 +80,7 @@ module Facter
80
80
  end
81
81
 
82
82
  def warn(msg)
83
- if @@message_callback
83
+ if @@message_callback && Options[:allow_external_loggers]
84
84
  @@message_callback.call(:warn, msg)
85
85
  else
86
86
  msg = colorize(msg, YELLOW) if Options[:color]
@@ -91,7 +91,7 @@ module Facter
91
91
  def error(msg, colorize = false)
92
92
  @@has_errors = true
93
93
 
94
- if @@message_callback
94
+ if @@message_callback && Options[:allow_external_loggers]
95
95
  @@message_callback.call(:error, msg)
96
96
  else
97
97
  msg = colorize(msg, RED) if colorize || Options[:color]
@@ -41,7 +41,7 @@ module Facter
41
41
  def no_user_query(loaded_facts)
42
42
  searched_facts = []
43
43
  loaded_facts.each do |loaded_fact|
44
- searched_facts << SearchedFact.new(loaded_fact.name, loaded_fact.klass, [], '', loaded_fact.type)
44
+ searched_facts << SearchedFact.new(loaded_fact.name, loaded_fact.klass, '', loaded_fact.type)
45
45
  end
46
46
  searched_facts
47
47
  end
@@ -59,7 +59,7 @@ module Facter
59
59
  return resolvable_fact_list if resolvable_fact_list.any?
60
60
  end
61
61
 
62
- resolvable_fact_list << SearchedFact.new(query, nil, [], query, :nil) if resolvable_fact_list.empty?
62
+ resolvable_fact_list << SearchedFact.new(query, nil, query, :nil) if resolvable_fact_list.empty?
63
63
 
64
64
  resolvable_fact_list
65
65
  end
@@ -73,7 +73,7 @@ module Facter
73
73
 
74
74
  next unless found_fact?(loaded_fact.name, query_fact)
75
75
 
76
- searched_fact = construct_loaded_fact(query_tokens, query_token_range, loaded_fact)
76
+ searched_fact = construct_loaded_fact(query_tokens, loaded_fact)
77
77
  resolvable_fact_list << searched_fact
78
78
  end
79
79
 
@@ -93,23 +93,16 @@ module Facter
93
93
  true
94
94
  end
95
95
 
96
- def construct_loaded_fact(query_tokens, query_token_range, loaded_fact)
97
- filter_tokens = construct_filter_tokens(query_tokens, query_token_range)
96
+ def construct_loaded_fact(query_tokens, loaded_fact)
98
97
  user_query = @query_list.any? ? query_tokens.join('.') : ''
99
98
  fact_name = loaded_fact.name.to_s
100
99
  klass_name = loaded_fact.klass
101
100
  type = loaded_fact.type
102
- sf = SearchedFact.new(fact_name, klass_name, filter_tokens, user_query, type)
101
+ sf = SearchedFact.new(fact_name, klass_name, user_query, type)
103
102
  sf.file = loaded_fact.file
104
103
 
105
104
  sf
106
105
  end
107
-
108
- def construct_filter_tokens(query_tokens, query_token_range)
109
- (query_tokens - query_tokens[query_token_range]).map do |token|
110
- token =~ /^[0-9]+$/ ? token.to_i : token
111
- end
112
- end
113
106
  end
114
107
  end
115
108
  end
@@ -7,6 +7,16 @@ module Facter
7
7
  @log = Log.new(self)
8
8
  end
9
9
 
10
+ def to_yaml
11
+ deep_to_h.to_yaml
12
+ end
13
+
14
+ # Transorms a list of {Facter::ResolvedFact} into a nested collection.
15
+ # @param facts [Array<Facter::ResolvedFact>]
16
+ #
17
+ # @return [FactCollection]
18
+ #
19
+ # @api private
10
20
  def build_fact_collection!(facts)
11
21
  facts.each do |fact|
12
22
  next if %i[core legacy].include?(fact.type) && fact.value.nil?
@@ -17,9 +27,29 @@ module Facter
17
27
  self
18
28
  end
19
29
 
20
- def value(*keys)
21
- keys.reduce(self) do |memo, key|
22
- memo.fetch(key.to_s)
30
+ def dig_fact(user_query)
31
+ value(user_query)
32
+ rescue KeyError, TypeError
33
+ nil
34
+ end
35
+
36
+ # Collection#fetch implementation for nested collections.
37
+ # @param user_query [String] the search terms, separated by "."
38
+ #
39
+ # @return [String]
40
+ #
41
+ # @example for fact_collection = { "os": { "name": "Darwin" } }
42
+ # fact_collection.fetch("os.name") #=> "Darwin"
43
+ #
44
+ # @api private
45
+ def value(user_query)
46
+ fetch(user_query) do
47
+ split_user_query = Facter::Utils.split_user_query(user_query)
48
+ split_user_query.reduce(self) do |memo, key|
49
+ raise KeyError unless memo.respond_to?(:fetch)
50
+
51
+ memo.fetch(key) { memo.fetch(key.to_s) }
52
+ end
23
53
  end
24
54
  end
25
55
 
@@ -39,9 +69,15 @@ module Facter
39
69
 
40
70
  private
41
71
 
72
+ def deep_to_h(collection = self)
73
+ collection.each_pair.with_object({}) do |(key, value), hash|
74
+ hash[key] = value.is_a?(FactCollection) ? deep_to_h(value) : value
75
+ end
76
+ end
77
+
42
78
  def bury_fact(fact)
43
79
  split_fact_name = extract_fact_name(fact)
44
- bury(*split_fact_name + fact.filter_tokens << fact.value)
80
+ bury(*split_fact_name << fact.value)
45
81
  rescue NoMethodError
46
82
  @log.error("#{fact.type.to_s.capitalize} fact `#{fact.name}` cannot be added to collection."\
47
83
  ' The format of this fact is incompatible with other'\
@@ -49,7 +85,14 @@ module Facter
49
85
  end
50
86
 
51
87
  def extract_fact_name(fact)
52
- fact.type == :legacy ? [fact.name] : fact.name.split('.')
88
+ case fact.type
89
+ when :legacy
90
+ [fact.name]
91
+ when :custom, :external
92
+ Options[:force_dot_resolution] == true ? fact.name.split('.') : [fact.name]
93
+ else
94
+ fact.name.split('.')
95
+ end
53
96
  end
54
97
  end
55
98
  end
@@ -3,14 +3,13 @@
3
3
  module Facter
4
4
  class ResolvedFact
5
5
  attr_reader :name, :type
6
- attr_accessor :user_query, :filter_tokens, :value, :file
6
+ attr_accessor :user_query, :value, :file
7
7
 
8
- def initialize(name, value = '', type = :core, user_query = nil, filter_tokens = [])
8
+ def initialize(name, value = '', type = :core, user_query = nil)
9
9
  @name = name
10
10
  @value = Utils.deep_stringify_keys(value)
11
11
  @type = type
12
12
  @user_query = user_query
13
- @filter_tokens = filter_tokens
14
13
  end
15
14
 
16
15
  def legacy?
@@ -2,13 +2,12 @@
2
2
 
3
3
  module Facter
4
4
  class SearchedFact
5
- attr_reader :name, :fact_class, :filter_tokens, :user_query, :type
5
+ attr_reader :name, :fact_class, :user_query, :type
6
6
  attr_accessor :file
7
7
 
8
- def initialize(fact_name, fact_class, filter_tokens, user_query, type)
8
+ def initialize(fact_name, fact_class, user_query, type)
9
9
  @name = fact_name
10
10
  @fact_class = fact_class
11
- @filter_tokens = filter_tokens
12
11
  @user_query = user_query
13
12
  @type = type
14
13
  end
@@ -33,7 +33,7 @@ module Facter
33
33
 
34
34
  return if Libc.getkerninfo(KINFO_READ | KINFO_GET_AVENRUN, averages, averages_size, 0).negative?
35
35
 
36
- averages.read_array_of_long_long(3).map { |x| (x / 65_536.0).round(5) }
36
+ averages.read_array_of_long_long(3).map { |x| (x / 65_536.0) }
37
37
  end
38
38
 
39
39
  def self.read_interfaces
@@ -16,6 +16,8 @@ module Facter
16
16
  def query_pddv(fact_name)
17
17
  @fact_list[:models] = []
18
18
  @fact_list[:logical_count] = 0
19
+ @fact_list[:cores_per_socket] = 0
20
+ @fact_list[:threads_per_core] = 0
19
21
 
20
22
  odmquery = Facter::Util::Aix::ODMQuery.new
21
23
  odmquery.equals('class', 'processor')
@@ -59,6 +61,8 @@ module Facter
59
61
  threads = smt_enabled ? smt_threads : 1
60
62
 
61
63
  @fact_list[:logical_count] += threads
64
+ @fact_list[:cores_per_socket] += 1
65
+ @fact_list[:threads_per_core] = threads
62
66
  @fact_list[:models].concat([type] * threads)
63
67
  end
64
68
 
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Resolvers
5
+ class Az < BaseResolver
6
+ init_resolver
7
+
8
+ AZ_METADATA_URL = 'http://169.254.169.254/metadata/instance?api-version=2020-09-01'
9
+ AZ_SESSION_TIMEOUT = 5
10
+
11
+ class << self
12
+ private
13
+
14
+ def post_resolve(fact_name, _options)
15
+ log.debug('Querying Az metadata')
16
+ @fact_list.fetch(fact_name) { read_facts(fact_name) }
17
+ end
18
+
19
+ def read_facts(fact_name)
20
+ @fact_list[:metadata] = {}
21
+ data = get_data_from(AZ_METADATA_URL)
22
+ @fact_list[:metadata] = JSON.parse(data) unless data.empty?
23
+
24
+ @fact_list[fact_name]
25
+ end
26
+
27
+ def get_data_from(url)
28
+ headers = { Metadata: 'true' }
29
+ Facter::Util::Resolvers::Http.get_request(url, headers, { session: determine_session_timeout })
30
+ end
31
+
32
+ def determine_session_timeout
33
+ session_env = ENV['AZ_SESSION_TIMEOUT']
34
+ session_env ? session_env.to_i : AZ_SESSION_TIMEOUT
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -28,10 +28,10 @@ module Facter
28
28
  cache_nil_for_unresolved_facts(fact_name)
29
29
  end
30
30
  rescue NoMethodError => e
31
- log.debug("Could not resolve #{fact_name}, got #{e}")
31
+ log.debug("Could not resolve #{fact_name}, got #{e} at #{e.backtrace[0]}")
32
32
  @fact_list[fact_name] = nil
33
33
  rescue LoadError, NameError => e
34
- log.debug("resolving fact #{fact_name}, but #{e}")
34
+ log.debug("Resolving fact #{fact_name}, but got #{e} at #{e.backtrace[0]}")
35
35
  @fact_list[fact_name] = nil
36
36
  end
37
37
 
@@ -37,7 +37,6 @@ module Facter
37
37
  @fact_list[:virtualbox_version] = output.match(/vboxVer_(\S+)/)&.captures&.first
38
38
  @fact_list[:virtualbox_revision] = output.match(/vboxRev_(\S+)/)&.captures&.first
39
39
  @fact_list[:vmware_version] = extract_vmware_version(output)
40
- @fact_list[:vendor] = output.match(/Vendor: (\S+)/)&.captures&.first
41
40
 
42
41
  @fact_list[fact_name]
43
42
  end
@@ -0,0 +1,126 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Resolvers
5
+ module Linux
6
+ class Hostname < BaseResolver
7
+ # :fqdn
8
+ # :domain
9
+ # :hostname
10
+
11
+ init_resolver
12
+
13
+ class << self
14
+ private
15
+
16
+ def post_resolve(fact_name, _options)
17
+ @fact_list.fetch(fact_name) { retrieve_info(fact_name) }
18
+ end
19
+
20
+ def retrieve_info(fact_name)
21
+ require 'socket'
22
+
23
+ output = retrieving_hostname
24
+ return nil unless output
25
+
26
+ # Check if the gethostname method retrieved fqdn
27
+ hostname, domain = parse_fqdn(output)
28
+
29
+ fqdn = retrieve_fqdn_for_host(hostname) if hostname_and_no_domain?(hostname, domain)
30
+
31
+ _, domain = parse_fqdn(fqdn) if exists_and_valid_fqdn?(fqdn, hostname)
32
+
33
+ domain = read_domain unless exists_and_not_empty?(domain)
34
+
35
+ construct_fact_list(hostname, domain, fqdn)
36
+ @fact_list[fact_name]
37
+ end
38
+
39
+ def retrieving_hostname
40
+ output = Socket.gethostname || ''
41
+ if output.empty? || output['0.0.0.0']
42
+ begin
43
+ require 'facter/util/resolvers/ffi/hostname'
44
+
45
+ output = Facter::Util::Resolvers::Ffi::Hostname.getffihostname
46
+ rescue LoadError => e
47
+ log.debug(e.message)
48
+ output = nil
49
+ end
50
+ end
51
+
52
+ log.debug("Tried to retrieve hostname and got: #{output}")
53
+ return output unless output&.empty?
54
+ end
55
+
56
+ def parse_fqdn(output)
57
+ if output =~ /(.*?)\.(.+$)/
58
+ log.debug("Managed to read hostname: #{Regexp.last_match(1)} and domain: #{Regexp.last_match(2)}")
59
+ [Regexp.last_match(1), Regexp.last_match(2)]
60
+ else
61
+ log.debug("Only managed to read hostname: #{output}, no domain was found.")
62
+ [output, '']
63
+ end
64
+ end
65
+
66
+ def retrieve_fqdn_for_host(host)
67
+ begin
68
+ name = Socket.getaddrinfo(host, 0, Socket::AF_UNSPEC, Socket::SOCK_STREAM, nil, Socket::AI_CANONNAME)[0]
69
+ rescue StandardError => e
70
+ log.debug("Socket.getaddrinfo failed to retrieve fqdn for hostname #{host} with: #{e}")
71
+ end
72
+
73
+ return name[2] if !name.nil? && !name.empty? && host != name[2] && name[2] != name[3]
74
+
75
+ retrieve_fqdn_for_host_with_ffi(host)
76
+ end
77
+
78
+ def retrieve_fqdn_for_host_with_ffi(host)
79
+ require 'facter/util/resolvers/ffi/hostname'
80
+
81
+ fqdn = Facter::Util::Resolvers::Ffi::Hostname.getffiaddrinfo(host)
82
+ log.debug("FFI getaddrinfo was called and it retrieved: #{fqdn}")
83
+ fqdn
84
+ rescue LoadError => e
85
+ log.debug(e.message)
86
+ nil
87
+ end
88
+
89
+ def exists_and_valid_fqdn?(fqdn, hostname)
90
+ exists_and_not_empty?(fqdn) && fqdn.start_with?("#{hostname}.")
91
+ end
92
+
93
+ def hostname_and_no_domain?(hostname, domain)
94
+ domain.empty? && !hostname.empty?
95
+ end
96
+
97
+ def read_domain
98
+ file_content = Facter::Util::FileHelper.safe_read('/etc/resolv.conf')
99
+ if file_content =~ /^domain\s+(\S+)/
100
+ Regexp.last_match(1)
101
+ elsif file_content =~ /^search\s+(\S+)/
102
+ Regexp.last_match(1)
103
+ end
104
+ end
105
+
106
+ def construct_fqdn(host, domain, fqdn)
107
+ return fqdn if exists_and_not_empty?(fqdn)
108
+ return if host.nil? || host.empty?
109
+
110
+ exists_and_not_empty?(domain) ? "#{host}.#{domain}" : host
111
+ end
112
+
113
+ def construct_fact_list(hostname, domain, fqdn)
114
+ @fact_list[:hostname] = hostname
115
+ @fact_list[:domain] = domain
116
+ @fact_list[:fqdn] = construct_fqdn(@fact_list[:hostname], @fact_list[:domain], fqdn)
117
+ end
118
+
119
+ def exists_and_not_empty?(variable)
120
+ variable && !variable.empty?
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end