facter 4.0.15 → 4.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +5 -7
- data/CHANGELOG.md +33 -0
- data/VERSION +1 -1
- data/lib/custom_facts/util/parser.rb +1 -1
- data/lib/custom_facts/version.rb +1 -1
- data/lib/facter.rb +13 -17
- data/lib/facts/aix/partitions.rb +15 -0
- data/lib/facts/windows/ssh.rb +27 -0
- data/lib/facts_utils/uptime_parser.rb +3 -3
- data/lib/framework/cli/cli.rb +1 -1
- data/lib/framework/config/block_list.rb +1 -4
- data/lib/framework/config/config_reader.rb +29 -26
- data/lib/framework/core/fact_filter.rb +2 -2
- data/lib/framework/core/file_loader.rb +3 -3
- data/lib/framework/core/options.rb +57 -64
- data/lib/framework/core/options/config_file_options.rb +58 -48
- data/lib/framework/core/options/option_store.rb +156 -0
- data/lib/framework/core/options/options_validator.rb +42 -2
- data/lib/framework/logging/logger.rb +2 -0
- data/lib/framework/parsers/query_parser.rb +1 -1
- data/lib/models/fact_collection.rb +1 -1
- data/lib/resolvers/aix/filesystem_resolver.rb +3 -2
- data/lib/resolvers/aix/partitions.rb +86 -0
- data/lib/resolvers/aix/utils/odm_query.rb +2 -2
- data/lib/resolvers/debian_version.rb +2 -5
- data/lib/resolvers/disk_resolver.rb +2 -3
- data/lib/resolvers/dmi_resolver.rb +3 -3
- data/lib/resolvers/filesystems_resolver.rb +3 -3
- data/lib/resolvers/fips_enabled_resolver.rb +1 -4
- data/lib/resolvers/hostname_resolver.rb +4 -4
- data/lib/resolvers/load_averages_resolver.rb +1 -3
- data/lib/resolvers/memory_resolver.rb +2 -2
- data/lib/resolvers/mountpoints_resolver.rb +1 -3
- data/lib/resolvers/os_release_resolver.rb +3 -6
- data/lib/resolvers/partitions.rb +11 -6
- data/lib/resolvers/processors_resolver.rb +3 -3
- data/lib/resolvers/selinux_resolver.rb +9 -9
- data/lib/resolvers/solaris/filesystems_resolver.rb +1 -1
- data/lib/resolvers/ssh_resolver.rb +4 -43
- data/lib/resolvers/utils/ssh_helper.rb +27 -0
- data/lib/resolvers/windows/ssh.rb +47 -0
- data/lib/util/file_helper.rb +24 -0
- metadata +9 -6
- data/lib/framework/core/options/default_options.rb +0 -35
- data/lib/framework/core/options/helper_options.rb +0 -52
- data/lib/framework/core/options/priority_options.rb +0 -12
- data/lib/framework/core/options/validate_options.rb +0 -49
@@ -1,71 +1,81 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Facter
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
class ConfigFileOptions
|
5
|
+
class << self
|
6
|
+
def init(config_path = nil)
|
7
|
+
@options = {}
|
8
|
+
Facter::ConfigReader.init(config_path)
|
9
|
+
|
10
|
+
augment_config_path(config_path)
|
11
|
+
|
12
|
+
if Options.cli?
|
13
|
+
augment_cli(Facter::ConfigReader.cli)
|
14
|
+
augment_ruby(Facter::ConfigReader.global)
|
15
|
+
end
|
16
|
+
augment_custom(Facter::ConfigReader.global)
|
17
|
+
augment_external(Facter::ConfigReader.global)
|
18
|
+
augment_show_legacy(Facter::ConfigReader.global)
|
19
|
+
augment_facts(Facter::ConfigReader.ttls)
|
20
|
+
end
|
21
|
+
|
22
|
+
def get
|
23
|
+
@options || {}
|
12
24
|
end
|
13
|
-
augment_custom(conf_reader.global)
|
14
|
-
augment_external(conf_reader.global)
|
15
|
-
augment_show_legacy(conf_reader.global)
|
16
|
-
augment_facts(conf_reader.ttls)
|
17
|
-
end
|
18
25
|
|
19
|
-
|
26
|
+
private
|
20
27
|
|
21
|
-
|
22
|
-
|
23
|
-
|
28
|
+
def augment_config_path(config_path)
|
29
|
+
@options[:config] = config_path
|
30
|
+
end
|
24
31
|
|
25
|
-
|
26
|
-
|
32
|
+
def augment_cli(file_cli_conf)
|
33
|
+
return unless file_cli_conf
|
27
34
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
35
|
+
@options[:debug] = file_cli_conf['debug'] unless file_cli_conf['debug'].nil?
|
36
|
+
@options[:trace] = file_cli_conf['trace'] unless file_cli_conf['trace'].nil?
|
37
|
+
@options[:verbose] = file_cli_conf['verbose'] unless file_cli_conf['verbose'].nil?
|
38
|
+
@options[:log_level] = file_cli_conf['log-level'].to_sym unless file_cli_conf['log-level'].nil?
|
39
|
+
end
|
40
|
+
|
41
|
+
def augment_custom(file_global_conf)
|
42
|
+
return unless file_global_conf
|
33
43
|
|
34
|
-
|
35
|
-
|
44
|
+
if Options.cli?
|
45
|
+
@options[:custom_facts] = !file_global_conf['no-custom-facts'] unless file_global_conf['no-custom-facts'].nil?
|
46
|
+
end
|
36
47
|
|
37
|
-
|
38
|
-
@options[:custom_facts] = !file_global_conf['no-custom-facts'] unless file_global_conf['no-custom-facts'].nil?
|
48
|
+
@options[:custom_dir] = file_global_conf['custom-dir'] unless file_global_conf['custom-dir'].nil?
|
39
49
|
end
|
40
|
-
@options[:custom_dir] = [file_global_conf['custom-dir']].flatten unless file_global_conf['custom-dir'].nil?
|
41
|
-
end
|
42
50
|
|
43
|
-
|
44
|
-
|
51
|
+
def augment_external(global_conf)
|
52
|
+
return unless global_conf
|
53
|
+
|
54
|
+
if Options.cli?
|
55
|
+
@options[:external_facts] = !global_conf['no-external-facts'] unless global_conf['no-external-facts'].nil?
|
56
|
+
end
|
45
57
|
|
46
|
-
|
47
|
-
@options[:external_facts] = !global_conf['no-external-facts'] unless global_conf['no-external-facts'].nil?
|
58
|
+
@options[:external_dir] = [global_conf['external-dir']].flatten unless global_conf['external-dir'].nil?
|
48
59
|
end
|
49
|
-
@options[:external_dir] = [global_conf['external-dir']].flatten unless global_conf['external-dir'].nil?
|
50
|
-
end
|
51
60
|
|
52
|
-
|
53
|
-
|
61
|
+
def augment_ruby(global_conf)
|
62
|
+
return unless global_conf
|
54
63
|
|
55
|
-
|
56
|
-
|
64
|
+
@options[:ruby] = global_conf['no-ruby'].nil? ? true : !global_conf['no-ruby']
|
65
|
+
end
|
57
66
|
|
58
|
-
|
59
|
-
|
67
|
+
def augment_show_legacy(global_conf)
|
68
|
+
return unless global_conf
|
60
69
|
|
61
|
-
|
62
|
-
|
70
|
+
@options[:show_legacy] = global_conf['show-legacy'] unless global_conf['show-legacy'].nil?
|
71
|
+
end
|
63
72
|
|
64
|
-
|
65
|
-
|
66
|
-
|
73
|
+
def augment_facts(ttls)
|
74
|
+
blocked_facts = Facter::BlockList.new.blocked_facts
|
75
|
+
@options[:blocked_facts] = blocked_facts unless blocked_facts.nil?
|
67
76
|
|
68
|
-
|
77
|
+
@options[:ttls] = ttls unless ttls.nil?
|
78
|
+
end
|
69
79
|
end
|
70
80
|
end
|
71
81
|
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Facter
|
4
|
+
class OptionStore
|
5
|
+
# default options
|
6
|
+
@debug = false
|
7
|
+
@trace = false
|
8
|
+
@verbose = false
|
9
|
+
# TODO: constant is not yet available when running puppet facts
|
10
|
+
@log_level = :warn
|
11
|
+
@show_legacy = true
|
12
|
+
@block = true
|
13
|
+
@custom_dir = []
|
14
|
+
@custom_facts = true
|
15
|
+
@external_dir = []
|
16
|
+
@external_facts = true
|
17
|
+
@ruby = true
|
18
|
+
@blocked_facts = []
|
19
|
+
@user_query = []
|
20
|
+
|
21
|
+
class << self
|
22
|
+
attr_reader :debug, :verbose, :log_level, :show_legacy, :trace,
|
23
|
+
:custom_dir, :external_dir, :ruby,
|
24
|
+
:custom_facts, :blocked_facts
|
25
|
+
|
26
|
+
attr_accessor :config, :user_query, :strict, :json, :haml, :external_facts,
|
27
|
+
:cache, :yaml, :puppet, :ttls, :block, :cli
|
28
|
+
|
29
|
+
def all
|
30
|
+
options = {}
|
31
|
+
instance_variables.each do |iv|
|
32
|
+
variable_name = iv.to_s.delete('@')
|
33
|
+
options[variable_name.to_sym] = OptionStore.send(variable_name.to_sym)
|
34
|
+
end
|
35
|
+
options
|
36
|
+
end
|
37
|
+
|
38
|
+
def ruby=(bool)
|
39
|
+
if bool == true
|
40
|
+
@ruby = true
|
41
|
+
else
|
42
|
+
@ruby = false
|
43
|
+
@custom_facts = false
|
44
|
+
@blocked_facts << 'ruby'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def external_dir=(dirs)
|
49
|
+
return unless dirs.any?
|
50
|
+
|
51
|
+
@external_dir = dirs
|
52
|
+
end
|
53
|
+
|
54
|
+
def blocked_facts=(*facts)
|
55
|
+
@blocked_facts += [*facts]
|
56
|
+
|
57
|
+
@blocked_facts.flatten!
|
58
|
+
end
|
59
|
+
|
60
|
+
def custom_dir=(*dirs)
|
61
|
+
return unless dirs.any?
|
62
|
+
|
63
|
+
@ruby = true
|
64
|
+
|
65
|
+
@custom_dir = [*dirs]
|
66
|
+
@custom_dir.flatten!
|
67
|
+
end
|
68
|
+
|
69
|
+
def debug=(bool)
|
70
|
+
if bool == true
|
71
|
+
self.log_level = :debug
|
72
|
+
else
|
73
|
+
@debug = false
|
74
|
+
self.log_level = Facter::DEFAULT_LOG_LEVEL
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def verbose=(bool)
|
79
|
+
if bool == true
|
80
|
+
@verbose = true
|
81
|
+
self.log_level = :info
|
82
|
+
else
|
83
|
+
@verbose = false
|
84
|
+
self.log_level = Facter::DEFAULT_LOG_LEVEL
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def custom_facts=(bool)
|
89
|
+
if bool == true
|
90
|
+
@custom_facts = true
|
91
|
+
@ruby = true
|
92
|
+
else
|
93
|
+
@custom_facts = false
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def log_level=(level)
|
98
|
+
level = level.to_sym
|
99
|
+
case level
|
100
|
+
when :trace
|
101
|
+
@log_level = :debug
|
102
|
+
@trace = true
|
103
|
+
when :debug
|
104
|
+
@log_level = :debug
|
105
|
+
@debug = true
|
106
|
+
else
|
107
|
+
@log_level = level
|
108
|
+
end
|
109
|
+
|
110
|
+
Facter::Log.level = @log_level
|
111
|
+
Facter.trace(@trace)
|
112
|
+
end
|
113
|
+
|
114
|
+
def show_legacy=(bool)
|
115
|
+
if bool == true
|
116
|
+
@show_legacy = bool
|
117
|
+
@ruby = true
|
118
|
+
else
|
119
|
+
@show_legacy = false
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def trace=(bool)
|
124
|
+
if bool == true
|
125
|
+
self.log_level = :trace
|
126
|
+
else
|
127
|
+
@log_level = Facter::DEFAULT_LOG_LEVEL
|
128
|
+
@trace = false
|
129
|
+
Facter.trace(false)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def set(key, value)
|
134
|
+
send("#{key}=".to_sym, value)
|
135
|
+
end
|
136
|
+
|
137
|
+
def reset
|
138
|
+
@debug = false
|
139
|
+
@trace = false
|
140
|
+
@verbose = false
|
141
|
+
# TODO: constant is not yet available when running puppet facts
|
142
|
+
@log_level = :warn
|
143
|
+
@show_legacy = true
|
144
|
+
@block = true
|
145
|
+
@custom_dir = []
|
146
|
+
@custom_facts = true
|
147
|
+
@external_dir = []
|
148
|
+
@external_facts = true
|
149
|
+
@ruby = true
|
150
|
+
@blocked_facts = []
|
151
|
+
@user_query = []
|
152
|
+
@cli = nil
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
@@ -33,11 +33,51 @@ module Facter
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def self.write_error_and_exit(message)
|
36
|
-
Options.augment_with_priority_options!(is_cli: true)
|
37
36
|
log = Facter::Log.new(self)
|
38
37
|
log.error(message, true)
|
39
|
-
Cli.start(['--help'])
|
38
|
+
Facter::Cli.start(['--help'])
|
39
|
+
|
40
40
|
exit 1
|
41
41
|
end
|
42
|
+
|
43
|
+
def self.validate_configs(options)
|
44
|
+
conflicting_configs(options).each do |op|
|
45
|
+
next unless op.values[0] && op.values[1]
|
46
|
+
|
47
|
+
message = "#{op.keys[0]} and #{op.keys[1]} options conflict: please specify only one"
|
48
|
+
write_error_and_exit(message)
|
49
|
+
end
|
50
|
+
validate_log_options(options)
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.conflicting_configs(options)
|
54
|
+
no_ruby = !options[:ruby]
|
55
|
+
no_custom_facts = !options[:custom_facts]
|
56
|
+
puppet = options[:puppet]
|
57
|
+
custom_dir = options[:custom_dir].nil? ? false : options[:custom_dir].any?
|
58
|
+
external_dir = options[:external_dir].nil? ? false : options[:external_dir].any?
|
59
|
+
|
60
|
+
[
|
61
|
+
{ 'no-ruby' => no_ruby, 'custom-dir' => custom_dir },
|
62
|
+
{ 'no-external-facts' => !options[:external_facts], 'external-dir' => external_dir },
|
63
|
+
{ 'no-custom-facts' => no_custom_facts, 'custom-dir' => custom_dir },
|
64
|
+
{ 'no-ruby' => no_ruby, 'puppet' => puppet },
|
65
|
+
{ 'no-custom-facts' => no_custom_facts, 'puppet' => puppet }
|
66
|
+
]
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.validate_log_options(options)
|
70
|
+
# TODO: find a better way to do this
|
71
|
+
return if options[:debug] == true && options[:log_level] == :debug
|
72
|
+
return if options[:verbose] == true && options[:log_level] == :info
|
73
|
+
|
74
|
+
return unless [options[:debug],
|
75
|
+
options[:verbose],
|
76
|
+
options[:log_level] != Facter::DEFAULT_LOG_LEVEL]
|
77
|
+
.count(true) > 1
|
78
|
+
|
79
|
+
message = 'debug, verbose, and log-level options conflict: please specify only one.'
|
80
|
+
write_error_and_exit(message)
|
81
|
+
end
|
42
82
|
end
|
43
83
|
end
|
@@ -4,6 +4,7 @@ require 'logger'
|
|
4
4
|
|
5
5
|
module Facter
|
6
6
|
RED = 31
|
7
|
+
DEFAULT_LOG_LEVEL = :warn
|
7
8
|
|
8
9
|
class Log
|
9
10
|
@@legacy_logger = nil
|
@@ -38,6 +39,7 @@ module Facter
|
|
38
39
|
return if @@legacy_logger
|
39
40
|
|
40
41
|
@@legacy_logger = Logger.new(output)
|
42
|
+
@@legacy_logger.level = DEFAULT_LOG_LEVEL
|
41
43
|
set_format_for_legacy_logger
|
42
44
|
@@logger.add_logger(@@legacy_logger)
|
43
45
|
end
|
@@ -71,7 +71,7 @@ module Facter
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def found_fact?(fact_name, query_fact)
|
74
|
-
fact_with_wildcard = fact_name.include?('.*')
|
74
|
+
fact_with_wildcard = fact_name.include?('.*') && !query_fact.include?('.')
|
75
75
|
|
76
76
|
return false if fact_with_wildcard && !query_fact.match("^#{fact_name}$")
|
77
77
|
|
@@ -15,9 +15,10 @@ module Facter
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def read_vtf_file(fact_name)
|
18
|
-
|
18
|
+
file_content = Util::FileHelper.safe_readlines('/etc/vfs')
|
19
|
+
return if file_content.empty?
|
19
20
|
|
20
|
-
file_content =
|
21
|
+
file_content = file_content.map do |line|
|
21
22
|
next if line =~ /#|%/ # skip lines that are comments or defaultvfs line
|
22
23
|
|
23
24
|
line.split(' ').first
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Facter
|
4
|
+
module Resolvers
|
5
|
+
module Aix
|
6
|
+
class Partitions < BaseResolver
|
7
|
+
@log = Facter::Log.new(self)
|
8
|
+
@semaphore = Mutex.new
|
9
|
+
@fact_list ||= {}
|
10
|
+
class << self
|
11
|
+
private
|
12
|
+
|
13
|
+
MEGABYTES_EXPONENT = 1024**2
|
14
|
+
GIGABYTES_EXPONENT = 1024**3
|
15
|
+
|
16
|
+
def post_resolve(fact_name)
|
17
|
+
@fact_list.fetch(fact_name) { query_cudv(fact_name) }
|
18
|
+
end
|
19
|
+
|
20
|
+
def query_cudv(fact_name)
|
21
|
+
@fact_list[:partitions] = {}
|
22
|
+
|
23
|
+
odmquery = Facter::ODMQuery.new
|
24
|
+
odmquery.equals('PdDvLn', 'logical_volume/lvsubclass/lvtype')
|
25
|
+
|
26
|
+
result = odmquery.execute
|
27
|
+
|
28
|
+
return unless result
|
29
|
+
|
30
|
+
result.each_line do |line|
|
31
|
+
next unless line.include?('name')
|
32
|
+
|
33
|
+
part_name = line.split('=')[1].strip.delete('"')
|
34
|
+
part = "/dev/#{part_name}"
|
35
|
+
info = populate_from_lslv(part_name)
|
36
|
+
@fact_list[:partitions][part] = info if info
|
37
|
+
end
|
38
|
+
|
39
|
+
@fact_list[fact_name]
|
40
|
+
end
|
41
|
+
|
42
|
+
def populate_from_lslv(name)
|
43
|
+
stdout, stderr, _status = Open3.capture3("lslv -L #{name}")
|
44
|
+
if stdout.empty?
|
45
|
+
@log.debug(stderr)
|
46
|
+
return
|
47
|
+
end
|
48
|
+
|
49
|
+
info_hash = extract_info(stdout)
|
50
|
+
size_bytes = compute_size(info_hash)
|
51
|
+
|
52
|
+
part_info = {
|
53
|
+
filesystem: info_hash['TYPE'],
|
54
|
+
size_bytes: size_bytes,
|
55
|
+
size: Facter::BytesToHumanReadable.convert(size_bytes)
|
56
|
+
}
|
57
|
+
mount = info_hash['MOUNTPOINT']
|
58
|
+
label = info_hash['LABEL']
|
59
|
+
part_info[:mount] = mount unless %r{N/A} =~ mount
|
60
|
+
part_info[:label] = label unless /None/ =~ label
|
61
|
+
part_info
|
62
|
+
end
|
63
|
+
|
64
|
+
def extract_info(lsl_content)
|
65
|
+
lsl_content = lsl_content.strip.split("\n").map do |line|
|
66
|
+
next unless /PPs:|PP SIZE|TYPE:|LABEL:|MOUNT/ =~ line
|
67
|
+
|
68
|
+
line.split(/:|\s\s/).reject(&:empty?)
|
69
|
+
end
|
70
|
+
|
71
|
+
lsl_content.flatten!.select! { |elem| elem }.map! { |elem| elem.delete("\s") }
|
72
|
+
|
73
|
+
Hash[*lsl_content]
|
74
|
+
end
|
75
|
+
|
76
|
+
def compute_size(info_hash)
|
77
|
+
physical_partitions = info_hash['PPs'].to_i
|
78
|
+
size_physical_partition = info_hash['PPSIZE']
|
79
|
+
exp = size_physical_partition[/mega/] ? MEGABYTES_EXPONENT : GIGABYTES_EXPONENT
|
80
|
+
size_physical_partition.to_i * physical_partitions * exp
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|