facter 4.0.40 → 4.0.46
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/facter.rb +72 -19
- data/lib/facter/config.rb +355 -0
- data/lib/facter/custom_facts/core/aggregate.rb +51 -17
- data/lib/facter/custom_facts/core/execution.rb +54 -38
- data/lib/facter/custom_facts/core/execution/base.rb +46 -40
- data/lib/facter/custom_facts/util/fact.rb +1 -1
- data/lib/facter/custom_facts/util/parser.rb +17 -3
- data/lib/facter/custom_facts/util/resolution.rb +40 -11
- data/lib/facter/facts/linux/ec2_metadata.rb +5 -30
- data/lib/facter/facts/linux/ec2_userdata.rb +5 -28
- data/lib/facter/facts/linux/is_virtual.rb +7 -46
- data/lib/facter/facts/linux/virtual.rb +3 -58
- data/lib/facter/facts/rhel/os/release.rb +1 -1
- data/lib/facter/facts/solaris/hypervisors/ldom.rb +3 -0
- data/lib/facter/facts/solaris/ldom.rb +4 -1
- data/lib/facter/facts/solaris/zones.rb +1 -1
- data/lib/facter/facts_utils/virtual_detector.rb +78 -0
- data/lib/facter/framework/benchmarking/timer.rb +4 -2
- data/lib/facter/framework/cli/cli.rb +19 -5
- data/lib/facter/framework/config/fact_groups.rb +10 -8
- data/lib/facter/framework/core/cache_manager.rb +78 -28
- data/lib/facter/framework/core/fact/internal/core_fact.rb +6 -1
- data/lib/facter/framework/core/fact/internal/internal_fact_manager.rb +38 -4
- data/lib/facter/framework/core/fact_augmenter.rb +1 -1
- data/lib/facter/framework/core/fact_loaders/fact_loader.rb +1 -1
- data/lib/facter/framework/core/fact_manager.rb +1 -1
- data/lib/facter/framework/core/options/config_file_options.rb +16 -5
- data/lib/facter/framework/core/options/option_store.rb +40 -20
- data/lib/facter/framework/detector/os_hierarchy.rb +5 -9
- data/lib/facter/resolvers/aio_agent_version.rb +1 -1
- data/lib/facter/resolvers/aix/architecture_resolver.rb +17 -2
- data/lib/facter/resolvers/aix/disks.rb +2 -1
- data/lib/facter/resolvers/aix/filesystem_resolver.rb +1 -1
- data/lib/facter/resolvers/aix/hardware_resolver.rb +2 -1
- data/lib/facter/resolvers/aix/load_averages_resolver.rb +2 -1
- data/lib/facter/resolvers/aix/memory.rb +2 -1
- data/lib/facter/resolvers/aix/mountpoints.rb +2 -1
- data/lib/facter/resolvers/aix/networking_resolver.rb +1 -1
- data/lib/facter/resolvers/aix/nim.rb +1 -1
- data/lib/facter/resolvers/aix/os_level.rb +2 -2
- data/lib/facter/resolvers/aix/partitions.rb +2 -1
- data/lib/facter/resolvers/aix/processors.rb +2 -1
- data/lib/facter/resolvers/aix/serialnumber.rb +1 -1
- data/lib/facter/resolvers/augeas_resolver.rb +8 -2
- data/lib/facter/resolvers/base_resolver.rb +11 -4
- data/lib/facter/resolvers/bsd/processors.rb +13 -8
- data/lib/facter/resolvers/cloud.rb +1 -1
- data/lib/facter/resolvers/containers.rb +2 -1
- data/lib/facter/resolvers/debian_version.rb +1 -1
- data/lib/facter/resolvers/disk_resolver.rb +15 -4
- data/lib/facter/resolvers/dmi_decode.rb +2 -1
- data/lib/facter/resolvers/dmi_resolver.rb +4 -3
- data/lib/facter/resolvers/ec2.rb +2 -1
- data/lib/facter/resolvers/eos_release_resolver.rb +1 -1
- data/lib/facter/resolvers/facterversion_resolver.rb +1 -1
- data/lib/facter/resolvers/filesystems_resolver.rb +4 -1
- data/lib/facter/resolvers/fips_enabled_resolver.rb +4 -1
- data/lib/facter/resolvers/freebsd/dmi_resolver.rb +1 -1
- data/lib/facter/resolvers/freebsd/freebsd_version_resolver.rb +9 -7
- data/lib/facter/resolvers/freebsd/geom_resolver.rb +14 -21
- data/lib/facter/resolvers/freebsd/processors.rb +13 -8
- data/lib/facter/resolvers/freebsd/swap_memory_resolver.rb +2 -1
- data/lib/facter/resolvers/freebsd/system_memory_resolver.rb +2 -1
- data/lib/facter/resolvers/gce.rb +2 -1
- data/lib/facter/resolvers/hostname_resolver.rb +2 -1
- data/lib/facter/resolvers/identity_resolver.rb +2 -1
- data/lib/facter/resolvers/linux/docker_uptime.rb +2 -1
- data/lib/facter/resolvers/linux/load_averages.rb +2 -1
- data/lib/facter/resolvers/load_averages.rb +2 -1
- data/lib/facter/resolvers/lpar_resolver.rb +1 -1
- data/lib/facter/resolvers/lsb_release_resolver.rb +1 -1
- data/lib/facter/resolvers/lspci.rb +1 -1
- data/lib/facter/resolvers/macosx/dmi_resolver.rb +1 -1
- data/lib/facter/resolvers/macosx/filesystems_resolver.rb +1 -1
- data/lib/facter/resolvers/macosx/load_averages_resolver.rb +2 -1
- data/lib/facter/resolvers/macosx/mountpoints_resolver.rb +2 -1
- data/lib/facter/resolvers/macosx/processor_resolver.rb +2 -1
- data/lib/facter/resolvers/macosx/swap_memory_resolver.rb +2 -1
- data/lib/facter/resolvers/macosx/system_memory_resolver.rb +2 -1
- data/lib/facter/resolvers/macosx/system_profiler_resolver.rb +1 -3
- data/lib/facter/resolvers/memory_resolver.rb +15 -15
- data/lib/facter/resolvers/mountpoints_resolver.rb +54 -23
- data/lib/facter/resolvers/networking_linux_resolver.rb +15 -9
- data/lib/facter/resolvers/networking_resolver.rb +1 -1
- data/lib/facter/resolvers/open_vz.rb +1 -1
- data/lib/facter/resolvers/os_release_resolver.rb +1 -1
- data/lib/facter/resolvers/partitions.rb +62 -58
- data/lib/facter/resolvers/path_resolver.rb +1 -1
- data/lib/facter/resolvers/processors_resolver.rb +9 -2
- data/lib/facter/resolvers/puppet_version_resolver.rb +1 -1
- data/lib/facter/resolvers/redhat_release_resolver.rb +1 -1
- data/lib/facter/resolvers/ruby_resolver.rb +1 -1
- data/lib/facter/resolvers/selinux_resolver.rb +1 -1
- data/lib/facter/resolvers/solaris/disks.rb +1 -1
- data/lib/facter/resolvers/solaris/dmi.rb +3 -1
- data/lib/facter/resolvers/solaris/dmi_sparc.rb +1 -1
- data/lib/facter/resolvers/solaris/filesystems.rb +1 -1
- data/lib/facter/resolvers/solaris/ipaddress.rb +2 -1
- data/lib/facter/resolvers/solaris/ldom.rb +1 -3
- data/lib/facter/resolvers/solaris/memory.rb +2 -1
- data/lib/facter/resolvers/solaris/mountpoints.rb +60 -0
- data/lib/facter/resolvers/solaris/networking.rb +2 -3
- data/lib/facter/resolvers/solaris/os_release.rb +6 -4
- data/lib/facter/resolvers/solaris/processors.rb +2 -1
- data/lib/facter/resolvers/solaris/zone.rb +1 -1
- data/lib/facter/resolvers/solaris/zone_name.rb +1 -1
- data/lib/facter/resolvers/ssh_resolver.rb +8 -5
- data/lib/facter/resolvers/suse_release_resolver.rb +1 -1
- data/lib/facter/resolvers/sw_vers_resolver.rb +2 -2
- data/lib/facter/resolvers/timezone_resolver.rb +1 -1
- data/lib/facter/resolvers/uname_resolver.rb +1 -1
- data/lib/facter/resolvers/uptime_resolver.rb +1 -1
- data/lib/facter/resolvers/utils/networking.rb +2 -0
- data/lib/facter/resolvers/virt_what.rb +1 -1
- data/lib/facter/resolvers/vmware.rb +1 -1
- data/lib/facter/resolvers/windows/aio_agent_version.rb +1 -1
- data/lib/facter/resolvers/windows/dmi_bios_resolver.rb +1 -1
- data/lib/facter/resolvers/windows/dmi_computersystem_resolver.rb +1 -1
- data/lib/facter/resolvers/windows/fips_resolver.rb +2 -1
- data/lib/facter/resolvers/windows/hardware_architecture_resolver.rb +2 -1
- data/lib/facter/resolvers/windows/identity_resolver.rb +2 -1
- data/lib/facter/resolvers/windows/kernel_resolver.rb +3 -1
- data/lib/facter/resolvers/windows/memory_resolver.rb +3 -1
- data/lib/facter/resolvers/windows/netkvm_resolver.rb +2 -1
- data/lib/facter/resolvers/windows/networking_resolver.rb +2 -1
- data/lib/facter/resolvers/windows/processors_resolver.rb +2 -1
- data/lib/facter/resolvers/windows/product_release_resolver.rb +2 -1
- data/lib/facter/resolvers/windows/ssh.rb +3 -1
- data/lib/facter/resolvers/windows/system32_resolver.rb +3 -1
- data/lib/facter/resolvers/windows/uptime_resolver.rb +2 -1
- data/lib/facter/resolvers/windows/virtualization_resolver.rb +2 -1
- data/lib/facter/resolvers/windows/win_os_description_resolver.rb +3 -1
- data/lib/facter/resolvers/wpar_resolver.rb +1 -1
- data/lib/facter/resolvers/xen.rb +1 -1
- data/lib/facter/resolvers/zfs.rb +2 -1
- data/lib/facter/resolvers/zpool.rb +2 -1
- data/lib/facter/version.rb +1 -1
- metadata +7 -5
- data/lib/facter/fact_groups.conf +0 -308
- data/lib/facter/os_hierarchy.json +0 -36
@@ -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
|
-
#
|
35
|
-
#
|
36
|
-
# Returns nil if no matching executable can be found otherwise returns
|
37
|
-
# the expanded pathname.
|
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
|
38
33
|
#
|
39
|
-
# @
|
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,26 +96,49 @@ 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 command
|
109
102
|
#
|
110
|
-
#
|
103
|
+
# Options accepted values :on_fail How to behave when the command could
|
111
104
|
# not be run. Specifying :raise will raise an error, anything else will
|
112
105
|
# return that object on failure. Default is :raise.
|
106
|
+
# :logger Optional logger used to log the command's stderr.
|
107
|
+
# :time_limit Optional time out for the specified command. If no time_limit is passed,
|
108
|
+
# a default of 300 seconds is used.
|
113
109
|
#
|
114
110
|
# @raise [Facter::Core::Execution::ExecutionFailure] If the command does
|
115
|
-
# not exist or could not be executed
|
111
|
+
# not exist or could not be executed and :on_fail is set to :raise
|
116
112
|
#
|
117
|
-
# @return [String] the output of the program, or the value of :on_fail if
|
113
|
+
# @return [String] the output of the program, or the value of :on_fail (if it's different than :raise) if
|
118
114
|
# command execution failed and :on_fail was specified.
|
119
115
|
#
|
120
116
|
# @api public
|
121
|
-
# @since 2.0.1
|
122
117
|
def execute(command, options = {})
|
123
118
|
@@impl.execute(command, options)
|
124
119
|
end
|
125
120
|
|
121
|
+
# Execute a command and return the stdout and stderr of that program.
|
122
|
+
# @param command [String] Command to run
|
123
|
+
#
|
124
|
+
# @param on_fail[Object] How to behave when the command could
|
125
|
+
# not be run. Specifying :raise will raise an error, anything else will
|
126
|
+
# return that object on failure. Default is :raise.
|
127
|
+
# @param logger Optional logger used to log the command's stderr.
|
128
|
+
# @param time_limit Optional time out for the specified command. If no time_limit is passed,
|
129
|
+
# a default of 300 seconds is used.
|
130
|
+
#
|
131
|
+
# @raise [Facter::Core::Execution::ExecutionFailure] If the command does
|
132
|
+
# not exist or could not be executed and :on_fail is set to :raise
|
133
|
+
#
|
134
|
+
# @return [String, String] the stdout and stderr of the program, or the value of
|
135
|
+
# :on_fail if command execution failed and :on_fail was specified.
|
136
|
+
#
|
137
|
+
# @api private
|
138
|
+
def execute_command(command, on_fail = nil, logger = nil, time_limit = nil)
|
139
|
+
@@impl.execute_command(command, on_fail, logger, time_limit)
|
140
|
+
end
|
141
|
+
|
126
142
|
class ExecutionFailure < StandardError; end
|
127
143
|
end
|
128
144
|
end
|
@@ -4,7 +4,7 @@ module Facter
|
|
4
4
|
module Core
|
5
5
|
module Execution
|
6
6
|
class Base
|
7
|
-
STDERR_MESSAGE = 'Command %s
|
7
|
+
STDERR_MESSAGE = 'Command %s completed with the following stderr message: %s'
|
8
8
|
|
9
9
|
def initialize
|
10
10
|
@log = Log.new(self)
|
@@ -57,40 +57,12 @@ module Facter
|
|
57
57
|
return on_fail
|
58
58
|
end
|
59
59
|
|
60
|
-
execute_command(expanded_command, on_fail, logger, time_limit)
|
60
|
+
out, = execute_command(expanded_command, on_fail, logger, time_limit)
|
61
|
+
out
|
61
62
|
end
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
def extract_options(options)
|
66
|
-
on_fail = options.fetch(:on_fail, :raise)
|
67
|
-
expand = options.fetch(:expand, true)
|
68
|
-
logger = options[:logger]
|
69
|
-
time_limit = options[:limit].to_i
|
70
|
-
time_limit = time_limit.positive? ? time_limit : nil
|
71
|
-
|
72
|
-
[on_fail, expand, logger, time_limit]
|
73
|
-
end
|
74
|
-
|
75
|
-
def log_stderr(msg, command, logger)
|
76
|
-
return if !msg || msg.empty?
|
77
|
-
|
78
|
-
if logger
|
79
|
-
logger.debug(format(STDERR_MESSAGE, command, msg.strip))
|
80
|
-
else
|
81
|
-
file_name = command.split('/').last
|
82
|
-
logger = Facter::Log.new(file_name)
|
83
|
-
logger.warn(format(STDERR_MESSAGE, command, msg.strip))
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def builtin_command?(command)
|
88
|
-
output, _status = Open3.capture2("type #{command}")
|
89
|
-
output.chomp =~ /builtin/ ? true : false
|
90
|
-
end
|
91
|
-
|
92
|
-
def execute_command(command, on_fail, logger = nil, time_limit = nil)
|
93
|
-
time_limit ||= 1.5
|
64
|
+
def execute_command(command, on_fail = nil, logger = nil, time_limit = nil)
|
65
|
+
time_limit ||= 300
|
94
66
|
begin
|
95
67
|
# Set LC_ALL and LANG to force i18n to C for the duration of this exec;
|
96
68
|
# this ensures that any code that parses the
|
@@ -100,18 +72,24 @@ module Facter
|
|
100
72
|
@log.debug("Executing command: #{command}")
|
101
73
|
out, stderr = Open3.popen3(opts, command.to_s) do |_, stdout, stderr, wait_thr|
|
102
74
|
pid = wait_thr.pid
|
103
|
-
|
104
|
-
|
75
|
+
stdout_messages = +''
|
76
|
+
stderr_messages = +''
|
77
|
+
out_reader = Thread.new { stdout.read }
|
78
|
+
err_reader = Thread.new { stderr.read }
|
105
79
|
begin
|
106
80
|
Timeout.timeout(time_limit) do
|
107
|
-
|
108
|
-
|
81
|
+
stdout_messages << out_reader.value
|
82
|
+
stderr_messages << err_reader.value
|
109
83
|
end
|
110
84
|
rescue Timeout::Error
|
111
|
-
|
85
|
+
message = "Timeout encounter after #{time_limit}s, killing process with pid: #{pid}"
|
112
86
|
Process.kill('KILL', pid)
|
87
|
+
on_fail == :raise ? (raise StandardError, message) : @log.debug(message)
|
88
|
+
ensure
|
89
|
+
out_reader.kill
|
90
|
+
err_reader.kill
|
113
91
|
end
|
114
|
-
[
|
92
|
+
[stdout_messages, stderr_messages]
|
115
93
|
end
|
116
94
|
log_stderr(stderr, command, logger)
|
117
95
|
rescue StandardError => e
|
@@ -122,7 +100,35 @@ module Facter
|
|
122
100
|
"Failed while executing '#{command}': #{e.message}"
|
123
101
|
end
|
124
102
|
|
125
|
-
out.strip
|
103
|
+
[out.strip, stderr]
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def extract_options(options)
|
109
|
+
on_fail = options.fetch(:on_fail, :raise)
|
110
|
+
expand = options.fetch(:expand, true)
|
111
|
+
logger = options[:logger]
|
112
|
+
time_limit = options[:limit].to_i
|
113
|
+
time_limit = time_limit.positive? ? time_limit : nil
|
114
|
+
|
115
|
+
[on_fail, expand, logger, time_limit]
|
116
|
+
end
|
117
|
+
|
118
|
+
def log_stderr(msg, command, logger)
|
119
|
+
return if !msg || msg.empty?
|
120
|
+
|
121
|
+
unless logger
|
122
|
+
file_name = command.split('/').last
|
123
|
+
logger = Facter::Log.new(file_name)
|
124
|
+
end
|
125
|
+
|
126
|
+
logger.debug(format(STDERR_MESSAGE, command, msg.strip))
|
127
|
+
end
|
128
|
+
|
129
|
+
def builtin_command?(command)
|
130
|
+
output, _status = Open3.capture2("type #{command}")
|
131
|
+
output.chomp =~ /builtin/ ? true : false
|
126
132
|
end
|
127
133
|
end
|
128
134
|
end
|
@@ -155,7 +155,7 @@ module Facter
|
|
155
155
|
@searching
|
156
156
|
end
|
157
157
|
|
158
|
-
# Lock our searching process, so we never
|
158
|
+
# Lock our searching process, so we never get stuck in recursion.
|
159
159
|
def searching
|
160
160
|
raise "Caught recursion on #{@name}" if searching?
|
161
161
|
|
@@ -8,6 +8,8 @@
|
|
8
8
|
module LegacyFacter
|
9
9
|
module Util
|
10
10
|
module Parser
|
11
|
+
STDERR_MESSAGE = 'Command %s completed with the following stderr message: %s'
|
12
|
+
|
11
13
|
@parsers = []
|
12
14
|
|
13
15
|
# For support mutliple extensions you can pass an array of extensions as
|
@@ -75,6 +77,15 @@ module LegacyFacter
|
|
75
77
|
res = KeyValuePairOutputFormat.parse output unless res.is_a?(Hash)
|
76
78
|
res
|
77
79
|
end
|
80
|
+
|
81
|
+
def log_stderr(msg, command, file)
|
82
|
+
return if !msg || msg.empty?
|
83
|
+
|
84
|
+
file_name = file.split('/').last
|
85
|
+
logger = Facter::Log.new(file_name)
|
86
|
+
|
87
|
+
logger.warn(format(STDERR_MESSAGE, command, msg.strip))
|
88
|
+
end
|
78
89
|
end
|
79
90
|
|
80
91
|
module KeyValuePairOutputFormat
|
@@ -139,7 +150,9 @@ module LegacyFacter
|
|
139
150
|
|
140
151
|
class ScriptParser < Base
|
141
152
|
def parse_results
|
142
|
-
|
153
|
+
stdout, stderr = Facter::Core::Execution.execute_command(quote(filename))
|
154
|
+
log_stderr(stderr, filename, filename)
|
155
|
+
parse_executable_output(stdout)
|
143
156
|
end
|
144
157
|
|
145
158
|
private
|
@@ -172,8 +185,9 @@ module LegacyFacter
|
|
172
185
|
|
173
186
|
shell_command =
|
174
187
|
"\"#{powershell}\" -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -File \"#{filename}\""
|
175
|
-
|
176
|
-
|
188
|
+
stdout, stderr = Facter::Core::Execution.execute_command(shell_command)
|
189
|
+
log_stderr(stderr, shell_command, filename)
|
190
|
+
parse_executable_output(stdout)
|
177
191
|
end
|
178
192
|
end
|
179
193
|
|