facter 4.0.38 → 4.0.43

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/bin/facter +3 -4
  3. data/lib/facter.rb +138 -27
  4. data/lib/facter/custom_facts/core/aggregate.rb +51 -17
  5. data/lib/facter/custom_facts/core/execution.rb +27 -35
  6. data/lib/facter/custom_facts/core/execution/base.rb +42 -6
  7. data/lib/facter/custom_facts/util/directory_loader.rb +1 -1
  8. data/lib/facter/custom_facts/util/resolution.rb +40 -11
  9. data/lib/facter/facts/aix/disks.rb +1 -1
  10. data/lib/facter/facts/aix/kernel.rb +1 -1
  11. data/lib/facter/facts/aix/kernelmajversion.rb +1 -1
  12. data/lib/facter/facts/aix/kernelrelease.rb +1 -1
  13. data/lib/facter/facts/aix/kernelversion.rb +1 -1
  14. data/lib/facter/facts/aix/os/release.rb +1 -1
  15. data/lib/facter/facts/linux/cloud.rb +15 -0
  16. data/lib/facter/facts/linux/disks.rb +1 -1
  17. data/lib/facter/facts/linux/ec2_metadata.rb +5 -27
  18. data/lib/facter/facts/linux/ec2_userdata.rb +5 -27
  19. data/lib/facter/facts/linux/is_virtual.rb +7 -46
  20. data/lib/facter/facts/linux/virtual.rb +3 -58
  21. data/lib/facter/facts/solaris/disks.rb +1 -1
  22. data/lib/facter/facts/solaris/zones.rb +1 -1
  23. data/lib/facter/facts_utils/virtual_detector.rb +78 -0
  24. data/lib/facter/framework/cli/cli.rb +83 -36
  25. data/lib/facter/framework/cli/cli_launcher.rb +34 -38
  26. data/lib/facter/framework/config/fact_groups.rb +36 -2
  27. data/lib/facter/framework/core/cache_manager.rb +40 -23
  28. data/lib/facter/framework/core/fact_loaders/fact_loader.rb +14 -11
  29. data/lib/facter/framework/core/options/config_file_options.rb +5 -3
  30. data/lib/facter/framework/core/options/option_store.rb +27 -10
  31. data/lib/facter/framework/logging/logger.rb +1 -5
  32. data/lib/facter/patches/sysfilesystem/sys/statvfs.rb +92 -0
  33. data/lib/facter/resolvers/aix/os_level.rb +27 -0
  34. data/lib/facter/resolvers/cloud.rb +39 -0
  35. data/lib/facter/resolvers/dmi_decode.rb +1 -0
  36. data/lib/facter/resolvers/dmi_resolver.rb +2 -2
  37. data/lib/facter/resolvers/memory_resolver.rb +12 -14
  38. data/lib/facter/resolvers/mountpoints_resolver.rb +5 -2
  39. data/lib/facter/resolvers/networking_linux_resolver.rb +10 -5
  40. data/lib/facter/resolvers/processors_resolver.rb +5 -1
  41. data/lib/facter/resolvers/solaris/mountpoints.rb +60 -0
  42. data/lib/facter/resolvers/solaris/networking.rb +1 -1
  43. data/lib/facter/resolvers/utils/filesystem_helper.rb +3 -1
  44. data/lib/facter/version.rb +1 -1
  45. metadata +8 -4
  46. data/lib/facter/resolvers/aix/os_level_resolver.rb +0 -25
  47. data/lib/facter/resolvers/os_level_resolver.rb +0 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4cded925592073cd18baac69fc11f1154cbeda4370359e9d3e6655f97194d467
4
- data.tar.gz: 16ea8f7a28b6ae86b0098a8c9412329dfa2665e1ca1a66ca3cc2d7e734452fa7
3
+ metadata.gz: 02e89a2638e45004e55f6b0ec4d902946c844b5253ee4e27139ab01d1ee12a92
4
+ data.tar.gz: bd4405449c4804a3c872510042a33c2cd6cf7fd588df8f95a99893fcb9248291
5
5
  SHA512:
