Skip to content

Commit

Permalink
(FACT-3140) Include partition type uuid for GPT based systems
Browse files Browse the repository at this point in the history
  • Loading branch information
jcpunk committed May 24, 2024
1 parent 2ab655b commit 02c737b
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions lib/facter/resolvers/partitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ def execute_and_extract_blkid_info
def populate_from_lsblk(partition_name, blkid_and_lsblk)
return {} unless available?('lsblk', blkid_and_lsblk)

blkid_and_lsblk[:lsblk] ||= Facter::Core::Execution.execute('lsblk -fp', logger: log)
lsblk_version_raw = Facter::Core::Execution.execute('lsblk --version 2>&1', logger: log)
lsblk_version = lsblk_version_raw.match(/ \d\.\d+/)[0].to_f
blkid_and_lsblk[:lsblk] ||= if lsblk_version >= 2.25
Facter::Core::Execution.execute('lsblk -p -P -o NAME,FSTYPE,LABEL,UUID,PARTTYPE', logger: log)
else
Facter::Core::Execution.execute('lsblk -p -P -o NAME,FSTYPE,LABEL,UUID', logger: log)
end

part_info = blkid_and_lsblk[:lsblk].match(/#{partition_name}.*/).to_s.split(' ')
return {} if part_info.empty?
Expand All @@ -130,13 +136,21 @@ def populate_from_lsblk(partition_name, blkid_and_lsblk)
end

def parse_part_info(part_info)
result = { filesystem: part_info[1] }

if part_info.count.eql?(5)
result[:label] = part_info[2]
result[:uuid] = part_info[3]
else
result[:uuid] = part_info[2]
result = {}

part_info.each do |setting|
simple_string = setting.delete('"')
key, value = simple_string.split('=')
case key
when 'FSTYPE'
result['filesystem'] = value
when 'LABEL'
result['label'] = value
when 'UUID'
result['uuid'] = value
when 'PARTTYPE'
result['type_uuid'] = value
end
end

result
Expand Down

0 comments on commit 02c737b

Please sign in to comment.