Add unallocated_pvs fact to the disk_management module
This change adds a custom fact named 'unallocated_pvs' to the disk_management module. It returns the array of disk partitions that are flagged as LVM partitions but not yet configured as physical volumes by LVM. Change-Id: I7d7fc5102cc208d95a9de6353f2a37f138026ea5
This commit is contained in:
parent
332cc352e4
commit
302599edd4
|
@ -0,0 +1,24 @@
|
|||
# Return the list of LVM disk partition that haven't been allocated yet
|
||||
unallocated_pvs = []
|
||||
|
||||
# Enumerate disk devices
|
||||
devices = Dir.entries('/sys/block/').select do |d|
|
||||
File.exist?( "/sys/block/#{ d }/device" )
|
||||
end
|
||||
|
||||
devices.each do |device|
|
||||
device = "/dev/#{ device }"
|
||||
# Filter only partitions flagged as LVM
|
||||
lvm_partitions = Facter::Util::Resolution.exec(
|
||||
"parted -s -m #{ device } print 2>/dev/null").scan(/^(\d+):.+:lvm;$/).flatten
|
||||
lvm_partitions.each do |x|
|
||||
# Filter only partitions which haven't been created yet
|
||||
pvs = Facter::Util::Resolution.exec(
|
||||
"pvs --noheadings #{ device }#{ x } 2>/dev/null")
|
||||
if pvs.nil? then
|
||||
unallocated_pvs.push("#{ device }#{ x }")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Facter.add("unallocated_pvs") { setcode { unallocated_pvs } }
|
Loading…
Reference in New Issue