facter 4.0.43 → 4.0.44
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 +13 -2
- data/lib/facter/config.rb +354 -0
- data/lib/facter/custom_facts/util/fact.rb +1 -1
- data/lib/facter/facts/rhel/os/release.rb +1 -1
- data/lib/facter/framework/benchmarking/timer.rb +4 -2
- data/lib/facter/framework/config/fact_groups.rb +5 -5
- data/lib/facter/framework/core/cache_manager.rb +4 -1
- data/lib/facter/framework/core/options/option_store.rb +35 -19
- data/lib/facter/framework/detector/os_hierarchy.rb +5 -9
- data/lib/facter/resolvers/aix/architecture_resolver.rb +15 -1
- data/lib/facter/resolvers/augeas_resolver.rb +7 -1
- data/lib/facter/resolvers/bsd/processors.rb +11 -7
- data/lib/facter/resolvers/disk_resolver.rb +11 -3
- data/lib/facter/resolvers/freebsd/geom_resolver.rb +12 -20
- data/lib/facter/resolvers/freebsd/processors.rb +11 -7
- data/lib/facter/resolvers/mountpoints_resolver.rb +48 -23
- data/lib/facter/resolvers/partitions.rb +60 -57
- data/lib/facter/resolvers/solaris/dmi.rb +2 -0
- data/lib/facter/resolvers/solaris/networking.rb +0 -1
- data/lib/facter/resolvers/solaris/os_release.rb +4 -3
- data/lib/facter/resolvers/ssh_resolver.rb +4 -4
- data/lib/facter/version.rb +1 -1
- metadata +3 -4
- data/lib/facter/fact_groups.conf +0 -308
- data/lib/facter/os_hierarchy.json +0 -36
@@ -74,7 +74,10 @@ module Facter
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def read_fact(searched_fact, fact_group)
|
77
|
-
data =
|
77
|
+
data = nil
|
78
|
+
Facter::Framework::Benchmarking::Timer.measure(searched_fact.name, 'cached') do
|
79
|
+
data = read_group_json(fact_group)
|
80
|
+
end
|
78
81
|
return unless data
|
79
82
|
|
80
83
|
@log.debug("loading cached values for #{searched_fact.name} facts")
|
@@ -8,28 +8,36 @@ module Facter
|
|
8
8
|
# TODO: constant is not yet available when running puppet facts
|
9
9
|
@log_level = :warn
|
10
10
|
@show_legacy = true
|
11
|
+
@custom_facts = true
|
12
|
+
@blocked_facts = []
|
13
|
+
@ruby = true
|
14
|
+
@external_facts = true
|
15
|
+
@config = nil
|
16
|
+
@user_query = []
|
17
|
+
@strict = false
|
18
|
+
@json = false
|
19
|
+
@cache = true
|
20
|
+
@yaml = false
|
21
|
+
@puppet = false
|
22
|
+
@ttls = []
|
11
23
|
@block = true
|
12
|
-
@
|
24
|
+
@cli = nil
|
13
25
|
@config_file_custom_dir = []
|
14
|
-
@custom_facts = true
|
15
|
-
@external_dir = []
|
16
26
|
@config_file_external_dir = []
|
17
27
|
@default_external_dir = []
|
18
|
-
@external_facts = true
|
19
|
-
@ruby = true
|
20
|
-
@cache = true
|
21
|
-
@blocked_facts = []
|
22
|
-
@user_query = []
|
23
|
-
@block_list = {}
|
24
28
|
@fact_groups = {}
|
29
|
+
@block_list = []
|
25
30
|
@color = true
|
31
|
+
@trace = false
|
26
32
|
@timing = false
|
33
|
+
@external_dir = []
|
34
|
+
@custom_dir = []
|
27
35
|
|
28
36
|
class << self
|
29
37
|
attr_reader :debug, :verbose, :log_level, :show_legacy,
|
30
38
|
:custom_facts, :blocked_facts, :ruby, :external_facts
|
31
39
|
|
32
|
-
attr_accessor :config, :user_query, :strict, :json,
|
40
|
+
attr_accessor :config, :user_query, :strict, :json,
|
33
41
|
:cache, :yaml, :puppet, :ttls, :block, :cli, :config_file_custom_dir,
|
34
42
|
:config_file_external_dir, :default_external_dir, :fact_groups,
|
35
43
|
:block_list, :color, :trace, :timing
|
@@ -158,26 +166,34 @@ module Facter
|
|
158
166
|
# TODO: constant is not yet available when running puppet facts
|
159
167
|
@log_level = :warn
|
160
168
|
@show_legacy = true
|
161
|
-
@block = true
|
162
169
|
@ruby = true
|
163
170
|
@user_query = []
|
164
|
-
@
|
171
|
+
@json = false
|
165
172
|
@cache = true
|
166
|
-
@
|
173
|
+
@yaml = false
|
174
|
+
@puppet = false
|
175
|
+
@ttls = []
|
176
|
+
@block = true
|
177
|
+
@cli = nil
|
167
178
|
reset_config
|
168
179
|
end
|
169
180
|
|
170
181
|
def reset_config
|
171
|
-
@custom_dir = []
|
172
182
|
@custom_facts = true
|
173
|
-
@external_dir = []
|
174
|
-
@default_external_dir = []
|
175
|
-
@config_file_external_dir = []
|
176
|
-
@external_facts = true
|
177
183
|
@blocked_facts = []
|
184
|
+
@external_facts = true
|
185
|
+
@config = nil
|
186
|
+
@strict = false
|
187
|
+
@config_file_custom_dir = []
|
188
|
+
@config_file_external_dir = []
|
189
|
+
@default_external_dir = []
|
178
190
|
@fact_groups = {}
|
179
|
-
@block_list =
|
191
|
+
@block_list = []
|
192
|
+
@color = true
|
193
|
+
@trace = false
|
180
194
|
@timing = false
|
195
|
+
@external_dir = []
|
196
|
+
@custom_dir = []
|
181
197
|
end
|
182
198
|
|
183
199
|
def fallback_external_dir
|
@@ -1,29 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'facter/config'
|
4
|
+
|
3
5
|
module Facter
|
4
6
|
class OsHierarchy
|
5
7
|
def initialize
|
6
8
|
@log = Log.new(self)
|
7
|
-
|
8
|
-
json_file = Util::FileHelper.safe_read(json_file_path)
|
9
|
-
begin
|
10
|
-
@json_os_hierarchy = JSON.parse(json_file)
|
11
|
-
rescue JSON::ParserError => _e
|
12
|
-
@log.error('Could not parse os_hierarchy json')
|
13
|
-
end
|
9
|
+
@os_hierarchy = Facter::Config::OS_HIERARCHY
|
14
10
|
end
|
15
11
|
|
16
12
|
def construct_hierarchy(searched_os)
|
17
13
|
return [] if searched_os.nil?
|
18
14
|
|
19
15
|
searched_os = searched_os.to_s.capitalize
|
20
|
-
if @
|
16
|
+
if @os_hierarchy.nil?
|
21
17
|
@log.debug("There is no os_hierarchy, will fall back to: #{searched_os}")
|
22
18
|
return [searched_os]
|
23
19
|
end
|
24
20
|
|
25
21
|
@searched_path = []
|
26
|
-
search(@
|
22
|
+
search(@os_hierarchy, searched_os, [])
|
27
23
|
|
28
24
|
@searched_path.map { |os_name| os_name.to_s.capitalize }
|
29
25
|
end
|
@@ -14,9 +14,11 @@ module Facter
|
|
14
14
|
|
15
15
|
def read_architecture(fact_name)
|
16
16
|
require_relative 'utils/odm_query'
|
17
|
+
|
18
|
+
proc_number = read_proc
|
17
19
|
odmquery = ODMQuery.new
|
18
20
|
odmquery
|
19
|
-
.equals('name',
|
21
|
+
.equals('name', proc_number)
|
20
22
|
.equals('attribute', 'type')
|
21
23
|
|
22
24
|
result = odmquery.execute
|
@@ -32,6 +34,18 @@ module Facter
|
|
32
34
|
|
33
35
|
@fact_list[fact_name]
|
34
36
|
end
|
37
|
+
|
38
|
+
def read_proc
|
39
|
+
odmquery = ODMQuery.new
|
40
|
+
odmquery
|
41
|
+
.equals('PdDvLn', 'processor/sys/proc_rspc')
|
42
|
+
.equals('status', '1')
|
43
|
+
|
44
|
+
result = odmquery.execute
|
45
|
+
result.each_line do |line|
|
46
|
+
return line.split('=')[1].strip.delete('\"') if line.include?('name')
|
47
|
+
end
|
48
|
+
end
|
35
49
|
end
|
36
50
|
end
|
37
51
|
end
|
@@ -20,7 +20,13 @@ module Facter
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def read_augeas_from_cli
|
23
|
-
|
23
|
+
command = if File.readable?('/opt/puppetlabs/puppet/bin/augparse')
|
24
|
+
'/opt/puppetlabs/puppet/bin/augparse'
|
25
|
+
else
|
26
|
+
'augparse'
|
27
|
+
end
|
28
|
+
|
29
|
+
output = Facter::Core::Execution.execute("#{command} --version 2>&1", logger: log)
|
24
30
|
Regexp.last_match(1) if output =~ /^augparse (\d+\.\d+\.\d+)/
|
25
31
|
end
|
26
32
|
|
@@ -16,8 +16,12 @@ module Facter
|
|
16
16
|
def collect_processors_info(fact_name)
|
17
17
|
require 'facter/resolvers/bsd/ffi/ffi_helper'
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
count = logical_count
|
20
|
+
model = processor_model
|
21
|
+
speed = processor_speed
|
22
|
+
|
23
|
+
@fact_list[:logical_count] = count
|
24
|
+
@fact_list[:models] = Array.new(count, model) if count && model
|
21
25
|
@fact_list[:speed] = speed * 1000 * 1000 if speed
|
22
26
|
|
23
27
|
@fact_list[fact_name]
|
@@ -28,16 +32,16 @@ module Facter
|
|
28
32
|
HW_NCPU = 3
|
29
33
|
HW_CPUSPEED = 12
|
30
34
|
|
31
|
-
def
|
32
|
-
|
35
|
+
def processor_model
|
36
|
+
Facter::Bsd::FfiHelper.sysctl(:string, [CTL_HW, HW_MODEL])
|
33
37
|
end
|
34
38
|
|
35
39
|
def logical_count
|
36
|
-
|
40
|
+
Facter::Bsd::FfiHelper.sysctl(:uint32_t, [CTL_HW, HW_NCPU])
|
37
41
|
end
|
38
42
|
|
39
|
-
def
|
40
|
-
|
43
|
+
def processor_speed
|
44
|
+
Facter::Bsd::FfiHelper.sysctl(:uint32_t, [CTL_HW, HW_CPUSPEED])
|
41
45
|
end
|
42
46
|
end
|
43
47
|
end
|
@@ -7,7 +7,7 @@ module Facter
|
|
7
7
|
@log = Facter::Log.new(self)
|
8
8
|
@fact_list ||= {}
|
9
9
|
DIR = '/sys/block'
|
10
|
-
FILE_PATHS = { model: 'device/model', size: 'size', vendor: 'device/vendor' }.freeze
|
10
|
+
FILE_PATHS = { model: 'device/model', size: 'size', vendor: 'device/vendor', type: 'queue/rotational' }.freeze
|
11
11
|
class << self
|
12
12
|
private
|
13
13
|
|
@@ -25,8 +25,16 @@ module Facter
|
|
25
25
|
result = Util::FileHelper.safe_read(file_path).strip
|
26
26
|
next if result.empty?
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
value[key] = case key
|
29
|
+
when :size
|
30
|
+
# Linux always considers sectors to be 512 bytes long
|
31
|
+
# independently of the devices real block size.
|
32
|
+
construct_size(value, result)
|
33
|
+
when :type
|
34
|
+
result == '0' ? 'ssd' : 'hdd'
|
35
|
+
else
|
36
|
+
result
|
37
|
+
end
|
30
38
|
end
|
31
39
|
end
|
32
40
|
|
@@ -5,6 +5,8 @@ module Facter
|
|
5
5
|
module Freebsd
|
6
6
|
class Geom < BaseResolver
|
7
7
|
@fact_list ||= {}
|
8
|
+
DISKS_ATTRIBUTES = %i[read_model read_serial_number read_size].freeze
|
9
|
+
PARTITIONS_ATTRIBUTES = %i[read_partlabel read_partuuid read_size].freeze
|
8
10
|
|
9
11
|
class << self
|
10
12
|
private
|
@@ -17,37 +19,27 @@ module Facter
|
|
17
19
|
require_relative 'ffi/ffi_helper'
|
18
20
|
require 'rexml/document'
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
+
topology = geom_topology
|
23
|
+
read_data('DISK', topology, DISKS_ATTRIBUTES)
|
24
|
+
read_data('PART', topology, PARTITIONS_ATTRIBUTES)
|
22
25
|
|
23
26
|
@fact_list[fact_name]
|
24
27
|
end
|
25
28
|
|
26
|
-
def
|
27
|
-
|
29
|
+
def read_data(fact_name, geom_topology, data_to_read)
|
30
|
+
fact_list_key = fact_name == 'DISK' ? :disks : :partitions
|
31
|
+
@fact_list[fact_list_key] = {}
|
28
32
|
|
29
|
-
each_geom_class_provider(
|
33
|
+
each_geom_class_provider(fact_name, geom_topology) do |provider|
|
30
34
|
name = provider.get_text('./name').value
|
31
35
|
|
32
|
-
@fact_list[
|
36
|
+
@fact_list[fact_list_key][name] = data_to_read.map do |x|
|
33
37
|
send(x, provider)
|
34
38
|
end.inject(:merge)
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
38
|
-
def
|
39
|
-
@fact_list[:partitions] = {}
|
40
|
-
|
41
|
-
each_geom_class_provider('PART') do |provider|
|
42
|
-
name = provider.get_text('./name').value
|
43
|
-
|
44
|
-
@fact_list[:partitions][name] = %i[read_partlabel read_partuuid read_size].map do |x|
|
45
|
-
send(x, provider)
|
46
|
-
end.inject(:merge)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def each_geom_class_provider(geom_class_name, &block)
|
42
|
+
def each_geom_class_provider(geom_class_name, geom_topology, &block)
|
51
43
|
REXML::XPath.each(geom_topology, "/mesh/class[name/text() = '#{geom_class_name}']/geom/provider", &block)
|
52
44
|
end
|
53
45
|
|
@@ -95,7 +87,7 @@ module Facter
|
|
95
87
|
end
|
96
88
|
|
97
89
|
def geom_topology
|
98
|
-
|
90
|
+
REXML::Document.new(geom_confxml)
|
99
91
|
end
|
100
92
|
|
101
93
|
def geom_confxml
|
@@ -18,23 +18,27 @@ module Facter
|
|
18
18
|
def collect_processors_info(fact_name)
|
19
19
|
require 'facter/resolvers/freebsd/ffi/ffi_helper'
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
count = logical_count
|
22
|
+
model = processors_model
|
23
|
+
speed = processors_speed
|
24
|
+
|
25
|
+
@fact_list[:logical_count] = count
|
26
|
+
@fact_list[:models] = Array.new(count, model) if logical_count && model
|
23
27
|
@fact_list[:speed] = speed * 1000 * 1000 if speed
|
24
28
|
|
25
29
|
@fact_list[fact_name]
|
26
30
|
end
|
27
31
|
|
28
|
-
def
|
29
|
-
|
32
|
+
def processors_model
|
33
|
+
Facter::Freebsd::FfiHelper.sysctl_by_name(:string, 'hw.model')
|
30
34
|
end
|
31
35
|
|
32
36
|
def logical_count
|
33
|
-
|
37
|
+
Facter::Freebsd::FfiHelper.sysctl_by_name(:uint32_t, 'hw.ncpu')
|
34
38
|
end
|
35
39
|
|
36
|
-
def
|
37
|
-
|
40
|
+
def processors_speed
|
41
|
+
Facter::Freebsd::FfiHelper.sysctl_by_name(:uint32_t, 'hw.clockrate')
|
38
42
|
end
|
39
43
|
end
|
40
44
|
end
|
@@ -16,7 +16,21 @@ module Facter
|
|
16
16
|
def root_device
|
17
17
|
cmdline = Util::FileHelper.safe_read('/proc/cmdline')
|
18
18
|
match = cmdline.match(/root=([^\s]+)/)
|
19
|
-
match&.captures&.first
|
19
|
+
root = match&.captures&.first
|
20
|
+
|
21
|
+
if !root.nil? && root.include?('=')
|
22
|
+
# We are dealing with the PARTUUID of the partition. Need to extract partition path.
|
23
|
+
root_partition_path = convert_partuuid_to_path(root)
|
24
|
+
root = root_partition_path unless root_partition_path.nil?
|
25
|
+
end
|
26
|
+
root
|
27
|
+
end
|
28
|
+
|
29
|
+
def convert_partuuid_to_path(root)
|
30
|
+
blkid_content = Facter::Core::Execution.execute('blkid', logger: log)
|
31
|
+
partuuid = root.split('=').last
|
32
|
+
match = blkid_content.match(/(.+)#{partuuid}/)
|
33
|
+
match&.captures&.first&.split(':')&.first
|
20
34
|
end
|
21
35
|
|
22
36
|
def compute_device(device)
|
@@ -26,36 +40,47 @@ module Facter
|
|
26
40
|
device
|
27
41
|
end
|
28
42
|
|
29
|
-
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
30
43
|
def read_mounts(fact_name)
|
31
44
|
mounts = []
|
32
|
-
FilesystemHelper.read_mountpoints.each do |
|
33
|
-
|
34
|
-
|
35
|
-
path = fs.mount_point
|
36
|
-
options = fs.options.split(',').map(&:strip)
|
37
|
-
|
38
|
-
next if path =~ %r{^/(proc|sys)} && filesystem != 'tmpfs' || filesystem == 'autofs'
|
45
|
+
FilesystemHelper.read_mountpoints.each do |file_system|
|
46
|
+
mount = {}
|
47
|
+
get_mount_data(file_system, mount)
|
39
48
|
|
40
|
-
|
41
|
-
size_bytes = stats.bytes_total.abs
|
42
|
-
available_bytes = stats.bytes_available.abs
|
49
|
+
next if mount[:path] =~ %r{^/(proc|sys)} && mount[:filesystem] != 'tmpfs' || mount[:filesystem] == 'autofs'
|
43
50
|
|
44
|
-
|
45
|
-
|
46
|
-
capacity = FilesystemHelper.compute_capacity(used_bytes, total_bytes)
|
47
|
-
|
48
|
-
size = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(size_bytes)
|
49
|
-
available = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(available_bytes)
|
50
|
-
used = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(used_bytes)
|
51
|
-
|
52
|
-
mounts << Hash[FilesystemHelper::MOUNT_KEYS.zip(FilesystemHelper::MOUNT_KEYS
|
53
|
-
.map { |v| binding.local_variable_get(v) })]
|
51
|
+
get_mount_sizes(mount)
|
52
|
+
mounts << mount
|
54
53
|
end
|
54
|
+
|
55
55
|
@fact_list[:mountpoints] = mounts
|
56
56
|
@fact_list[fact_name]
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
|
+
def get_mount_data(file_system, mount)
|
60
|
+
mount[:device] = compute_device(file_system.name)
|
61
|
+
mount[:filesystem] = file_system.mount_type
|
62
|
+
mount[:path] = file_system.mount_point
|
63
|
+
mount[:options] = file_system.options.split(',').map(&:strip)
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_mount_sizes(mount)
|
67
|
+
stats = FilesystemHelper.read_mountpoint_stats(mount[:path])
|
68
|
+
|
69
|
+
get_bytes_data(mount, stats)
|
70
|
+
|
71
|
+
total_bytes = mount[:used_bytes] + mount[:available_bytes]
|
72
|
+
mount[:capacity] = FilesystemHelper.compute_capacity(mount[:used_bytes], total_bytes)
|
73
|
+
|
74
|
+
mount[:size] = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(mount[:size_bytes])
|
75
|
+
mount[:available] = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(mount[:available_bytes])
|
76
|
+
mount[:used] = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(mount[:used_bytes])
|
77
|
+
end
|
78
|
+
|
79
|
+
def get_bytes_data(mount, stats)
|
80
|
+
mount[:size_bytes] = stats.bytes_total.abs
|
81
|
+
mount[:available_bytes] = stats.bytes_available.abs
|
82
|
+
mount[:used_bytes] = stats.bytes_used.abs
|
83
|
+
end
|
59
84
|
end
|
60
85
|
end
|
61
86
|
end
|
@@ -15,98 +15,122 @@ module Facter
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def read_partitions(fact_name)
|
18
|
-
|
19
|
-
return {} unless File.readable?(BLOCK_PATH)
|
18
|
+
return unless File.readable?(BLOCK_PATH)
|
20
19
|
|
21
20
|
block_devices = Dir.entries(BLOCK_PATH).reject { |dir| dir =~ /^\.+/ }
|
21
|
+
@fact_list[:partitions] = {} unless block_devices.empty?
|
22
|
+
blkid_and_lsblk = {}
|
23
|
+
|
22
24
|
block_devices.each do |block_device|
|
23
25
|
block_path = "#{BLOCK_PATH}/#{block_device}"
|
24
26
|
if File.directory?("#{block_path}/device")
|
25
|
-
extract_from_device(block_path)
|
27
|
+
extract_from_device(block_path, blkid_and_lsblk)
|
26
28
|
elsif File.directory?("#{block_path}/dm")
|
27
|
-
extract_from_dm(block_path)
|
29
|
+
extract_from_dm(block_path, block_device, blkid_and_lsblk)
|
28
30
|
elsif File.directory?("#{block_path}/loop")
|
29
|
-
extract_from_loop(block_path)
|
31
|
+
extract_from_loop(block_path, block_device, blkid_and_lsblk)
|
30
32
|
end
|
31
33
|
end
|
34
|
+
|
32
35
|
@fact_list[fact_name]
|
33
36
|
end
|
34
37
|
|
35
|
-
def extract_from_device(block_path)
|
38
|
+
def extract_from_device(block_path, blkid_and_lsblk)
|
36
39
|
subdirs = browse_subdirectories(block_path)
|
37
40
|
subdirs.each do |subdir|
|
38
41
|
name = "/dev/#{subdir.split('/').last}"
|
39
|
-
populate_partitions(name, subdir)
|
42
|
+
populate_partitions(name, subdir, blkid_and_lsblk)
|
40
43
|
end
|
41
44
|
end
|
42
45
|
|
43
|
-
def extract_from_dm(block_path)
|
46
|
+
def extract_from_dm(block_path, block_device, blkid_and_lsblk)
|
44
47
|
map_name = Util::FileHelper.safe_read("#{block_path}/dm/name").chomp
|
45
48
|
if map_name.empty?
|
46
|
-
populate_partitions("/dev
|
49
|
+
populate_partitions("/dev/#{block_device}", block_path, blkid_and_lsblk)
|
47
50
|
else
|
48
|
-
populate_partitions("/dev/mapper/#{map_name}", block_path)
|
51
|
+
populate_partitions("/dev/mapper/#{map_name}", block_path, blkid_and_lsblk)
|
49
52
|
end
|
50
53
|
end
|
51
54
|
|
52
|
-
def extract_from_loop(block_path)
|
55
|
+
def extract_from_loop(block_path, block_device, blkid_and_lsblk)
|
53
56
|
backing_file = Util::FileHelper.safe_read("#{block_path}/loop/backing_file").chomp
|
54
57
|
if backing_file.empty?
|
55
|
-
populate_partitions("/dev
|
58
|
+
populate_partitions("/dev/#{block_device}", block_path, blkid_and_lsblk)
|
56
59
|
else
|
57
|
-
populate_partitions("/dev
|
60
|
+
populate_partitions("/dev/#{block_device}", block_path, blkid_and_lsblk, backing_file)
|
58
61
|
end
|
59
62
|
end
|
60
63
|
|
61
|
-
def populate_partitions(partition_name, block_path, backing_file = nil)
|
62
|
-
@fact_list[:partitions][partition_name] = {}
|
64
|
+
def populate_partitions(partition_name, block_path, blkid_and_lsblk, backing_file = nil)
|
63
65
|
size_bytes = Util::FileHelper.safe_read("#{block_path}/size", '0')
|
64
66
|
.chomp.to_i * BLOCK_SIZE
|
65
67
|
info_hash = { size_bytes: size_bytes,
|
66
68
|
size: Facter::FactsUtils::UnitConverter.bytes_to_human_readable(size_bytes),
|
67
69
|
backing_file: backing_file }
|
68
|
-
info_hash.merge!(populate_from_syscalls(partition_name))
|
70
|
+
info_hash.merge!(populate_from_syscalls(partition_name, blkid_and_lsblk))
|
69
71
|
@fact_list[:partitions][partition_name] = info_hash.reject { |_key, value| value.nil? }
|
70
72
|
end
|
71
73
|
|
72
|
-
def populate_from_syscalls(partition_name)
|
73
|
-
part_info = populate_from_blkid(partition_name)
|
74
|
+
def populate_from_syscalls(partition_name, blkid_and_lsblk)
|
75
|
+
part_info = populate_from_blkid(partition_name, blkid_and_lsblk)
|
74
76
|
|
75
|
-
return
|
77
|
+
return populate_from_lsblk(partition_name, blkid_and_lsblk) if part_info.empty?
|
76
78
|
|
77
79
|
part_info
|
78
80
|
end
|
79
81
|
|
80
|
-
def
|
81
|
-
|
82
|
+
def browse_subdirectories(path)
|
83
|
+
dirs = Dir[File.join(path, '**', '*')].select { |p| File.directory? p }
|
84
|
+
dirs.select { |subdir| subdir.split('/').last.include?(path.split('/').last) }.reject(&:nil?)
|
85
|
+
end
|
86
|
+
|
87
|
+
def populate_from_blkid(partition_name, blkid_and_lsblk)
|
88
|
+
return {} unless available?('blkid', blkid_and_lsblk)
|
89
|
+
|
90
|
+
blkid_and_lsblk[:blkid] ||= execute_and_extract_blkid_info
|
82
91
|
|
83
|
-
|
84
|
-
return {} unless
|
92
|
+
partition_data = blkid_and_lsblk[:blkid][partition_name]
|
93
|
+
return {} unless partition_data
|
94
|
+
|
95
|
+
filesys = partition_data['TYPE']
|
96
|
+
uuid = partition_data['UUID']
|
97
|
+
label = partition_data['LABEL']
|
98
|
+
part_uuid = partition_data['PARTUUID']
|
99
|
+
part_label = partition_data['PARTLABEL']
|
85
100
|
|
86
|
-
filesys = @blkid_content[partition_name]['TYPE']
|
87
|
-
uuid = @blkid_content[partition_name]['UUID']
|
88
|
-
label = @blkid_content[partition_name]['LABEL']
|
89
|
-
part_uuid = @blkid_content[partition_name]['PARTUUID']
|
90
|
-
part_label = @blkid_content[partition_name]['PARTLABEL']
|
91
101
|
{ filesystem: filesys, uuid: uuid, label: label, partuuid: part_uuid, partlabel: part_label }
|
92
102
|
end
|
93
103
|
|
94
|
-
def
|
95
|
-
|
104
|
+
def available?(command, blkid_and_lsblk)
|
105
|
+
command_exists_key = command == 'blkid' ? :blkid_exists : :lsblk_exists
|
106
|
+
|
107
|
+
return blkid_and_lsblk[command_exists_key] unless blkid_and_lsblk[command_exists_key].nil?
|
96
108
|
|
97
|
-
output = Facter::Core::Execution.execute(
|
109
|
+
output = Facter::Core::Execution.execute("which #{command}", logger: log)
|
98
110
|
|
99
|
-
|
111
|
+
blkid_and_lsblk[:command_exists_key] = !output.empty?
|
100
112
|
end
|
101
113
|
|
102
|
-
def
|
103
|
-
|
114
|
+
def execute_and_extract_blkid_info
|
115
|
+
stdout = Facter::Core::Execution.execute('blkid', logger: log)
|
116
|
+
output_hash = Hash[*stdout.split(/^([^:]+):/)[1..-1]]
|
117
|
+
output_hash.each do |key, value|
|
118
|
+
output_hash[key] = Hash[*value.delete('"').chomp.rstrip.split(/ ([^= ]+)=/)[1..-1]]
|
119
|
+
end
|
120
|
+
end
|
104
121
|
|
105
|
-
|
122
|
+
def populate_from_lsblk(partition_name, blkid_and_lsblk)
|
123
|
+
return {} unless available?('lsblk', blkid_and_lsblk)
|
106
124
|
|
107
|
-
|
125
|
+
blkid_and_lsblk[:lsblk] ||= Facter::Core::Execution.execute('lsblk -fp', logger: log)
|
126
|
+
|
127
|
+
part_info = blkid_and_lsblk[:lsblk].match(/#{partition_name}.*/).to_s.split(' ')
|
108
128
|
return {} if part_info.empty?
|
109
129
|
|
130
|
+
parse_part_info(part_info)
|
131
|
+
end
|
132
|
+
|
133
|
+
def parse_part_info(part_info)
|
110
134
|
result = { filesystem: part_info[1] }
|
111
135
|
|
112
136
|
if part_info.count.eql?(5)
|
@@ -118,27 +142,6 @@ module Facter
|
|
118
142
|
|
119
143
|
result
|
120
144
|
end
|
121
|
-
|
122
|
-
def lsblk_command?
|
123
|
-
return @lsblk_exists unless @lsblk_exists.nil?
|
124
|
-
|
125
|
-
output = Facter::Core::Execution.execute('which lsblk', logger: log)
|
126
|
-
|
127
|
-
@lsblk_exists = !output.empty?
|
128
|
-
end
|
129
|
-
|
130
|
-
def execute_and_extract_blkid_info
|
131
|
-
stdout = Facter::Core::Execution.execute('blkid', logger: log)
|
132
|
-
output_hash = Hash[*stdout.split(/^([^:]+):/)[1..-1]]
|
133
|
-
output_hash.each do |key, value|
|
134
|
-
output_hash[key] = Hash[*value.delete('"').chomp.rstrip.split(/ ([^= ]+)=/)[1..-1]]
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
def browse_subdirectories(path)
|
139
|
-
dirs = Dir[File.join(path, '**', '*')].select { |p| File.directory? p }
|
140
|
-
dirs.select { |subdir| subdir.split('/').last.include?(path.split('/').last) }.reject(&:nil?)
|
141
|
-
end
|
142
145
|
end
|
143
146
|
end
|
144
147
|
end
|