-
Notifications
You must be signed in to change notification settings - Fork 276
/
Copy pathlvm_support.rb
66 lines (59 loc) · 1.4 KB
/
lvm_support.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# lvm_support: true/nil
# Whether there is LVM support (based on the presence of the "vgs" command)
Facter.add('lvm_support') do
confine :kernel => :linux
setcode do
vgdisplay = Facter::Util::Resolution.which('vgs')
vgdisplay.nil? ? nil : true
end
end
# lvm_vgs: [0-9]+
# Number of VGs
vg_list = []
Facter.add('lvm_vgs') do
confine :lvm_support => true
setcode do
vgs = Facter::Core::Execution.execute('vgs -o name --noheadings 2>/dev/null', timeout: 30)
if vgs.nil?
0
else
vg_list = vgs.split
vg_list.length
end
end
end
# lvm_vg_[0-9]+
# VG name by index
vg_list.each_with_index do |vg, i|
setcode do
Facter.add("lvm_vg_#{i}") { vg }
Facter.add("lvm_vg_#{vg}_pvs") do
pvs = Facter::Core::Execution.execute("vgs -o pv_name #{vg} 2>/dev/null", timeout: 30)
res = nil
unless pvs.nil?
res = pvs.split("\n").select{|l| l =~ /^\s+\// }.collect(&:strip).sort.join(',')
end
res
end
end
end
# lvm_pvs: [0-9]+
# Number of PVs
pv_list = []
Facter.add('lvm_pvs') do
confine :lvm_support => true
setcode do
pvs = Facter::Core::Execution.execute('pvs -o name --noheadings 2>/dev/null', timeout: 30)
if pvs.nil?
0
else
pv_list = pvs.split
pv_list.length
end
end
end
# lvm_pv_[0-9]+
# PV name by index
pv_list.each_with_index do |pv, i|
Facter.add("lvm_pv_#{i}") { setcode { pv } }
end