6
- metadata.gz: be78011c78dab1cdc01e44af6a2e2e053f3600c43a4c758e1edbf2b6a067052de36a8166749148fc2740694394af682c38cd7f72d516f75a323af9c69a278667
7
- data.tar.gz: 3b614e324b33c54c571e5857ea184dcf89d0e7e1fdc9030ee57478bdc3eaa6c0511d73f8f18441e33d31258ea5be7f227b3412770a90f82ed8fe789f9f3690f8
6
+ metadata.gz: 31feabfeb9c2008ae30f16b6469cdf689b78e8711d64e3b614481a3e98b41d8271822b6cb26511a56ba5e19394f2ea811552b29168484d8ee377dbd3697f6655
7
+ data.tar.gz: f579f81b0dc6fedf937d016e531650c183bc4f89ce66c918f47932af01e97bfc19f0e0f012adcfe36a52e4a9a314685765055fe23bde5aa4cf5b2f92353a450c
data/bin/facter CHANGED
@@ -4,8 +4,7 @@
4
4
  require 'pathname'
5
5
  require 'facter/framework/cli/cli_launcher.rb'
6
6
 
7
- cli_launcher = CliLauncher.new(ARGV)
7
+ Facter::OptionsValidator.validate(ARGV)
8
+ processed_arguments = CliLauncher.prepare_arguments(ARGV)
8
9
 
9
- cli_launcher.validate_options
10
- cli_launcher.prepare_arguments
11
- cli_launcher.start
10
+ CliLauncher.start(processed_arguments)
@@ -17,8 +17,32 @@ module Facter
17
17
  @warn_once = []
18
18
 
19
19
  class << self
20
- def clear_messages
21
- logger.debug('clear_messages is not implemented')
20
+ # Method used by puppet-agent to retrieve facts
21
+ # @param args_as_string [string] facter cli arguments
22
+ #
23
+ # @return nil
24
+ #
25
+ # @api private
26
+ def resolve(args_as_string)
27
+ require 'facter/framework/cli/cli_launcher'
28
+
29
+ args = args_as_string.split(' ')
30
+
31
+ Facter::OptionsValidator.validate(args)
32
+ processed_arguments = CliLauncher.prepare_arguments(args, nil)
33
+
34
+ cli = Facter::Cli.new([], processed_arguments)
35
+
36
+ if cli.args.include?(:version)
37
+ cli.invoke(:version, [])
38
+ elsif cli.args.include?('--list-cache-groups')
39
+ cli.invoke(:list_cache_groups, [])
40
+ elsif cli.args.include?('--list-block-groups')
41
+ cli.invoke(:list_block_groups, [])
42
+ else
43
+ cli.invoke(:arg_parser)
44
+ end
45
+ nil
22
46
  end
23
47
 
24
48
  # Alias method for Facter.fact()
@@ -62,8 +86,16 @@ module Facter
62
86
  Options[:custom_dir] = []
63
87
  LegacyFacter.collection.invalidate_custom_facts
64
88
  LegacyFacter.collection.reload_custom_facts
89
+ SessionCache.invalidate_all_caches
90
+ nil
65
91
  end
66
92
 
93
+ # Gets the value for a core fact, external or custom facts are
94
+ # not returned with this call. Returns `nil` if no such fact exists.
95
+ #
96
+ # @return [FactCollection] hash with fact names and values
97
+ #
98
+ # @api private
67
99
  def core_value(user_query)
68
100
  user_query = user_query.to_s
69
101
  resolved_facts = Facter::FactManager.instance.resolve_core([user_query])
@@ -102,8 +134,29 @@ module Facter
102
134
  nil
103
135
  end
104
136
 
137
+ # Define a new fact or extend an existing fact.
138
+ #
139
+ # @param name [Symbol] The name of the fact to define
140
+ # @param options [Hash] A hash of options to set on the fact
141
+ #
142
+ # @return [Facter::Util::Fact] The fact that was defined
143
+ #
144
+ # @api public
145
+ def define_fact(name, options = {}, &block)
146
+ options[:fact_type] = :custom
147
+ LegacyFacter.define_fact(name, options, &block)
148
+ end
149
+
150
+ # Stores a proc that will be used to output custom messages.
151
+ # The proc must receive one parameter that will be the message to log.
152
+ # @param block [Proc] a block defining messages handler
153
+ #
154
+ # @return [nil]
155
+ #
156
+ # @api public
105
157
  def on_message(&block)
106
158
  Facter::Log.on_message(&block)
159
+ nil
107
160
  end
108
161
 
109
162
  # Check whether debugging is enabled
@@ -125,6 +178,25 @@ module Facter
125
178
  Facter::Options[:debug] = debug_bool
126
179
  end
127
180
 
181
+ # Iterates over fact names and values
182
+ #
183
+ # @yieldparam [String] name the fact name
184
+ # @yieldparam [String] value the current value of the fact
185
+ #
186
+ # @return [Facter]
187
+ #
188
+ # @api public
189
+ def each
190
+ log_blocked_facts
191
+ resolved_facts = Facter::FactManager.instance.resolve_facts
192
+
193
+ resolved_facts.each do |fact|
194
+ yield(fact.name, fact.value)
195
+ end
196
+
197
+ self
198
+ end
199
+
128
200
  # Returns a fact object by name. If you use this, you still have to
129
201
  # call {Facter::Util::Fact#value `value`} on it to retrieve the actual
130
202
  # value.
@@ -152,30 +224,41 @@ module Facter
152
224
  LegacyFacter.reset
153
225
  Options[:custom_dir] = []
154
226
  Options[:external_dir] = []
227
+ SessionCache.invalidate_all_caches
155
228
  nil
156
229
  end
157
230
 
158
- # Register directories to be searched for custom facts. The registered directories
159
- # must be absolute paths or they will be ignored.
231
+ # Loads all facts
160
232
  #
233
+ # @return [nil]
234
+ #
235
+ # @api public
236
+ def loadfacts
237
+ LegacyFacter.loadfacts
238
+ nil
239
+ end
240
+
241
+ # Register directories to be searched for custom facts. The registered directories
242
+ # must be absolute paths or they will be ignored.
161
243
  # @param dirs [Array<String>] An array of searched directories
162
244
  #
163
- # @return [void]
245
+ # @return [nil]
164
246
  #
165
247
  # @api public
166
248
  def search(*dirs)
167
249
  Options[:custom_dir] += dirs
250
+ nil
168
251
  end
169
252
 
170
253
  # Registers directories to be searched for external facts.
171
- #
172
254
  # @param dirs [Array<String>] An array of searched directories
173
255
  #
174
- # @return [void]
256
+ # @return [nil]
175
257
  #
176
258
  # @api public
177
259
  def search_external(dirs)
178
260
  Options[:external_dir] += dirs
261
+ nil
179
262
  end
180
263
 
181
264
  # Returns the registered search directories.for external facts.
@@ -199,14 +282,13 @@ module Facter
199
282
  # Gets a hash mapping fact names to their values
200
283
  # The hash contains core facts, legacy facts, custom facts and external facts (all facts that can be resolved).
201
284
  #
202
- # @return [FactCollection] the hash of fact names and values
285
+ # @return [FactCollection] hash with fact names and values
203
286
  #
204
287
  # @api public
205
288
  def to_hash
206
289
  log_blocked_facts
207
290
 
208
291
  resolved_facts = Facter::FactManager.instance.resolve_facts
209
- Facter::SessionCache.invalidate_all_caches
210
292
  Facter::FactCollection.new.build_fact_collection!(resolved_facts)
211
293
  end
212
294
 
@@ -222,7 +304,7 @@ module Facter
222
304
  # Enable or disable trace
223
305
  # @param bool [bool] Set trace on debug state
224
306
  #
225
- # @return [type] [description]
307
+ # @return [bool] Value of trace debug state
226
308
  #
227
309
  # @api public
228
310
  def trace(bool)
@@ -241,6 +323,27 @@ module Facter
241
323
  @already_searched[user_query]&.value
242
324
  end
243
325
 
326
+ # Gets the values for multiple facts.
327
+ #
328
+ # @param options [Hash] parameters for the fact - attributes
329
+ # of {Facter::Util::Fact} and {Facter::Util::Resolution} can be
330
+ # supplied here
331
+ # @param user_queries [String] the fact names
332
+ #
333
+ # @return [FactCollection] hash with fact names and values
334
+ #
335
+ # @api public
336
+ def values(options, user_queries)
337
+ init_cli_options(options, user_queries)
338
+ resolved_facts = Facter::FactManager.instance.resolve_facts(user_queries)
339
+
340
+ if user_queries.count.zero?
341
+ Facter::FactCollection.new.build_fact_collection!(resolved_facts)
342
+ else
343
+ FormatterHelper.retrieve_facts_to_display_for_user_query(user_queries, resolved_facts)
344
+ end
345
+ end
346
+
244
347
  # Returns Facter version
