facter 4.2.5 → 4.2.8
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/config.rb +1 -0
- data/lib/facter/custom_facts/core/execution/base.rb +4 -2
- data/lib/facter/custom_facts/util/fact.rb +1 -1
- data/lib/facter/custom_facts/util/resolution.rb +1 -1
- data/lib/facter/facts/linux/cloud/provider.rb +2 -0
- data/lib/facter/facts/linux/disks.rb +1 -1
- data/lib/facter/facts/linux/hypervisors/kvm.rb +3 -1
- data/lib/facter/facts/windows/cloud/provider.rb +2 -0
- data/lib/facter/facts/windows/os/windows/display_version.rb +2 -1
- data/lib/facter/facts/windows/timezone.rb +1 -1
- data/lib/facter/framework/core/cache_manager.rb +17 -1
- data/lib/facter/framework/core/options.rb +16 -1
- data/lib/facter/framework/detector/os_detector.rb +2 -3
- data/lib/facter/resolvers/aix/mountpoints.rb +14 -8
- data/lib/facter/resolvers/disks.rb +86 -0
- data/lib/facter/resolvers/dmi.rb +1 -0
- data/lib/facter/resolvers/ec2.rb +1 -1
- data/lib/facter/resolvers/lsb_release.rb +0 -2
- data/lib/facter/resolvers/os_release.rb +51 -20
- data/lib/facter/resolvers/redhat_release.rb +5 -5
- data/lib/facter/resolvers/suse_release.rb +1 -1
- data/lib/facter/resolvers/windows/ffi/winnls_ffi.rb +11 -0
- data/lib/facter/resolvers/windows/timezone.rb +41 -0
- data/lib/facter/util/file_helper.rb +10 -0
- data/lib/facter/version.rb +1 -1
- metadata +6 -4
- data/lib/facter/resolvers/disk.rb +0 -64
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3abae20894fc4d31ecfa8190b26307c05f73dce8454b1caa5ae0753cf6f17928
|
4
|
+
data.tar.gz: 7f5e4ed7f8eda7306ef86101e8a7d61c59b1dd1e56104875378bbd7113b19632
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcfeebbb72dd925224405095a1043bd6e99ef30afc4395f896172f1441b88a1c4c454ff812c4d23e71da823e20e54b30ae76e08602dd70fd5376c7f5a583f23a
|
7
|
+
data.tar.gz: 3cccf97b96203afddc850670e73ddc96bfffa9dc5f7949d567f89f44be68a39ba642ec04d930154b874d1b02cc9c98a5a0ae0d78cd96f6a17089ee6b4c01e7c2
|
data/lib/facter/config.rb
CHANGED
@@ -7,6 +7,7 @@ module Facter
|
|
7
7
|
module Execution
|
8
8
|
class Base
|
9
9
|
STDERR_MESSAGE = 'Command %s completed with the following stderr message: %s'
|
10
|
+
VALID_OPTIONS = %i[on_fail expand logger timeout].freeze
|
10
11
|
|
11
12
|
def initialize
|
12
13
|
@log = Log.new(self)
|
@@ -117,9 +118,10 @@ module Facter
|
|
117
118
|
timeout = (options[:timeout] || options[:time_limit] || options[:limit]).to_i
|
118
119
|
timeout = timeout.positive? ? timeout : nil
|
119
120
|
|
120
|
-
extra_keys = options.keys -
|
121
|
+
extra_keys = options.keys - VALID_OPTIONS
|
121
122
|
unless extra_keys.empty?
|
122
|
-
@log.warn("Unexpected key passed to Facter::Core::Execution.execute option: #{
|
123
|
+
@log.warn("Unexpected key passed to Facter::Core::Execution.execute option: #{extra_keys.join(',')}" \
|
124
|
+
" - valid keys: #{VALID_OPTIONS.join(',')}")
|
123
125
|
end
|
124
126
|
|
125
127
|
[on_fail, expand, logger, timeout]
|
@@ -10,6 +10,8 @@ module Facts
|
|
10
10
|
provider = case Facter::Util::Facts::Posix::VirtualDetector.platform
|
11
11
|
when 'hyperv'
|
12
12
|
'azure' unless Facter::Resolvers::Az.resolve(:metadata).empty?
|
13
|
+
when 'kvm', 'xen'
|
14
|
+
'aws' unless Facter::Resolvers::Ec2.resolve(:metadata).empty?
|
13
15
|
end
|
14
16
|
|
15
17
|
Facter::ResolvedFact.new(FACT_NAME, provider)
|
@@ -35,13 +35,15 @@ module Facts
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def kvm?
|
38
|
+
product_name = discover_hypervisor
|
38
39
|
bios_vendor = Facter::Resolvers::Linux::DmiBios.resolve(:bios_vendor)
|
39
40
|
@log.debug("Detected bios vendor: #{bios_vendor}")
|
40
41
|
|
41
42
|
Facter::Resolvers::VirtWhat.resolve(:vm) == 'kvm' ||
|
42
43
|
Facter::Resolvers::Lspci.resolve(:vm) == 'kvm' ||
|
43
44
|
bios_vendor&.include?('Amazon EC2') ||
|
44
|
-
bios_vendor&.include?('Google')
|
45
|
+
bios_vendor&.include?('Google') ||
|
46
|
+
product_name&.include?('OpenStack')
|
45
47
|
end
|
46
48
|
|
47
49
|
def discover_provider
|
@@ -11,6 +11,8 @@ module Facts
|
|
11
11
|
provider = case virtual
|
12
12
|
when 'hyperv'
|
13
13
|
'azure' unless Facter::Resolvers::Az.resolve(:metadata).empty?
|
14
|
+
when 'kvm', 'xen'
|
15
|
+
'aws' unless Facter::Resolvers::Ec2.resolve(:metadata).empty?
|
14
16
|
end
|
15
17
|
|
16
18
|
Facter::ResolvedFact.new(FACT_NAME, provider)
|
@@ -6,11 +6,12 @@ module Facts
|
|
6
6
|
module Windows
|
7
7
|
class DisplayVersion
|
8
8
|
FACT_NAME = 'os.windows.display_version'
|
9
|
+
ALIASES = 'windows_display_version'
|
9
10
|
|
10
11
|
def call_the_resolver
|
11
12
|
fact_value = Facter::Resolvers::ProductRelease.resolve(:display_version)
|
12
13
|
|
13
|
-
Facter::ResolvedFact.new(FACT_NAME, fact_value)
|
14
|
+
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
@@ -167,7 +167,8 @@ cache_format_version is incorrect!")
|
|
167
167
|
next unless check_ttls?(group_name, @fact_groups.get_group_ttls(group_name))
|
168
168
|
|
169
169
|
cache_file_name = File.join(@cache_dir, group_name)
|
170
|
-
|
170
|
+
|
171
|
+
next if facts_already_cached?(cache_file_name, data)
|
171
172
|
|
172
173
|
@log.debug("caching values for #{group_name} facts")
|
173
174
|
|
@@ -176,6 +177,21 @@ cache_format_version is incorrect!")
|
|
176
177
|
end
|
177
178
|
end
|
178
179
|
|
180
|
+
def facts_already_cached?(cache_file_name, data)
|
181
|
+
if File.readable?(cache_file_name)
|
182
|
+
file = Facter::Util::FileHelper.safe_read(cache_file_name)
|
183
|
+
begin
|
184
|
+
cached_data = JSON.parse(file) unless file.nil?
|
185
|
+
return true if (data.keys - cached_data.keys).empty?
|
186
|
+
rescue JSON::ParserError => e
|
187
|
+
@log.debug("Failed to read cache file #{cache_file_name}. Detail: #{e.message}")
|
188
|
+
rescue NoMethodError => e
|
189
|
+
@log.debug("No keys found in #{cache_file_name}. Detail: #{e.message}")
|
190
|
+
end
|
191
|
+
end
|
192
|
+
false
|
193
|
+
end
|
194
|
+
|
179
195
|
def read_group_json(group_name)
|
180
196
|
return @groups[group_name] if @groups.key?(group_name)
|
181
197
|
|
@@ -55,10 +55,25 @@ module Facter
|
|
55
55
|
|
56
56
|
def store(options)
|
57
57
|
options.each do |key, value|
|
58
|
-
value =
|
58
|
+
value = munge_option(key, value)
|
59
59
|
OptionStore.set(key, value)
|
60
60
|
end
|
61
61
|
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def munge_option(key, value)
|
66
|
+
return value unless key.to_sym == :log_level
|
67
|
+
|
68
|
+
case value.to_sym
|
69
|
+
when :log_level
|
70
|
+
''
|
71
|
+
when :none
|
72
|
+
'unknown'
|
73
|
+
else
|
74
|
+
value
|
75
|
+
end
|
76
|
+
end
|
62
77
|
end
|
63
78
|
end
|
64
79
|
end
|
@@ -5,7 +5,7 @@ require 'rbconfig'
|
|
5
5
|
class OsDetector
|
6
6
|
include Singleton
|
7
7
|
|
8
|
-
attr_reader :identifier, :
|
8
|
+
attr_reader :identifier, :hierarchy
|
9
9
|
|
10
10
|
def initialize(*_args)
|
11
11
|
@log = Facter::Log.new(self)
|
@@ -75,8 +75,7 @@ class OsDetector
|
|
75
75
|
[Facter::Resolvers::OsRelease,
|
76
76
|
Facter::Resolvers::RedHatRelease,
|
77
77
|
Facter::Resolvers::SuseRelease].each do |resolver|
|
78
|
-
@identifier = resolver.resolve(:
|
79
|
-
@version = resolver.resolve(:version)
|
78
|
+
@identifier = resolver.resolve(:id)
|
80
79
|
break if @identifier
|
81
80
|
end
|
82
81
|
|
@@ -18,23 +18,29 @@ module Facter
|
|
18
18
|
def read_mount(fact_name)
|
19
19
|
@fact_list[:mountpoints] = {}
|
20
20
|
output = Facter::Core::Execution.execute('mount', logger: log)
|
21
|
-
output.split("\n").map do |line|
|
22
|
-
next if line =~
|
21
|
+
output.split("\n").drop(2).map do |line|
|
22
|
+
next if line =~ /procfs|ahafs/
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
@fact_list[:mountpoints][elem[1]] = { device: elem[0], filesystem: elem[2],
|
27
|
-
options: elem.last.split(',') }
|
24
|
+
add_mount_points_fact(line)
|
28
25
|
end
|
29
26
|
|
30
27
|
retrieve_sizes_for_mounts
|
31
28
|
@fact_list[fact_name]
|
32
29
|
end
|
33
30
|
|
31
|
+
def add_mount_points_fact(line)
|
32
|
+
elem = line.split("\s")
|
33
|
+
|
34
|
+
elem.shift unless line[0] == ' '
|
35
|
+
|
36
|
+
@fact_list[:mountpoints][elem[1]] = { device: elem[0], filesystem: elem[2],
|
37
|
+
options: elem.last.include?(':') ? [] : elem.last.split(',') }
|
38
|
+
end
|
39
|
+
|
34
40
|
def retrieve_sizes_for_mounts
|
35
41
|
output = Facter::Core::Execution.execute('df -P', logger: log)
|
36
|
-
output.split("\n").map do |line|
|
37
|
-
next if line =~
|
42
|
+
output.split("\n").drop(1).map do |line|
|
43
|
+
next if line =~ /-\s+-\s+-/
|
38
44
|
|
39
45
|
mount_info = line.split("\s")
|
40
46
|
mount_info[3] = translate_to_bytes(mount_info[3])
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Facter
|
4
|
+
module Resolvers
|
5
|
+
module Linux
|
6
|
+
class Disks < BaseResolver
|
7
|
+
@log = Facter::Log.new(self)
|
8
|
+
|
9
|
+
init_resolver
|
10
|
+
|
11
|
+
DIR = '/sys/block'
|
12
|
+
FILE_PATHS = { model: 'device/model',
|
13
|
+
size: 'size',
|
14
|
+
vendor: 'device/vendor',
|
15
|
+
type: 'queue/rotational',
|
16
|
+
serial: 'false',
|
17
|
+
wwn: 'false' }.freeze
|
18
|
+
|
19
|
+
class << self
|
20
|
+
private
|
21
|
+
|
22
|
+
def post_resolve(fact_name, _options)
|
23
|
+
@fact_list.fetch(fact_name) do
|
24
|
+
return unless @fact_list.empty?
|
25
|
+
|
26
|
+
build_disks_hash
|
27
|
+
|
28
|
+
read_facts
|
29
|
+
|
30
|
+
@fact_list[:disks] = nil if @fact_list[:disks].empty?
|
31
|
+
@fact_list[fact_name]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def lsblk(option, disk)
|
36
|
+
result = Facter::Core::Execution.execute(
|
37
|
+
"lsblk -dn -o #{option} /dev/#{disk}", on_fail: '', timeout: 1
|
38
|
+
).strip
|
39
|
+
result.empty? ? nil : result
|
40
|
+
end
|
41
|
+
|
42
|
+
def read_facts
|
43
|
+
FILE_PATHS.each do |key, file|
|
44
|
+
@fact_list[:disks].each do |disk, value|
|
45
|
+
file_path = File.join(DIR, disk, file)
|
46
|
+
|
47
|
+
result = if file == 'false'
|
48
|
+
lsblk(key, disk)
|
49
|
+
else
|
50
|
+
Facter::Util::FileHelper.safe_read(file_path, nil)&.strip
|
51
|
+
end
|
52
|
+
|
53
|
+
next unless result
|
54
|
+
|
55
|
+
value[key] = case key
|
56
|
+
when :size
|
57
|
+
# Linux always considers sectors to be 512 bytes long
|
58
|
+
# independently of the devices real block size.
|
59
|
+
construct_size(value, result)
|
60
|
+
when :type
|
61
|
+
result == '0' ? 'ssd' : 'hdd'
|
62
|
+
else
|
63
|
+
result
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def build_disks_hash
|
70
|
+
valid_disks = Facter::Util::FileHelper.dir_children(DIR)
|
71
|
+
.select { |disk| File.readable?(File.join(DIR, disk, 'device')) }
|
72
|
+
|
73
|
+
@fact_list[:disks] = {}
|
74
|
+
valid_disks.each { |disk| @fact_list[:disks][disk] = {} }
|
75
|
+
end
|
76
|
+
|
77
|
+
def construct_size(facts, value)
|
78
|
+
value = value.to_i * 512
|
79
|
+
facts[:size_bytes] = value
|
80
|
+
facts[:size] = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(value)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/lib/facter/resolvers/dmi.rb
CHANGED
@@ -36,6 +36,7 @@ module Facter
|
|
36
36
|
return unless File.directory?('/sys/class/dmi')
|
37
37
|
|
38
38
|
file_content = Facter::Util::FileHelper.safe_read("/sys/class/dmi/id/#{fact_name}", nil)
|
39
|
+
.encode('UTF-8', invalid: :replace)
|
39
40
|
if files.include?(fact_name.to_s) && file_content
|
40
41
|
file_content = file_content.strip
|
41
42
|
@fact_list[fact_name] = file_content unless file_content.empty?
|
data/lib/facter/resolvers/ec2.rb
CHANGED
@@ -20,7 +20,7 @@ module Facter
|
|
20
20
|
def read_facts(fact_name)
|
21
21
|
@fact_list[:metadata] = {}
|
22
22
|
query_for_metadata(EC2_METADATA_ROOT_URL, @fact_list[:metadata])
|
23
|
-
@fact_list[:userdata] = get_data_from(EC2_USERDATA_ROOT_URL).strip
|
23
|
+
@fact_list[:userdata] = get_data_from(EC2_USERDATA_ROOT_URL).strip.force_encoding('UTF-8')
|
24
24
|
@fact_list[fact_name]
|
25
25
|
end
|
26
26
|
|
@@ -20,53 +20,84 @@ module Facter
|
|
20
20
|
private
|
21
21
|
|
22
22
|
def post_resolve(fact_name, _options)
|
23
|
-
@fact_list.fetch(fact_name)
|
23
|
+
@fact_list.fetch(fact_name) do
|
24
|
+
# If we get here multiple times per run it's probably because
|
25
|
+
# someone's asking for a os-release value not present in the file
|
26
|
+
# (e.g. VERSION is not a thing on rolling distributions, so this
|
27
|
+
# code will always run if the resolver is being asked for :version,
|
28
|
+
# because it'll never get cached).
|
29
|
+
#
|
30
|
+
# Just return early to avoid reparsing the file.
|
31
|
+
return unless @fact_list.empty?
|
32
|
+
|
33
|
+
pairs = read_and_parse_os_release_file
|
34
|
+
return unless pairs
|
35
|
+
|
36
|
+
fill_fact_list(pairs)
|
37
|
+
|
38
|
+
process_name
|
39
|
+
process_version_id
|
40
|
+
process_id
|
41
|
+
|
42
|
+
@fact_list[fact_name]
|
43
|
+
end
|
24
44
|
end
|
25
45
|
|
26
|
-
def
|
27
|
-
|
28
|
-
return
|
46
|
+
def read_and_parse_os_release_file
|
47
|
+
content = Facter::Util::FileHelper.safe_readlines('/etc/os-release')
|
48
|
+
return nil if content.empty?
|
29
49
|
|
30
50
|
pairs = []
|
31
|
-
|
32
|
-
output.each do |line|
|
51
|
+
content.each do |line|
|
33
52
|
pairs << line.strip.delete('"').split('=', 2)
|
34
53
|
end
|
35
54
|
|
36
|
-
|
37
|
-
process_name
|
38
|
-
pad_version_id
|
39
|
-
normalize_opensuse_identifier
|
40
|
-
|
41
|
-
@fact_list[fact_name]
|
55
|
+
pairs
|
42
56
|
end
|
43
57
|
|
44
58
|
def fill_fact_list(pairs)
|
45
59
|
result = Hash[*pairs.flatten]
|
46
60
|
result.each { |k, v| @fact_list[k.downcase.to_sym] = v }
|
47
|
-
|
48
|
-
@fact_list[:identifier] = @fact_list[:id]
|
49
61
|
end
|
50
62
|
|
51
|
-
def
|
63
|
+
def process_version_id
|
64
|
+
return unless @fact_list[:version_id]
|
65
|
+
|
52
66
|
@fact_list[:version_id] = "#{@fact_list[:version_id]}.0" unless @fact_list[:version_id] =~ /\./
|
53
67
|
end
|
54
68
|
|
69
|
+
def process_id
|
70
|
+
return unless @fact_list[:id]
|
71
|
+
|
72
|
+
@fact_list[:id] = 'opensuse' if @fact_list[:id] =~ /opensuse/i
|
73
|
+
end
|
74
|
+
|
55
75
|
def process_name
|
56
|
-
|
57
|
-
|
76
|
+
return unless @fact_list[:name]
|
77
|
+
|
78
|
+
join_os_name
|
79
|
+
capitalize_os_name
|
80
|
+
append_linux_to_os_name
|
81
|
+
end
|
58
82
|
|
83
|
+
def join_os_name
|
84
|
+
os_name = @fact_list[:name]
|
59
85
|
@fact_list[:name] = if os_name.downcase.start_with?('red', 'oracle', 'arch', 'manjaro')
|
60
86
|
os_name = os_name.split(' ')[0..1].join
|
61
|
-
os_name = os_name.capitalize if os_name.downcase.start_with?('arch', 'manjaro')
|
62
87
|
os_name
|
63
88
|
else
|
64
89
|
os_name.split(' ')[0].strip
|
65
90
|
end
|
66
91
|
end
|
67
92
|
|
68
|
-
def
|
69
|
-
|
93
|
+
def capitalize_os_name
|
94
|
+
os_name = @fact_list[:name]
|
95
|
+
@fact_list[:name] = os_name.capitalize if os_name.downcase.start_with?('arch', 'manjaro')
|
96
|
+
end
|
97
|
+
|
98
|
+
def append_linux_to_os_name
|
99
|
+
os_name = @fact_list[:name]
|
100
|
+
@fact_list[:name] = os_name + 'Linux' if os_name.downcase.start_with?('virtuozzo')
|
70
101
|
end
|
71
102
|
end
|
72
103
|
end
|
@@ -36,18 +36,18 @@ module Facter
|
|
36
36
|
@fact_list[:distributor_id] = distributor_id(output_strings[0])
|
37
37
|
@fact_list[:name] = release_name(output_strings[0])
|
38
38
|
@fact_list[:version] = version(output_strings)
|
39
|
-
@fact_list[:
|
39
|
+
@fact_list[:id] = id(@fact_list[:name])
|
40
40
|
end
|
41
41
|
|
42
42
|
def release_name(value)
|
43
43
|
value.split.reject { |el| el.casecmp('linux').zero? }[0..1].join
|
44
44
|
end
|
45
45
|
|
46
|
-
def
|
47
|
-
|
48
|
-
|
46
|
+
def id(value)
|
47
|
+
id = value.downcase
|
48
|
+
id = 'rhel' if @fact_list[:name].casecmp('Red Hat Enterprise Linux')
|
49
49
|
|
50
|
-
|
50
|
+
id
|
51
51
|
end
|
52
52
|
|
53
53
|
def codename(value)
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Facter
|
4
|
+
module Resolvers
|
5
|
+
module Windows
|
6
|
+
class Timezone < BaseResolver
|
7
|
+
init_resolver
|
8
|
+
|
9
|
+
class << self
|
10
|
+
private
|
11
|
+
|
12
|
+
def post_resolve(fact_name, _options)
|
13
|
+
@fact_list.fetch(fact_name) { determine_timezone }
|
14
|
+
end
|
15
|
+
|
16
|
+
def determine_timezone
|
17
|
+
timezone = Time.now.zone
|
18
|
+
@fact_list[:timezone] = timezone.force_encoding("CP#{codepage}").encode('UTF-8', invalid: :replace)
|
19
|
+
rescue ArgumentError
|
20
|
+
@fact_list[:timezone] = timezone
|
21
|
+
end
|
22
|
+
|
23
|
+
def codepage
|
24
|
+
result = codepage_from_api
|
25
|
+
result.empty? ? codepage_from_registry : result
|
26
|
+
end
|
27
|
+
|
28
|
+
def codepage_from_registry
|
29
|
+
require 'win32/registry'
|
30
|
+
::Win32::Registry::HKEY_LOCAL_MACHINE.open('SYSTEM\CurrentControlSet\Control\Nls\CodePage')['ACP']
|
31
|
+
end
|
32
|
+
|
33
|
+
def codepage_from_api
|
34
|
+
require 'facter/resolvers/windows/ffi/winnls_ffi'
|
35
|
+
WinnlsFFI.GetACP.to_s
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -22,6 +22,16 @@ module Facter
|
|
22
22
|
default_return
|
23
23
|
end
|
24
24
|
|
25
|
+
def dir_children(path)
|
26
|
+
children = if RUBY_VERSION.to_f < 2.5
|
27
|
+
Dir.entries(path).reject { |dir| ['.', '..'].include?(dir) }
|
28
|
+
else
|
29
|
+
Dir.children(path)
|
30
|
+
end
|
31
|
+
|
32
|
+
children
|
33
|
+
end
|
34
|
+
|
25
35
|
private
|
26
36
|
|
27
37
|
def log_failed_to_read(path)
|
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.2.
|
4
|
+
version: 4.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -934,7 +934,7 @@ files:
|
|
934
934
|
- lib/facter/resolvers/bsd/processors.rb
|
935
935
|
- lib/facter/resolvers/containers.rb
|
936
936
|
- lib/facter/resolvers/debian_version.rb
|
937
|
-
- lib/facter/resolvers/
|
937
|
+
- lib/facter/resolvers/disks.rb
|
938
938
|
- lib/facter/resolvers/dmi.rb
|
939
939
|
- lib/facter/resolvers/dmi_decode.rb
|
940
940
|
- lib/facter/resolvers/ec2.rb
|
@@ -1022,6 +1022,7 @@ files:
|
|
1022
1022
|
- lib/facter/resolvers/windows/ffi/performance_information.rb
|
1023
1023
|
- lib/facter/resolvers/windows/ffi/system32_ffi.rb
|
1024
1024
|
- lib/facter/resolvers/windows/ffi/system_info.rb
|
1025
|
+
- lib/facter/resolvers/windows/ffi/winnls_ffi.rb
|
1025
1026
|
- lib/facter/resolvers/windows/fips.rb
|
1026
1027
|
- lib/facter/resolvers/windows/hardware_architecture.rb
|
1027
1028
|
- lib/facter/resolvers/windows/identity.rb
|
@@ -1033,6 +1034,7 @@ files:
|
|
1033
1034
|
- lib/facter/resolvers/windows/product_release.rb
|
1034
1035
|
- lib/facter/resolvers/windows/ssh.rb
|
1035
1036
|
- lib/facter/resolvers/windows/system32.rb
|
1037
|
+
- lib/facter/resolvers/windows/timezone.rb
|
1036
1038
|
- lib/facter/resolvers/windows/uptime.rb
|
1037
1039
|
- lib/facter/resolvers/windows/virtualization.rb
|
1038
1040
|
- lib/facter/resolvers/windows/win_os_description.rb
|
@@ -1092,7 +1094,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1092
1094
|
- !ruby/object:Gem::Version
|
1093
1095
|
version: '0'
|
1094
1096
|
requirements: []
|
1095
|
-
rubygems_version: 3.
|
1097
|
+
rubygems_version: 3.1.6
|
1096
1098
|
signing_key:
|
1097
1099
|
specification_version: 4
|
1098
1100
|
summary: Facter, a system inventory tool
|
@@ -1,64 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Facter
|
4
|
-
module Resolvers
|
5
|
-
module Linux
|
6
|
-
class Disk < BaseResolver
|
7
|
-
@log = Facter::Log.new(self)
|
8
|
-
|
9
|
-
init_resolver
|
10
|
-
|
11
|
-
DIR = '/sys/block'
|
12
|
-
FILE_PATHS = { model: 'device/model', size: 'size', vendor: 'device/vendor', type: 'queue/rotational' }.freeze
|
13
|
-
|
14
|
-
class << self
|
15
|
-
private
|
16
|
-
|
17
|
-
def post_resolve(fact_name, _options)
|
18
|
-
@fact_list.fetch(fact_name) { read_facts(fact_name) }
|
19
|
-
end
|
20
|
-
|
21
|
-
def read_facts(fact_name)
|
22
|
-
build_disks_hash
|
23
|
-
|
24
|
-
FILE_PATHS.each do |key, file|
|
25
|
-
@fact_list[:disks].each do |disk, value|
|
26
|
-
file_path = File.join(DIR, disk, file)
|
27
|
-
|
28
|
-
result = Facter::Util::FileHelper.safe_read(file_path).strip
|
29
|
-
next if result.empty?
|
30
|
-
|
31
|
-
value[key] = case key
|
32
|
-
when :size
|
33
|
-
# Linux always considers sectors to be 512 bytes long
|
34
|
-
# independently of the devices real block size.
|
35
|
-
construct_size(value, result)
|
36
|
-
when :type
|
37
|
-
result == '0' ? 'ssd' : 'hdd'
|
38
|
-
else
|
39
|
-
result
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
@fact_list[:disks] = nil if @fact_list[:disks].empty?
|
45
|
-
@fact_list[fact_name]
|
46
|
-
end
|
47
|
-
|
48
|
-
def build_disks_hash
|
49
|
-
@fact_list[:disks] = {}
|
50
|
-
directories = Dir.entries(DIR).reject { |dir| dir =~ /\.+/ }
|
51
|
-
directories.each { |disk| @fact_list[:disks].merge!(disk => {}) }
|
52
|
-
@fact_list[:disks].select! { |disk, _fact| File.readable?(File.join(DIR, disk, 'device')) }
|
53
|
-
end
|
54
|
-
|
55
|
-
def construct_size(facts, value)
|
56
|
-
value = value.to_i * 512
|
57
|
-
facts[:size_bytes] = value
|
58
|
-
facts[:size] = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(value)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|