facter 4.8.0 → 4.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1b586ac7fd5ca2a0dbba3e314510199c246eeafcf3238d4450429c07662e2ac
4
- data.tar.gz: a3dbb666fd7d0168042df86ba3f85bd5d487a85ed348bf71fc3e0ec2f397a347
3
+ metadata.gz: 97c091ad872480f9a35f8c56682e89b65cd221d2b7da74b6bab229e37e27dda0
4
+ data.tar.gz: c55e4ec6c3e39148ca2c8ce0819eecc4dcf33eddd1ece53442d293eddb405955
5
5
  SHA512:
6
- metadata.gz: 2580f1bb8294a6de8e89402244448362f1657d31db3d9d4d2dba551e103848a5285983fd9f57693d4afc2ea6fd6678d97889490e82c8542d125bddb917fd7c58
7
- data.tar.gz: 8c26e42de115a8b5f3bef1b045b8aff8c18b3f28ab1ca431ea7225f71a97114f7bfaddbc9b9d5ebed7c92225a045d225582cd0d667740ab6beabdcad2c1613da
6
+ metadata.gz: 8d87380c0d913de5c09f664a5b9a7a35a26434ff806b5788c4712b70cfa6bb85e9fa6670e9bd05dbd275a6f87cd20001d620596e97f732b351d05afe9c5a47d7
7
+ data.tar.gz: 5900798a818340f42464fff9eec375d2810157f1b73a143fb0191c342149f92634344a4077589af2c19597d3c984aff673bfcb611b14f59a6438c1f2f27eb232
@@ -43,7 +43,7 @@ module Facter
43
43
 
44
44
  info = {}
45
45
  case container
46
- when 'lxcroot'
46
+ when 'lxc'
47
47
  vm = 'lxc'
48
48
  when 'podman'
49
49
  vm = 'podman'
@@ -54,7 +54,7 @@ module Facter
54
54
  info = { 'id' => Facter::Util::FileHelper.safe_read('/etc/machine-id', nil).strip }
55
55
  else
56
56
  vm = 'container_other'
57
- log.warn("Container runtime, '#{container}', is unsupported, setting to, '#{vm}'")
57
+ log.warn("Container runtime, '#{container}', is unsupported, setting to '#{vm}'")
58
58
  end
59
59
  @fact_list[:vm] = vm
60
60
  @fact_list[:hypervisor] = { vm.to_sym => info } if vm
@@ -69,13 +69,14 @@ module Facter
69
69
  size: Facter::Util::Facts::UnitConverter.bytes_to_human_readable(size_bytes),
70
70
  backing_file: backing_file }
71
71
  info_hash.merge!(populate_from_syscalls(partition_name, blkid_and_lsblk))
72
- @fact_list[:partitions][partition_name] = info_hash.reject { |_key, value| value.nil? }
72
+ @fact_list[:partitions][partition_name] = info_hash.compact
73
73
  end
74
74
 
75
75
  def populate_from_syscalls(partition_name, blkid_and_lsblk)
76
- part_info = populate_from_blkid(partition_name, blkid_and_lsblk)
76
+ # Prefer lsblk over blkid since lsblk does not require root, returns more information, and is recommended by blkid
77
+ part_info = populate_from_lsblk(partition_name, blkid_and_lsblk)
77
78
 
78
- return populate_from_lsblk(partition_name, blkid_and_lsblk) if part_info.empty?
79
+ return populate_from_blkid(partition_name, blkid_and_lsblk) if part_info.empty?
79
80
 
80
81
  part_info
81
82
  end
@@ -121,26 +122,47 @@ module Facter
121
122
  def populate_from_lsblk(partition_name, blkid_and_lsblk)
122
123
  return {} unless available?('lsblk', blkid_and_lsblk)
123
124
 
124
- blkid_and_lsblk[:lsblk] ||= Facter::Core::Execution.execute('lsblk -fp', logger: log)
125
+ lsblk_version_raw = Facter::Core::Execution.execute('lsblk --version 2>&1', logger: log)
126
+ # Return if the version of lsblk is too old (< 2.22) to support the --version flag
127
+ lsblk_version_raw.match?(/ \d\.\d+/) ? lsblk_version = lsblk_version_raw.match(/ \d\.\d+/)[0].to_f : (return {})
125
128
 
126
- part_info = blkid_and_lsblk[:lsblk].match(/#{partition_name}.*/).to_s.split(' ')
127
- return {} if part_info.empty?
129
+ # The -p/--paths option was added in lsblk 2.23, return early and fall back to blkid with earlier versions
130
+ return {} if lsblk_version < 2.23
128
131
 
129
- parse_part_info(part_info)
130
- end
132
+ blkid_and_lsblk[:lsblk] ||= execute_and_extract_lsblk_info(lsblk_version)
131
133
 
132
- def parse_part_info(part_info)
133
- result = { filesystem: part_info[1] }
134
+ partition_data = blkid_and_lsblk[:lsblk][partition_name]
135
+ return {} unless partition_data
134
136
 
135
- if part_info.count.eql?(5)
136
- result[:label] = part_info[2]
137
- result[:uuid] = part_info[3]
138
- else
139
- result[:uuid] = part_info[2]
140
- end
137
+ filesys = partition_data['FSTYPE']
138
+ uuid = partition_data['UUID']
139
+ label = partition_data['LABEL']
140
+ part_uuid = partition_data['PARTUUID']
141
+ part_label = partition_data['PARTLABEL']
142
+ part_type = partition_data['PARTTYPE']
143
+
144
+ result = { filesystem: filesys, uuid: uuid, label: label, partuuid: part_uuid, partlabel: part_label }
145
+ result[:parttype] = part_type if part_type
141
146
 
142
147
  result
143
148
  end
149
+
150
+ def execute_and_extract_lsblk_info(lsblk_version)
151
+ # lsblk 2.25 added support for GPT partition type GUIDs
152
+ stdout = if lsblk_version >= 2.25
153
+ Facter::Core::Execution.execute('lsblk -p -P -o NAME,FSTYPE,UUID,LABEL,PARTUUID,PARTLABEL,PARTTYPE', logger: log)
154
+ else
155
+ Facter::Core::Execution.execute('lsblk -p -P -o NAME,FSTYPE,LABEL,UUID,PARTUUID,PARTLABEL', logger: log)
156
+ end
157
+
158
+ output_hash = Hash[*stdout.split(/^(NAME=\S+)/)[1..-1]]
159
+ output_hash.transform_keys! { |key| key.delete('NAME=')[1..-2] }
160
+ output_hash.each do |key, value|
161
+ output_hash[key] = Hash[*value.chomp.rstrip.split(/ ([^= ]+)=/)[1..-1].each { |x| x.delete!('"') }]
162
+ end
163
+ output_hash.each_value { |value_hash| value_hash.delete_if { |_k, v| v.empty? } }
164
+ output_hash.delete_if { |_k, v| v.empty? }
165
+ end
144
166
  end
145
167
  end
146
168
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Facter
4
- VERSION = '4.8.0' unless defined?(VERSION)
4
+ VERSION = '4.9.0' unless defined?(VERSION)
5
5
  end
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.8.0
4
+ version: 4.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-19 00:00:00.000000000 Z
11
+ date: 2024-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi