facter 4.0.42 → 4.0.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/facter.rb +47 -19
- data/lib/facter/custom_facts/core/aggregate.rb +51 -17
- data/lib/facter/custom_facts/core/execution.rb +27 -35
- data/lib/facter/custom_facts/util/resolution.rb +40 -11
- data/lib/facter/facts/solaris/zones.rb +1 -1
- data/lib/facter/facts_utils/virtual_detector.rb +1 -1
- data/lib/facter/framework/cli/cli.rb +5 -6
- data/lib/facter/resolvers/dmi_resolver.rb +2 -2
- data/lib/facter/resolvers/mountpoints_resolver.rb +5 -2
- data/lib/facter/resolvers/networking_linux_resolver.rb +10 -4
- data/lib/facter/resolvers/processors_resolver.rb +5 -1
- data/lib/facter/resolvers/solaris/mountpoints.rb +60 -0
- data/lib/facter/resolvers/solaris/networking.rb +1 -1
- data/lib/facter/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02e89a2638e45004e55f6b0ec4d902946c844b5253ee4e27139ab01d1ee12a92
|
4
|
+
data.tar.gz: bd4405449c4804a3c872510042a33c2cd6cf7fd588df8f95a99893fcb9248291
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31feabfeb9c2008ae30f16b6469cdf689b78e8711d64e3b614481a3e98b41d8271822b6cb26511a56ba5e19394f2ea811552b29168484d8ee377dbd3697f6655
|
7
|
+
data.tar.gz: f579f81b0dc6fedf937d016e531650c183bc4f89ce66c918f47932af01e97bfc19f0e0f012adcfe36a52e4a9a314685765055fe23bde5aa4cf5b2f92353a450c
|
data/lib/facter.rb
CHANGED
@@ -17,6 +17,12 @@ module Facter
|
|
17
17
|
@warn_once = []
|
18
18
|
|
19
19
|
class << self
|
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
|
20
26
|
def resolve(args_as_string)
|
21
27
|
require 'facter/framework/cli/cli_launcher'
|
22
28
|
|
@@ -36,10 +42,7 @@ module Facter
|
|
36
42
|
else
|
37
43
|
cli.invoke(:arg_parser)
|
38
44
|
end
|
39
|
-
|
40
|
-
|
41
|
-
def clear_messages
|
42
|
-
logger.debug('clear_messages is not implemented')
|
45
|
+
nil
|
43
46
|
end
|
44
47
|
|
45
48
|
# Alias method for Facter.fact()
|
@@ -83,8 +86,16 @@ module Facter
|
|
83
86
|
Options[:custom_dir] = []
|
84
87
|
LegacyFacter.collection.invalidate_custom_facts
|
85
88
|
LegacyFacter.collection.reload_custom_facts
|
89
|
+
SessionCache.invalidate_all_caches
|
90
|
+
nil
|
86
91
|
end
|
87
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
|
88
99
|
def core_value(user_query)
|
89
100
|
user_query = user_query.to_s
|
90
101
|
resolved_facts = Facter::FactManager.instance.resolve_core([user_query])
|
@@ -136,8 +147,16 @@ module Facter
|
|
136
147
|
LegacyFacter.define_fact(name, options, &block)
|
137
148
|
end
|
138
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
|
139
157
|
def on_message(&block)
|
140
158
|
Facter::Log.on_message(&block)
|
159
|
+
nil
|
141
160
|
end
|
142
161
|
|
143
162
|
# Check whether debugging is enabled
|
@@ -170,7 +189,6 @@ module Facter
|
|
170
189
|
def each
|
171
190
|
log_blocked_facts
|
172
191
|
resolved_facts = Facter::FactManager.instance.resolve_facts
|
173
|
-
SessionCache.invalidate_all_caches
|
174
192
|
|
175
193
|
resolved_facts.each do |fact|
|
176
194
|
yield(fact.name, fact.value)
|
@@ -206,6 +224,7 @@ module Facter
|
|
206
224
|
LegacyFacter.reset
|
207
225
|
Options[:custom_dir] = []
|
208
226
|
Options[:external_dir] = []
|
227
|
+
SessionCache.invalidate_all_caches
|
209
228
|
nil
|
210
229
|
end
|
211
230
|
|
@@ -220,26 +239,26 @@ module Facter
|
|
220
239
|
end
|
221
240
|
|
222
241
|
# Register directories to be searched for custom facts. The registered directories
|
223
|
-
#
|
224
|
-
#
|
242
|
+
# must be absolute paths or they will be ignored.
|
225
243
|
# @param dirs [Array<String>] An array of searched directories
|
226
244
|
#
|
227
|
-
# @return [
|
245
|
+
# @return [nil]
|
228
246
|
#
|
229
247
|
# @api public
|
230
248
|
def search(*dirs)
|
231
249
|
Options[:custom_dir] += dirs
|
250
|
+
nil
|
232
251
|
end
|
233
252
|
|
234
253
|
# Registers directories to be searched for external facts.
|
235
|
-
#
|
236
254
|
# @param dirs [Array<String>] An array of searched directories
|
237
255
|
#
|
238
|
-
# @return [
|
256
|
+
# @return [nil]
|
239
257
|
#
|
240
258
|
# @api public
|
241
259
|
def search_external(dirs)
|
242
260
|
Options[:external_dir] += dirs
|
261
|
+
nil
|
243
262
|
end
|
244
263
|
|
245
264
|
# Returns the registered search directories.for external facts.
|
@@ -263,14 +282,13 @@ module Facter
|
|
263
282
|
# Gets a hash mapping fact names to their values
|
264
283
|
# The hash contains core facts, legacy facts, custom facts and external facts (all facts that can be resolved).
|
265
284
|
#
|
266
|
-
# @return [FactCollection]
|
285
|
+
# @return [FactCollection] hash with fact names and values
|
267
286
|
#
|
268
287
|
# @api public
|
269
288
|
def to_hash
|
270
289
|
log_blocked_facts
|
271
290
|
|
272
291
|
resolved_facts = Facter::FactManager.instance.resolve_facts
|
273
|
-
Facter::SessionCache.invalidate_all_caches
|
274
292
|
Facter::FactCollection.new.build_fact_collection!(resolved_facts)
|
275
293
|
end
|
276
294
|
|
@@ -286,7 +304,7 @@ module Facter
|
|
286
304
|
# Enable or disable trace
|
287
305
|
# @param bool [bool] Set trace on debug state
|
288
306
|
#
|
289
|
-
# @return [
|
307
|
+
# @return [bool] Value of trace debug state
|
290
308
|
#
|
291
309
|
# @api public
|
292
310
|
def trace(bool)
|
@@ -305,10 +323,19 @@ module Facter
|
|
305
323
|
@already_searched[user_query]&.value
|
306
324
|
end
|
307
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
|
308
336
|
def values(options, user_queries)
|
309
337
|
init_cli_options(options, user_queries)
|
310
338
|
resolved_facts = Facter::FactManager.instance.resolve_facts(user_queries)
|
311
|
-
Facter::SessionCache.invalidate_all_caches
|
312
339
|
|
313
340
|
if user_queries.count.zero?
|
314
341
|
Facter::FactCollection.new.build_fact_collection!(resolved_facts)
|
@@ -336,7 +363,6 @@ module Facter
|
|
336
363
|
logger.info("executed with command line: #{ARGV.drop(1).join(' ')}")
|
337
364
|
log_blocked_facts
|
338
365
|
resolved_facts = Facter::FactManager.instance.resolve_facts(args)
|
339
|
-
SessionCache.invalidate_all_caches
|
340
366
|
fact_formatter = Facter::FormatterFactory.build(Facter::Options.get)
|
341
367
|
|
342
368
|
status = error_check(resolved_facts)
|
@@ -344,6 +370,11 @@ module Facter
|
|
344
370
|
[fact_formatter.format(resolved_facts), status || 0]
|
345
371
|
end
|
346
372
|
|
373
|
+
# Logs an exception and an optional message
|
374
|
+
#
|
375
|
+
# @return [nil]
|
376
|
+
#
|
377
|
+
# @api public
|
347
378
|
def log_exception(exception, message = nil)
|
348
379
|
error_message = []
|
349
380
|
|
@@ -351,10 +382,10 @@ module Facter
|
|
351
382
|
|
352
383
|
parse_exception(exception, error_message)
|
353
384
|
logger.error(error_message.flatten.join("\n"))
|
385
|
+
nil
|
354
386
|
end
|
355
387
|
|
356
388
|
# Returns a list with the names of all solved facts
|
357
|
-
#
|
358
389
|
# @return [Array] the list with all the fact names
|
359
390
|
#
|
360
391
|
# @api public
|
@@ -363,7 +394,6 @@ module Facter
|
|
363
394
|
end
|
364
395
|
|
365
396
|
# Logs the message parameter as a warning.
|
366
|
-
#
|
367
397
|
# @param message [Object] the warning object to be displayed
|
368
398
|
#
|
369
399
|
# @return [nil]
|
@@ -375,7 +405,6 @@ module Facter
|
|
375
405
|
end
|
376
406
|
|
377
407
|
# Logs only once the same warning message.
|
378
|
-
#
|
379
408
|
# @param message [Object] the warning message object
|
380
409
|
#
|
381
410
|
# @return [nil]
|
@@ -426,7 +455,6 @@ module Facter
|
|
426
455
|
def resolve_fact(user_query)
|
427
456
|
user_query = user_query.to_s
|
428
457
|
resolved_facts = Facter::FactManager.instance.resolve_facts([user_query])
|
429
|
-
SessionCache.invalidate_all_caches
|
430
458
|
# we must make a distinction between custom facts that return nil and nil facts
|
431
459
|
# Nil facts should not be packaged as ResolvedFacts! (add_fact_to_searched_facts packages facts)
|
432
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
|
-
#
|
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
|
-
#
|
26
|
-
#
|
28
|
+
#
|
29
|
+
# @return [LegacyFacter::Core::DirectedGraph]
|
30
|
+
#
|
31
|
+
# @api private
|
27
32
|
attr_reader :deps
|
28
33
|
|
29
34
|
# @!attribute [r] confines
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
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
|
-
# @
|
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
|
-
|
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 [
|
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
|
@@ -3,10 +3,6 @@
|
|
3
3
|
module Facter
|
4
4
|
module Core
|
5
5
|
module Execution
|
6
|
-
# require_relative 'execution/base'
|
7
|
-
# require_relative 'execution/windows'
|
8
|
-
# require_relative 'execution/posix'
|
9
|
-
|
10
6
|
@@impl = if LegacyFacter::Util::Config.windows?
|
11
7
|
Facter::Core::Execution::Windows.new
|
12
8
|
else
|
@@ -20,24 +16,22 @@ module Facter
|
|
20
16
|
module_function
|
21
17
|
|
22
18
|
# Returns the locations to be searched when looking for a binary. This
|
23
|
-
#
|
24
|
-
#
|
19
|
+
# is currently determined by the +PATH+ environment variable plus
|
20
|
+
# `/sbin` and `/usr/sbin` when run on unix
|
21
|
+
#
|
22
|
+
# @return [Array<String>] The paths to be searched for binaries
|
25
23
|
#
|
26
|
-
# @return [Array<String>] the paths to be searched for binaries
|
27
24
|
# @api private
|
28
25
|
def search_paths
|
29
26
|
@@impl.search_paths
|
30
27
|
end
|
31
28
|
|
32
29
|
# Determines the full path to a binary. If the supplied filename does not
|
33
|
-
#
|
34
|
-
#
|
30
|
+
# already describe an absolute path then different locations (determined
|
31
|
+
# by {search_paths}) will be searched for a match.
|
32
|
+
# @param bin [String] The executable to locate
|
35
33
|
#
|
36
|
-
#
|
37
|
-
# the expanded pathname.
|
38
|
-
#
|
39
|
-
# @param bin [String] the executable to locate
|
40
|
-
# @return [String,nil] the full path to the executable or nil if not
|
34
|
+
# @return [String/nil] The full path to the executable or nil if not
|
41
35
|
# found
|
42
36
|
#
|
43
37
|
# @api public
|
@@ -46,10 +40,12 @@ module Facter
|
|
46
40
|
end
|
47
41
|
|
48
42
|
# Determine in a platform-specific way whether a path is absolute. This
|
49
|
-
#
|
43
|
+
# defaults to the local platform if none is specified.
|
44
|
+
# @param path [String] The path to check
|
45
|
+
|
46
|
+
# @param platform [:posix/:windows/nil] The platform logic to use
|
50
47
|
#
|
51
|
-
# @
|
52
|
-
# @param platform [:posix,:windows,nil] the platform logic to use
|
48
|
+
# @api private
|
53
49
|
def absolute_path?(path, platform = nil)
|
54
50
|
case platform
|
55
51
|
when :posix
|
@@ -62,38 +58,35 @@ module Facter
|
|
62
58
|
end
|
63
59
|
|
64
60
|
# Given a command line, this returns the command line with the
|
65
|
-
#
|
66
|
-
#
|
67
|
-
#
|
61
|
+
# executable written as an absolute path. If the executable contains
|
62
|
+
# spaces, it has to be put in double quotes to be properly recognized.
|
68
63
|
# @param command [String] the command line
|
69
64
|
#
|
70
|
-
# @return [String
|
71
|
-
#
|
65
|
+
# @return [String/nil] The command line with the executable's path
|
66
|
+
# expanded, or nil if the executable cannot be found.
|
67
|
+
#
|
68
|
+
# @api private
|
72
69
|
def expand_command(command)
|
73
70
|
@@impl.expand_command(command)
|
74
71
|
end
|
75
72
|
|
76
73
|
# Overrides environment variables within a block of code. The
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
# @overload with_env(values, { || ... })
|
81
|
-
#
|
74
|
+
# specified values will be set for the duration of the block, after
|
75
|
+
# which the original values (if any) will be restored.
|
82
76
|
# @param values [Hash<String=>String>] A hash of the environment
|
83
77
|
# variables to override
|
84
78
|
#
|
85
|
-
# @return [
|
79
|
+
# @return [String] The block's return string
|
86
80
|
#
|
87
|
-
# @api
|
81
|
+
# @api private
|
88
82
|
def with_env(values, &block)
|
89
83
|
@@impl.with_env(values, &block)
|
90
84
|
end
|
91
85
|
|
92
86
|
# Try to execute a command and return the output.
|
87
|
+
# @param command [String] Command to run
|
93
88
|
#
|
94
|
-
# @
|
95
|
-
#
|
96
|
-
# @return [String] the output of the program, or nil if the command does
|
89
|
+
# @return [String/nil] Output of the program, or nil if the command does
|
97
90
|
# not exist or could not be executed.
|
98
91
|
#
|
99
92
|
# @deprecated Use #{execute} instead
|
@@ -103,9 +96,9 @@ module Facter
|
|
103
96
|
end
|
104
97
|
|
105
98
|
# Execute a command and return the output of that program.
|
99
|
+
# @param command [String] Command to run
|
106
100
|
#
|
107
|
-
# @param
|
108
|
-
# @param options [Hash]
|
101
|
+
# @param options [Hash] Hash with options for the aggregate fact
|
109
102
|
#
|
110
103
|
# @option options [Object] :on_fail How to behave when the command could
|
111
104
|
# not be run. Specifying :raise will raise an error, anything else will
|
@@ -118,7 +111,6 @@ module Facter
|
|
118
111
|
# command execution failed and :on_fail was specified.
|
119
112
|
#
|
120
113
|
# @api public
|
121
|
-
# @since 2.0.1
|
122
114
|
def execute(command, options = {})
|
123
115
|
@@impl.execute(command, options)
|
124
116
|
end
|
@@ -14,6 +14,8 @@ module Facter
|
|
14
14
|
class Resolution
|
15
15
|
# @api private
|
16
16
|
attr_accessor :code, :fact_type
|
17
|
+
|
18
|
+
# @api private
|
17
19
|
attr_writer :value
|
18
20
|
|
19
21
|
extend Facter::Core::Execution
|
@@ -24,7 +26,12 @@ module Facter
|
|
24
26
|
# compatibility.
|
25
27
|
#
|
26
28
|
# @deprecated
|
27
|
-
|
29
|
+
#
|
30
|
+
# @api public
|
31
|
+
public :which, :exec
|
32
|
+
|
33
|
+
# @api private
|
34
|
+
public :with_env
|
28
35
|
end
|
29
36
|
|
30
37
|
include LegacyFacter::Core::Resolvable
|
@@ -32,22 +39,27 @@ module Facter
|
|
32
39
|
|
33
40
|
# @!attribute [rw] name
|
34
41
|
# The name of this resolution. The resolution name should be unique with
|
35
|
-
#
|
42
|
+
# respect to the given fact.
|
43
|
+
#
|
36
44
|
# @return [String]
|
45
|
+
#
|
37
46
|
# @api public
|
38
47
|
attr_accessor :name
|
39
48
|
|
40
49
|
# @!attribute [r] fact
|
41
|
-
#
|
50
|
+
#
|
51
|
+
# @return [Facter::Util::Fact] Associated fact with this resolution.
|
52
|
+
#
|
42
53
|
# @api private
|
43
54
|
attr_reader :fact
|
44
55
|
|
45
56
|
# Create a new resolution mechanism.
|
46
57
|
#
|
47
58
|
# @param name [String] The name of the resolution.
|
48
|
-
# @return [void]
|
49
59
|
#
|
50
|
-
# @
|
60
|
+
# @return [Facter::Util::Resolution] The created resolution
|
61
|
+
#
|
62
|
+
# @api public
|
51
63
|
def initialize(name, fact)
|
52
64
|
@name = name
|
53
65
|
@fact = fact
|
@@ -57,6 +69,11 @@ module Facter
|
|
57
69
|
@weight = nil
|
58
70
|
end
|
59
71
|
|
72
|
+
# Returns the fact's resolution type
|
73
|
+
#
|
74
|
+
# @return [Symbol] The fact's type
|
75
|
+
#
|
76
|
+
# @api private
|
60
77
|
def resolution_type
|
61
78
|
:simple
|
62
79
|
end
|
@@ -64,7 +81,9 @@ module Facter
|
|
64
81
|
# Evaluate the given block in the context of this resolution. If a block has
|
65
82
|
# already been evaluated emit a warning to that effect.
|
66
83
|
#
|
67
|
-
# @return [
|
84
|
+
# @return [String] Result of the block's evaluation
|
85
|
+
#
|
86
|
+
# @api private
|
68
87
|
def evaluate(&block)
|
69
88
|
if @last_evaluated
|
70
89
|
msg = "Already evaluated #{@name}"
|
@@ -85,6 +104,11 @@ module Facter
|
|
85
104
|
end
|
86
105
|
end
|
87
106
|
|
107
|
+
# Sets options for the aggregate fact
|
108
|
+
#
|
109
|
+
# @return [nil]
|
110
|
+
#
|
111
|
+
# @api private
|
88
112
|
def options(options)
|
89
113
|
accepted_options = %i[name value timeout weight fact_type file]
|
90
114
|
|
@@ -98,8 +122,6 @@ module Facter
|
|
98
122
|
# Sets the code block or external program that will be evaluated to
|
99
123
|
# get the value of the fact.
|
100
124
|
#
|
101
|
-
# @return [void]
|
102
|
-
#
|
103
125
|
# @overload setcode(string)
|
104
126
|
# Sets an external program to call to get the value of the resolution
|
105
127
|
# @param [String] string the external program to run to get the
|
@@ -111,6 +133,8 @@ module Facter
|
|
111
133
|
# This block is run when the fact is evaluated. Errors raised from
|
112
134
|
# inside the block are rescued and printed to stderr.
|
113
135
|
#
|
136
|
+
# @return [Facter::Util::Resolution] Returns itself
|
137
|
+
#
|
114
138
|
# @api public
|
115
139
|
def setcode(string = nil, &block)
|
116
140
|
if string
|
@@ -127,11 +151,16 @@ module Facter
|
|
127
151
|
else
|
128
152
|
raise ArgumentError, 'You must pass either code or a block'
|
129
153
|
end
|
154
|
+
self
|
130
155
|
end
|
131
156
|
|
132
|
-
#
|
133
|
-
#
|
134
|
-
#
|
157
|
+
# Comparison is done based on weight and fact type.
|
158
|
+
# The greater the weight, the higher the priority.
|
159
|
+
# If weights are equal, we consider external facts greater than custom facts.
|
160
|
+
#
|
161
|
+
# @return [bool] Weight comparison result
|
162
|
+
#
|
163
|
+
# @api private
|
135
164
|
def <=>(other)
|
136
165
|
return compare_equal_weights(other) if weight == other.weight
|
137
166
|
return 1 if weight > other.weight
|
@@ -28,7 +28,7 @@ module Facts
|
|
28
28
|
end
|
29
29
|
|
30
30
|
resolved_facts << Facter::ResolvedFact.new('solaris_zones.zones', zones)
|
31
|
-
resolved_facts << Facter::ResolvedFact.new('zones', results.count
|
31
|
+
resolved_facts << Facter::ResolvedFact.new('zones', results.count, :legacy)
|
32
32
|
|
33
33
|
resolved_facts.flatten
|
34
34
|
end
|
@@ -22,7 +22,7 @@ module Facter
|
|
22
22
|
@log.debug('Checking DMI')
|
23
23
|
vendor = Facter::Resolvers::DmiDecode.resolve(:vendor)
|
24
24
|
@log.debug("dmi detected vendor: #{vendor}")
|
25
|
-
return '
|
25
|
+
return 'kvm' if vendor =~ /Amazon/
|
26
26
|
|
27
27
|
'xen' if vendor =~ /Xen/
|
28
28
|
end
|
@@ -79,6 +79,11 @@ module Facter
|
|
79
79
|
type: :boolean,
|
80
80
|
desc: 'Show legacy facts when querying all facts.'
|
81
81
|
|
82
|
+
class_option :puppet,
|
83
|
+
type: :boolean,
|
84
|
+
aliases: '-p',
|
85
|
+
desc: 'Load the Puppet libraries, thus allowing Facter to load Puppet-specific facts.'
|
86
|
+
|
82
87
|
class_option :yaml,
|
83
88
|
aliases: '-y',
|
84
89
|
type: :boolean,
|
@@ -152,12 +157,6 @@ module Facter
|
|
152
157
|
puts cache_groups
|
153
158
|
end
|
154
159
|
|
155
|
-
desc '--puppet, -p', '(NOT SUPPORTED)Load the Puppet libraries, thus allowing Facter to load Puppet-specific facts.'
|
156
|
-
map ['--puppet', '-p'] => :puppet
|
157
|
-
def puppet(*_args)
|
158
|
-
puts '`facter --puppet` and `facter -p` are no longer supported, use `puppet facts show` instead'
|
159
|
-
end
|
160
|
-
|
161
160
|
desc 'help', 'Help for all arguments'
|
162
161
|
def help(*args)
|
163
162
|
help_string = +''
|
@@ -36,9 +36,9 @@ module Facter
|
|
36
36
|
|
37
37
|
file_content = Util::FileHelper.safe_read("/sys/class/dmi/id/#{fact_name}", nil)
|
38
38
|
if files.include?(fact_name.to_s) && file_content
|
39
|
-
|
39
|
+
file_content = file_content.strip
|
40
|
+
@fact_list[fact_name] = file_content unless file_content.empty?
|
40
41
|
chassis_to_name(@fact_list[fact_name]) if fact_name == :chassis_type
|
41
|
-
|
42
42
|
end
|
43
43
|
@fact_list[fact_name]
|
44
44
|
end
|
@@ -10,7 +10,7 @@ module Facter
|
|
10
10
|
private
|
11
11
|
|
12
12
|
def post_resolve(fact_name)
|
13
|
-
@fact_list.fetch(fact_name) { read_mounts }
|
13
|
+
@fact_list.fetch(fact_name) { read_mounts(fact_name) }
|
14
14
|
end
|
15
15
|
|
16
16
|
def root_device
|
@@ -26,7 +26,8 @@ module Facter
|
|
26
26
|
device
|
27
27
|
end
|
28
28
|
|
29
|
-
|
29
|
+
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
30
|
+
def read_mounts(fact_name)
|
30
31
|
mounts = []
|
31
32
|
FilesystemHelper.read_mountpoints.each do |fs|
|
32
33
|
device = compute_device(fs.name)
|
@@ -52,7 +53,9 @@ module Facter
|
|
52
53
|
.map { |v| binding.local_variable_get(v) })]
|
53
54
|
end
|
54
55
|
@fact_list[:mountpoints] = mounts
|
56
|
+
@fact_list[fact_name]
|
55
57
|
end
|
58
|
+
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
56
59
|
end
|
57
60
|
end
|
58
61
|
end
|
@@ -59,9 +59,14 @@ module Facter
|
|
59
59
|
return if !network_info[interface_name] || network_info[interface_name][:dhcp]
|
60
60
|
|
61
61
|
index = tokens[0].delete(':')
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
file_content = Util::FileHelper.safe_read("/run/systemd/netif/leases/#{index}", nil)
|
63
|
+
dhcp = file_content.match(/SERVER_ADDRESS=(.*)/) if file_content
|
64
|
+
if dhcp
|
65
|
+
network_info[interface_name][:dhcp] = dhcp[1]
|
66
|
+
else
|
67
|
+
alternate_dhcp = retrieve_from_other_directories(interface_name)
|
68
|
+
network_info[interface_name][:dhcp] = alternate_dhcp if alternate_dhcp
|
69
|
+
end
|
65
70
|
end
|
66
71
|
|
67
72
|
def retrieve_from_other_directories(interface_name)
|
@@ -75,7 +80,8 @@ module Facter
|
|
75
80
|
content = Util::FileHelper.safe_read("#{dir}#{file}", nil)
|
76
81
|
next unless content =~ /interface.*#{interface_name}/
|
77
82
|
|
78
|
-
|
83
|
+
dhcp = content.match(/dhcp-server-identifier ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/)
|
84
|
+
return dhcp[1] if dhcp
|
79
85
|
end
|
80
86
|
end
|
81
87
|
return unless File.readable?('/var/lib/NetworkManager/')
|
@@ -60,7 +60,11 @@ module Facter
|
|
60
60
|
def physical_devices_count
|
61
61
|
Dir.entries('/sys/devices/system/cpu')
|
62
62
|
.select { |dir| dir =~ /cpu[0-9]+$/ }
|
63
|
-
.
|
63
|
+
.select { |dir| File.exist?("/sys/devices/system/cpu/#{dir}/topology/physical_package_id") }
|
64
|
+
.map do |dir|
|
65
|
+
Util::FileHelper.safe_read("/sys/devices/system/cpu/#{dir}/topology/physical_package_id").strip
|
66
|
+
end
|
67
|
+
.uniq.count
|
64
68
|
end
|
65
69
|
|
66
70
|
def build_speed(tokens)
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Facter
|
4
|
+
module Resolvers
|
5
|
+
module Solaris
|
6
|
+
class Mountpoints < BaseResolver
|
7
|
+
include Facter::FilesystemHelper
|
8
|
+
@fact_list ||= {}
|
9
|
+
@log = Facter::Log.new(self)
|
10
|
+
class << self
|
11
|
+
private
|
12
|
+
|
13
|
+
def post_resolve(fact_name)
|
14
|
+
@fact_list.fetch(fact_name) { read_mounts(fact_name) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def root_device
|
18
|
+
cmdline = 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
|
28
|
+
end
|
29
|
+
|
30
|
+
def read_mounts(fact_name) # rubocop:disable Metrics/AbcSize
|
31
|
+
mounts = []
|
32
|
+
FilesystemHelper.read_mountpoints.each do |fs|
|
33
|
+
device = compute_device(fs.name)
|
34
|
+
filesystem = fs.mount_type
|
35
|
+
path = fs.mount_point
|
36
|
+
options = fs.options.split(',').map(&:strip)
|
37
|
+
|
38
|
+
stats = FilesystemHelper.read_mountpoint_stats(path)
|
39
|
+
size_bytes = stats.bytes_total.abs
|
40
|
+
available_bytes = stats.bytes_available.abs
|
41
|
+
|
42
|
+
used_bytes = stats.bytes_used.abs
|
43
|
+
total_bytes = used_bytes + available_bytes
|
44
|
+
capacity = FilesystemHelper.compute_capacity(used_bytes, total_bytes)
|
45
|
+
|
46
|
+
size = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(size_bytes)
|
47
|
+
available = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(available_bytes)
|
48
|
+
used = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(used_bytes)
|
49
|
+
|
50
|
+
mounts << Hash[FilesystemHelper::MOUNT_KEYS.zip(FilesystemHelper::MOUNT_KEYS
|
51
|
+
.map { |v| binding.local_variable_get(v) })]
|
52
|
+
end
|
53
|
+
@fact_list[:mountpoints] = mounts
|
54
|
+
@fact_list[fact_name]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -66,7 +66,7 @@ module Facter
|
|
66
66
|
|
67
67
|
@log.debug("Error! #{::FFI::LastError.error}") if ioctl == -1
|
68
68
|
|
69
|
-
@interfaces[lifreq.name][:mtu]
|
69
|
+
@interfaces[lifreq.name][:mtu] ||= lifreq[:lifr_lifru][:lifru_metric]
|
70
70
|
end
|
71
71
|
|
72
72
|
def load_netmask(lifreq)
|
data/lib/facter/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: facter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.43
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -936,6 +936,7 @@ files:
|
|
936
936
|
- lib/facter/resolvers/solaris/ipaddress.rb
|
937
937
|
- lib/facter/resolvers/solaris/ldom.rb
|
938
938
|
- lib/facter/resolvers/solaris/memory.rb
|
939
|
+
- lib/facter/resolvers/solaris/mountpoints.rb
|
939
940
|
- lib/facter/resolvers/solaris/networking.rb
|
940
941
|
- lib/facter/resolvers/solaris/os_release.rb
|
941
942
|
- lib/facter/resolvers/solaris/processors.rb
|