245
348
  #
246
349
  # @return [String] Current version
@@ -260,7 +363,6 @@ module Facter
260
363
  logger.info("executed with command line: #{ARGV.drop(1).join(' ')}")
261
364
  log_blocked_facts
262
365
  resolved_facts = Facter::FactManager.instance.resolve_facts(args)
263
- SessionCache.invalidate_all_caches
264
366
  fact_formatter = Facter::FormatterFactory.build(Facter::Options.get)
265
367
 
266
368
  status = error_check(resolved_facts)
@@ -268,23 +370,22 @@ module Facter
268
370
  [fact_formatter.format(resolved_facts), status || 0]
269
371
  end
270
372
 
271
- def log_exception(exception, message = :default)
272
- arr = []
273
- if message == :default
274
- arr << exception.message
275
- elsif message
276
- arr << message
277
- end
278
- if Options[:trace]
279
- arr << 'backtrace:'
280
- arr.concat(exception.backtrace)
281
- end
373
+ # Logs an exception and an optional message
374
+ #
375
+ # @return [nil]
376
+ #
377
+ # @api public
378
+ def log_exception(exception, message = nil)
379
+ error_message = []
282
380
 
283
- logger.error(arr.flatten.join("\n"))
381
+ error_message << message.to_s unless message.nil? || (message.is_a?(String) && message.empty?)
382
+
383
+ parse_exception(exception, error_message)
384
+ logger.error(error_message.flatten.join("\n"))
385
+ nil
284
386
  end
285
387
 
286
388
  # Returns a list with the names of all solved facts
287
- #
288
389
  # @return [Array] the list with all the fact names
289
390
  #
290
391
  # @api public
@@ -293,7 +394,6 @@ module Facter
293
394
  end
294
395
 
295
396
  # Logs the message parameter as a warning.
296
- #
297
397
  # @param message [Object] the warning object to be displayed
298
398
  #
299
399
  # @return [nil]
@@ -305,7 +405,6 @@ module Facter
305
405
  end
306
406
 
307
407
  # Logs only once the same warning message.
308
- #
309
408
  # @param message [Object] the warning message object
310
409
  #
311
410
  # @return [nil]
@@ -322,6 +421,19 @@ module Facter
322
421
 
323
422
  private
324
423
 
424
+ def parse_exception(exception, error_message)
425
+ if exception.is_a?(Exception)
426
+ error_message << exception.message if error_message.empty?
427
+
428
+ if Options[:trace] && !exception.backtrace.nil?
429
+ error_message << 'backtrace:'
430
+ error_message.concat(exception.backtrace)
431
+ end
432
+ elsif error_message.empty?
433
+ error_message << exception.to_s
434
+ end
435
+ end
436
+
325
437
  def logger
326
438
  @logger ||= Log.new(self)
327
439
  end
@@ -343,7 +455,6 @@ module Facter
343
455
  def resolve_fact(user_query)
344
456
  user_query = user_query.to_s
345
457
  resolved_facts = Facter::FactManager.instance.resolve_facts([user_query])
346
- SessionCache.invalidate_all_caches
347
458
  # we must make a distinction between custom facts that return nil and nil facts
348
459
  # Nil facts should not be packaged as ResolvedFacts! (add_fact_to_searched_facts packages facts)
349
460
  resolved_facts = resolved_facts.reject { |fact| fact.type == :nil }
@@ -18,22 +18,31 @@ module Facter
18
18
  include LegacyFacter::Core::Resolvable
19
19
 
20
20
  # @!attribute [r] name
21
- # @return [Symbol] The name of the aggregate resolution
21
+ #
22
+ # @return [Symbol] The name of the aggregate resolution
23
+ #
24
+ # @api public
22
25
  attr_reader :name
23
26
 
24
27
  # @!attribute [r] deps
25
- # @api private
26
- # @return [LegacyFacter::Core::DirectedGraph]
28
+ #
29
+ # @return [LegacyFacter::Core::DirectedGraph]
30
+ #
31
+ # @api private
27
32
  attr_reader :deps
28
33
 
29
34
  # @!attribute [r] confines
