facter 4.2.0 → 4.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +202 -0
- data/lib/facter/custom_facts/core/file_loader.rb +0 -1
- data/lib/facter/custom_facts/core/legacy_facter.rb +0 -2
- data/lib/facter/custom_facts/core/resolvable.rb +1 -1
- data/lib/facter/custom_facts/util/collection.rb +6 -4
- data/lib/facter/custom_facts/util/confine.rb +9 -3
- data/lib/facter/custom_facts/util/directory_loader.rb +18 -6
- data/lib/facter/custom_facts/util/fact.rb +12 -10
- data/lib/facter/custom_facts/util/loader.rb +7 -3
- data/lib/facter/custom_facts/util/parser.rb +8 -2
- data/lib/facter/custom_facts/util/resolution.rb +5 -1
- data/lib/facter/framework/cli/cli.rb +13 -15
- data/lib/facter/framework/core/fact/internal/internal_fact_manager.rb +0 -2
- data/lib/facter/framework/core/fact_loaders/fact_loader.rb +0 -1
- data/lib/facter/framework/core/fact_manager.rb +11 -0
- data/lib/facter/framework/logging/logger.rb +61 -0
- data/lib/facter/framework/parsers/query_parser.rb +1 -4
- data/lib/facter/resolvers/aix/disks.rb +1 -1
- data/lib/facter/resolvers/aix/mountpoints.rb +1 -1
- data/lib/facter/resolvers/aix/partitions.rb +1 -1
- data/lib/facter/resolvers/ec2.rb +8 -1
- data/lib/facter/resolvers/linux/networking.rb +0 -1
- data/lib/facter/resolvers/lsb_release.rb +1 -2
- data/lib/facter/resolvers/macosx/{processor.rb → processors.rb} +21 -21
- data/lib/facter/resolvers/networking.rb +3 -1
- data/lib/facter/resolvers/os_release.rb +7 -4
- data/lib/facter/resolvers/partitions.rb +1 -3
- data/lib/facter/resolvers/windows/ffi/kernel_ffi.rb +1 -1
- data/lib/facter/util/aix/info_extractor.rb +60 -9
- data/lib/facter/util/linux/dhcp.rb +4 -1
- data/lib/facter/util/linux/socket_parser.rb +17 -2
- data/lib/facter/version.rb +1 -1
- data/lib/facter.rb +12 -18
- metadata +25 -5
- data/lib/facter/custom_facts/core/logging.rb +0 -203
@@ -107,9 +107,7 @@ module Facter
|
|
107
107
|
|
108
108
|
return blkid_and_lsblk[command_exists_key] unless blkid_and_lsblk[command_exists_key].nil?
|
109
109
|
|
110
|
-
|
111
|
-
|
112
|
-
blkid_and_lsblk[command_exists_key] = !output.empty?
|
110
|
+
blkid_and_lsblk[command_exists_key] = !Facter::Core::Execution.which(command).nil?
|
113
111
|
end
|
114
112
|
|
115
113
|
def execute_and_extract_blkid_info
|
@@ -6,17 +6,68 @@ module Facter
|
|
6
6
|
module InfoExtractor
|
7
7
|
MEGABYTES_EXPONENT = 1024**2
|
8
8
|
GIGABYTES_EXPONENT = 1024**3
|
9
|
+
PROPERTIES = {
|
10
|
+
lslv: [
|
11
|
+
'LOGICAL VOLUME:',
|
12
|
+
'VOLUME GROUP:',
|
13
|
+
'LV IDENTIFIER:',
|
14
|
+
'PERMISSION:',
|
15
|
+
'VG STATE:',
|
16
|
+
'LV STATE:',
|
17
|
+
'TYPE:',
|
18
|
+
'WRITE VERIFY:',
|
19
|
+
'MAX LPs:',
|
20
|
+
'PP SIZE:',
|
21
|
+
'COPIES:',
|
22
|
+
'SCHED POLICY:',
|
23
|
+
'LPs:',
|
24
|
+
'PPs:',
|
25
|
+
'STALE PPs:',
|
26
|
+
'BB POLICY:',
|
27
|
+
'INTER-POLICY:',
|
28
|
+
'RELOCATABLE:',
|
29
|
+
'INTRA-POLICY:',
|
30
|
+
'UPPER BOUND:',
|
31
|
+
'MOUNT POINT:',
|
32
|
+
'LABEL:',
|
33
|
+
'MIRROR WRITE CONSISTENCY:',
|
34
|
+
'EACH LP COPY ON A SEPARATE PV ?:',
|
35
|
+
'Serialize IO ?:'
|
36
|
+
],
|
37
|
+
lspv: [
|
38
|
+
'PHYSICAL VOLUME:',
|
39
|
+
'VOLUME GROUP:',
|
40
|
+
'PV IDENTIFIER:',
|
41
|
+
'VG IDENTIFIER',
|
42
|
+
'PV STATE:',
|
43
|
+
'STALE PARTITIONS:',
|
44
|
+
'ALLOCATABLE:',
|
45
|
+
'PP SIZE:',
|
46
|
+
'LOGICAL VOLUMES:',
|
47
|
+
'TOTAL PPs:',
|
48
|
+
'VG DESCRIPTORS:',
|
49
|
+
'FREE PPs:',
|
50
|
+
'HOT SPARE:',
|
51
|
+
'USED PPs:',
|
52
|
+
'MAX REQUEST:',
|
53
|
+
'FREE DISTRIBUTION:',
|
54
|
+
'USED DISTRIBUTION:',
|
55
|
+
'MIRROR POOL:'
|
56
|
+
]
|
57
|
+
}.freeze
|
9
58
|
|
10
|
-
def self.extract(content,
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
59
|
+
def self.extract(content, cmd)
|
60
|
+
property_hash = {}
|
61
|
+
properties = PROPERTIES[cmd]
|
62
|
+
properties.each do |property|
|
63
|
+
str = (properties - [property]).join('|')
|
64
|
+
matcher = content.match(/#{Regexp.escape(property)}([^\n]*?)(#{str}|\n|$)/s)
|
65
|
+
if matcher
|
66
|
+
value = matcher[1].strip
|
67
|
+
property_hash[property.split(':').first] = value
|
68
|
+
end
|
15
69
|
end
|
16
|
-
|
17
|
-
content.flatten!.reject!(&:nil?)
|
18
|
-
|
19
|
-
Hash[*content]
|
70
|
+
property_hash
|
20
71
|
end
|
21
72
|
end
|
22
73
|
end
|
@@ -75,7 +75,10 @@ module Facter
|
|
75
75
|
def search_with_dhcpcd_command(interface_name)
|
76
76
|
@log.debug("Attempt to get DHCP for interface #{interface_name}, from dhcpcd command")
|
77
77
|
|
78
|
-
|
78
|
+
@dhcpcd_command ||= Facter::Core::Execution.which('dhcpcd')
|
79
|
+
return unless @dhcpcd_command
|
80
|
+
|
81
|
+
output = Facter::Core::Execution.execute("#{@dhcpcd_command} -U #{interface_name}", logger: @log)
|
79
82
|
dhcp = output.match(/dhcp_server_identifier='(.*)'/)
|
80
83
|
dhcp[1] if dhcp
|
81
84
|
end
|
@@ -59,8 +59,23 @@ module Facter
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def bond_master_of(interface_name)
|
62
|
-
content =
|
63
|
-
content
|
62
|
+
content = get_ip_link_show_data(interface_name)
|
63
|
+
content&.match(/master (\S*) /)&.captures&.first
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_ip_link_show_data(interface_name)
|
67
|
+
@ip_link_show_data ||= read_ip_link_show_data
|
68
|
+
@ip_link_show_data[interface_name]
|
69
|
+
end
|
70
|
+
|
71
|
+
def read_ip_link_show_data
|
72
|
+
ip_link_show_data = {}
|
73
|
+
output = Facter::Core::Execution.execute('ip -o link show', logger: @log)
|
74
|
+
output.each_line do |line|
|
75
|
+
interface_name = line.split(':')[1]&.strip if line
|
76
|
+
ip_link_show_data[interface_name] = line if interface_name
|
77
|
+
end
|
78
|
+
ip_link_show_data
|
64
79
|
end
|
65
80
|
|
66
81
|
def mac_from(ifaddr)
|
data/lib/facter/version.rb
CHANGED
data/lib/facter.rb
CHANGED
@@ -13,8 +13,6 @@ module Facter
|
|
13
13
|
Options.init
|
14
14
|
Log.output(STDOUT)
|
15
15
|
@already_searched = {}
|
16
|
-
@debug_once = []
|
17
|
-
@warn_once = []
|
18
16
|
|
19
17
|
class << self
|
20
18
|
# Method used by puppet-agent to retrieve facts
|
@@ -109,8 +107,7 @@ module Facter
|
|
109
107
|
# @api public
|
110
108
|
def clear
|
111
109
|
@already_searched = {}
|
112
|
-
|
113
|
-
@warn_once = []
|
110
|
+
Facter.clear_messages
|
114
111
|
LegacyFacter.clear
|
115
112
|
Options[:custom_dir] = []
|
116
113
|
LegacyFacter.collection.invalidate_custom_facts
|
@@ -119,6 +116,13 @@ module Facter
|
|
119
116
|
nil
|
120
117
|
end
|
121
118
|
|
119
|
+
# Clears the seen state of debug and warning messages.
|
120
|
+
#
|
121
|
+
# @return [nil]
|
122
|
+
def clear_messages
|
123
|
+
Facter::Log.clear_messages
|
124
|
+
end
|
125
|
+
|
122
126
|
# Retrieves the value of a core fact. External or custom facts are
|
123
127
|
# not returned with this call. Returns `nil` if no such fact exists.
|
124
128
|
#
|
@@ -153,13 +157,7 @@ module Facter
|
|
153
157
|
#
|
154
158
|
# @api public
|
155
159
|
def debugonce(message)
|
156
|
-
|
157
|
-
|
158
|
-
message_string = message.to_s
|
159
|
-
return if @debug_once.include? message_string
|
160
|
-
|
161
|
-
@debug_once << message_string
|
162
|
-
logger.debug(message_string)
|
160
|
+
logger.debugonce(message)
|
163
161
|
nil
|
164
162
|
end
|
165
163
|
|
@@ -392,7 +390,7 @@ module Facter
|
|
392
390
|
#
|
393
391
|
# @api public
|
394
392
|
def value(user_query)
|
395
|
-
user_query = user_query.to_s
|
393
|
+
user_query = user_query.to_s.downcase
|
396
394
|
resolve_fact(user_query)
|
397
395
|
|
398
396
|
@already_searched[user_query]&.value
|
@@ -409,7 +407,7 @@ module Facter
|
|
409
407
|
#
|
410
408
|
# @api public
|
411
409
|
def fact(user_query)
|
412
|
-
user_query = user_query.to_s
|
410
|
+
user_query = user_query.to_s.downcase
|
413
411
|
resolve_fact(user_query)
|
414
412
|
|
415
413
|
@already_searched[user_query]
|
@@ -482,11 +480,7 @@ module Facter
|
|
482
480
|
#
|
483
481
|
# @api public
|
484
482
|
def warnonce(message)
|
485
|
-
|
486
|
-
return if @warn_once.include? message_string
|
487
|
-
|
488
|
-
@warn_once << message_string
|
489
|
-
logger.warn(message_string)
|
483
|
+
logger.warnonce(message)
|
490
484
|
nil
|
491
485
|
end
|
492
486
|
|
metadata
CHANGED
@@ -1,19 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: facter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.2.
|
4
|
+
version: 4.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '12.3'
|
17
20
|
- - ">="
|
18
21
|
- !ruby/object:Gem::Version
|
19
22
|
version: 12.3.3
|
@@ -21,6 +24,9 @@ dependencies:
|
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '12.3'
|
24
30
|
- - ">="
|
25
31
|
- !ruby/object:Gem::Version
|
26
32
|
version: 12.3.3
|
@@ -108,6 +114,20 @@ dependencies:
|
|
108
114
|
- - "~>"
|
109
115
|
- !ruby/object:Gem::Version
|
110
116
|
version: '1.3'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: timecop
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0.9'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0.9'
|
111
131
|
- !ruby/object:Gem::Dependency
|
112
132
|
name: webmock
|
113
133
|
requirement: !ruby/object:Gem::Requirement
|
@@ -178,6 +198,7 @@ executables:
|
|
178
198
|
extensions: []
|
179
199
|
extra_rdoc_files: []
|
180
200
|
files:
|
201
|
+
- LICENSE
|
181
202
|
- bin/facter
|
182
203
|
- lib/docs/generate.rb
|
183
204
|
- lib/docs/generate_cli.rb
|
@@ -193,7 +214,6 @@ files:
|
|
193
214
|
- lib/facter/custom_facts/core/execution/windows.rb
|
194
215
|
- lib/facter/custom_facts/core/file_loader.rb
|
195
216
|
- lib/facter/custom_facts/core/legacy_facter.rb
|
196
|
-
- lib/facter/custom_facts/core/logging.rb
|
197
217
|
- lib/facter/custom_facts/core/resolvable.rb
|
198
218
|
- lib/facter/custom_facts/core/suitable.rb
|
199
219
|
- lib/facter/custom_facts/util/collection.rb
|
@@ -944,7 +964,7 @@ files:
|
|
944
964
|
- lib/facter/resolvers/macosx/filesystems.rb
|
945
965
|
- lib/facter/resolvers/macosx/load_averages.rb
|
946
966
|
- lib/facter/resolvers/macosx/mountpoints.rb
|
947
|
-
- lib/facter/resolvers/macosx/
|
967
|
+
- lib/facter/resolvers/macosx/processors.rb
|
948
968
|
- lib/facter/resolvers/macosx/swap_memory.rb
|
949
969
|
- lib/facter/resolvers/macosx/system_memory.rb
|
950
970
|
- lib/facter/resolvers/macosx/system_profiler.rb
|
@@ -1051,7 +1071,7 @@ files:
|
|
1051
1071
|
- lib/facter/version.rb
|
1052
1072
|
homepage: https://github.com/puppetlabs/facter
|
1053
1073
|
licenses:
|
1054
|
-
-
|
1074
|
+
- Apache-2.0
|
1055
1075
|
metadata: {}
|
1056
1076
|
post_install_message:
|
1057
1077
|
rdoc_options: []
|
@@ -1,203 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module LegacyFacter
|
4
|
-
module Core
|
5
|
-
module Logging
|
6
|
-
extend self
|
7
|
-
|
8
|
-
# @api private
|
9
|
-
GREEN = "\e[0;32m"
|
10
|
-
# @api private
|
11
|
-
RESET = "\e[0m"
|
12
|
-
|
13
|
-
RED = "\e[31m"
|
14
|
-
|
15
|
-
# @api private
|
16
|
-
@@debug = false
|
17
|
-
# @api private
|
18
|
-
@@timing = false
|
19
|
-
# @api private
|
20
|
-
@@trace = false
|
21
|
-
|
22
|
-
# @api private
|
23
|
-
@@warn_messages = {}
|
24
|
-
# @api private
|
25
|
-
@@debug_messages = {}
|
26
|
-
|
27
|
-
# @api private
|
28
|
-
@@message_callback = nil
|
29
|
-
|
30
|
-
# Used to register a callback that is called when a message is logged.
|
31
|
-
# If a block is given, Facter will not log messages.
|
32
|
-
# If a block is not given, Facter will resume logging messages.
|
33
|
-
# @param block [Proc] the callback to call when a message is logged.
|
34
|
-
# The first argument to the callback will be a symbol representing a level. The supported
|
35
|
-
# levels are: :trace, :debug, :info, :warn, :error, and :fatal.
|
36
|
-
# The second argument to the callback will be a string containing the message
|
37
|
-
# that was logged.
|
38
|
-
# @api public
|
39
|
-
def on_message(&block)
|
40
|
-
@@message_callback = block
|
41
|
-
end
|
42
|
-
|
43
|
-
# Prints a debug message if debugging is turned on
|
44
|
-
#
|
45
|
-
# @param msg [String] the debug message
|
46
|
-
# @return [void]
|
47
|
-
def debug(msg)
|
48
|
-
return unless debugging?
|
49
|
-
|
50
|
-
if msg.nil? || msg.empty?
|
51
|
-
invoker = caller(1..1).first.slice(/.*:\d+/)
|
52
|
-
self.warn "#{self.class}#debug invoked with invalid message #{msg.inspect}:#{msg.class} at #{invoker}"
|
53
|
-
elsif @@message_callback
|
54
|
-
@@message_callback.call(:debug, msg)
|
55
|
-
else
|
56
|
-
puts GREEN + msg + RESET
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# Prints a debug message only once.
|
61
|
-
#
|
62
|
-
# @note Uniqueness is based on the string, not the specific location
|
63
|
-
# of the method call.
|
64
|
-
#
|
65
|
-
# @param msg [String] the debug message
|
66
|
-
# @return [void]
|
67
|
-
def debugonce(msg)
|
68
|
-
return unless msg && !msg.empty? && @@debug_messages[msg].nil?
|
69
|
-
|
70
|
-
@@debug_messages[msg] = true
|
71
|
-
debug(msg)
|
72
|
-
end
|
73
|
-
|
74
|
-
# Prints a warning message. The message is only printed if debugging
|
75
|
-
# is enabled.
|
76
|
-
#
|
77
|
-
# @param msg [String] the warning message to be printed
|
78
|
-
#
|
79
|
-
# @return [void]
|
80
|
-
def warn(msg)
|
81
|
-
if msg.nil? || msg.empty?
|
82
|
-
invoker = caller(1..1).first.slice(/.*:\d+/)
|
83
|
-
msg = "#{self.class}#debug invoked with invalid message #{msg.inspect}:#{msg.class} at #{invoker}"
|
84
|
-
end
|
85
|
-
if @@message_callback
|
86
|
-
@@message_callback.call(:warn, msg)
|
87
|
-
else
|
88
|
-
Kernel.warn msg
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
# Prints a warning message only once per process. Each unique string
|
93
|
-
# is printed once.
|
94
|
-
#
|
95
|
-
# @note Unlike {warn} the message will be printed even if debugging is
|
96
|
-
# not turned on. This behavior is likely to change and should not be
|
97
|
-
# relied on.
|
98
|
-
#
|
99
|
-
# @param msg [String] the warning message to be printed
|
100
|
-
#
|
101
|
-
# @return [void]
|
102
|
-
def warnonce(msg)
|
103
|
-
return unless @@warn_messages[msg].nil?
|
104
|
-
|
105
|
-
self.warn(msg)
|
106
|
-
@@warn_messages[msg] = true
|
107
|
-
end
|
108
|
-
|
109
|
-
def log_exception(exception, message = :default)
|
110
|
-
self.warn(format_exception(exception, message, @@trace))
|
111
|
-
end
|
112
|
-
|
113
|
-
def format_exception(exception, message, trace)
|
114
|
-
arr = []
|
115
|
-
|
116
|
-
if message == :default
|
117
|
-
arr << exception.message
|
118
|
-
elsif message
|
119
|
-
arr << message
|
120
|
-
end
|
121
|
-
|
122
|
-
if trace
|
123
|
-
arr << 'backtrace:'
|
124
|
-
arr.concat(exception.backtrace)
|
125
|
-
end
|
126
|
-
|
127
|
-
"#{RED}#{arr.flatten.join("\n")}#{RESET}"
|
128
|
-
end
|
129
|
-
|
130
|
-
# Print an exception message, and optionally a backtrace if trace is set
|
131
|
-
|
132
|
-
# Print timing information
|
133
|
-
#
|
134
|
-
# @param string [String] the time to print
|
135
|
-
# @return [void]
|
136
|
-
#
|
137
|
-
# @api private
|
138
|
-
def show_time(string)
|
139
|
-
return unless string && timing?
|
140
|
-
|
141
|
-
if @@message_callback
|
142
|
-
@@message_callback.call(:info, string)
|
143
|
-
else
|
144
|
-
$stderr.puts "#{GREEN}#{string}#{RESET}"
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
# Enable or disable logging of debug messages
|
149
|
-
#
|
150
|
-
# @param bool [true, false]
|
151
|
-
# @return [void]
|
152
|
-
#
|
153
|
-
# @api private
|
154
|
-
def debugging(bool)
|
155
|
-
@@debug = bool
|
156
|
-
end
|
157
|
-
|
158
|
-
# Is debugging enabled?
|
159
|
-
#
|
160
|
-
# @return [true, false]
|
161
|
-
#
|
162
|
-
# @api private
|
163
|
-
def debugging?
|
164
|
-
@@debug
|
165
|
-
end
|
166
|
-
|
167
|
-
# Enable or disable logging of timing information
|
168
|
-
#
|
169
|
-
# @param bool [true, false]
|
170
|
-
# @return [void]
|
171
|
-
#
|
172
|
-
# @api private
|
173
|
-
def timing(bool)
|
174
|
-
@@timing = bool
|
175
|
-
end
|
176
|
-
|
177
|
-
# Returns whether timing output is turned on
|
178
|
-
#
|
179
|
-
# @api private
|
180
|
-
def timing?
|
181
|
-
@@timing
|
182
|
-
end
|
183
|
-
|
184
|
-
def trace(bool)
|
185
|
-
@@trace = bool
|
186
|
-
end
|
187
|
-
|
188
|
-
def trace?
|
189
|
-
@@trace
|
190
|
-
end
|
191
|
-
|
192
|
-
# Clears the seen state of debug and warning messages. See {debugonce} and {warnonce}.
|
193
|
-
#
|
194
|
-
# @return [void]
|
195
|
-
#
|
196
|
-
# @api private
|
197
|
-
def clear_messages
|
198
|
-
@@debug_messages.clear
|
199
|
-
@@warn_messages.clear
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|