30
- # @return [Array<LegacyFacter::Core::Confine>] An array of confines restricting
31
- # this to a specific platform
32
- # @see Facter::Core::Suitable
35
+ #
36
+ # @return [Array<LegacyFacter::Core::Confine>] An array of confines restricting
37
+ # this to a specific platform
38
+ #
39
+ # @api private
33
40
  attr_reader :confines
34
41
 
35
42
  # @!attribute [r] fact
43
+ #
36
44
  # @return [Facter::Util::Fact]
45
+ #
37
46
  # @api private
38
47
  attr_reader :fact
39
48
 
@@ -48,10 +57,20 @@ module Facter
48
57
  @deps = LegacyFacter::Core::DirectedGraph.new
49
58
  end
50
59
 
60
+ # Compares the weight of two aggregate facts
61
+ #
62
+ # @return [bool] Weight comparison result
63
+ #
64
+ # @api private
51
65
  def <=>(other)
52
66
  weight <=> other.weight
53
67
  end
54
68
 
69
+ # Sets options for the aggregate fact
70
+ #
71
+ # @return [nil]
72
+ #
73
+ # @api private
55
74
  def options(options)
56
75
  accepted_options = %i[name timeout weight fact_type]
57
76
  accepted_options.each do |option_name|
@@ -60,14 +79,17 @@ module Facter
60
79
  raise ArgumentError, "Invalid aggregate options #{options.keys.inspect}" unless options.keys.empty?
61
80
  end
62
81
 
82
+ # Evaluates the given block
83
+ #
84
+ # @return [String] Result of the block's evaluation
85
+ #
86
+ # @api private
63
87
  def evaluate(&block)
64
88
  instance_eval(&block)
65
89
  end
66
90
 
67
91
  # Define a new chunk for the given aggregate
68
92
  #
69
- # @api public
70
- #
71
93
  # @example Defining a chunk with no dependencies
72
94
  # aggregate.chunk(:mountpoints) do
73
95
  # # generate mountpoint information
@@ -80,14 +102,14 @@ module Facter
80
102
  # end
81
103
  #
82
104
  # @param name [Symbol] A name unique to this aggregate describing the chunk
83
- # @param opts [Hash]
84
- # @options opts [Array<Symbol>, Symbol] :require One or more chunks
85
- # to evaluate and pass to this block.
86
- # @yield [*Object] Zero or more chunk results
87
105
  #
88
- # @return [void]
106
+ # @param opts [Hash] Hash with options for the aggregate fact
107
+ #
108
+ # @return [Facter::Core::Aggregate] The aggregate object
109
+ #
110
+ # @api public
89
111
  def chunk(name, opts = {}, &block)
90
- raise ArgumentError, "#{self.class.name}#chunk requires a block" unless block_given?
112
+ evaluate_params(name, &block)
91
113
 
92
114
  deps = Array(opts.delete(:require))
93
115
 
@@ -97,12 +119,11 @@ module Facter
97
119
 
98
120
  @deps[name] = deps
99
121
  @chunks[name] = block
122
+ self
100
123
  end
101
124
 
102
125
  # Define how all chunks should be combined
103
126
  #
104
- # @api public
105
- #
106
127
  # @example Merge all chunks
107
128
  # aggregate.aggregate do |chunks|
108
129
  # final_result = {}
@@ -124,19 +145,32 @@ module Facter
124
145
  # @yield [Hash<Symbol, Object>] A hash containing chunk names and
125
146
  # chunk values
126
147
  #
127
- # @return [void]
148
+ # @return [Facter::Core::Aggregate] The aggregate fact
149
+ #
150
+ # @api public
128
151
  def aggregate(&block)
129
152
  raise ArgumentError, "#{self.class.name}#aggregate requires a block" unless block_given?
130
153
 
131
154
  @aggregate = block
155
+ self
132
156
  end
133
157
 
158
+ # Returns the fact's resolution type
159
+ #
160
+ # @return [Symbol] The fact's type
161
+ #
162
+ # @api private
134
163
  def resolution_type
135
164
  :aggregate
136
165
  end
137
166
 
138
167
  private
139
168
 
169
+ def evaluate_params(name)
170
+ raise ArgumentError, "#{self.class.name}#chunk requires a block" unless block_given?
171
+ raise ArgumentError, "#{self.class.name}#expected chunk name to be a Symbol" unless name.is_a? Symbol
172
+ end
173
+
140
174
  # Evaluate the results of this aggregate.
141
175
  #
142
176
  # @see Facter::Core::Resolvable#value