Skip to content

Commit 90212a1

Browse files
author
Gerard Hickey
committed
Facter modlue for gathering disk facts
1 parent cc39d27 commit 90212a1

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Gathers hardware-related facts from the underlying system pertaining
2+
# to the processors. Information gathered here is exposed directly as
3+
# Facter facts for the purpose of node registration.
4+
#
5+
#
6+
7+
# add the '/usr/local/lib/ruby' directory to the LOAD_PATH
8+
# (this is where the hanlon_microkernel module files are placed by
9+
# our Dockerfile)
10+
$LOAD_PATH.unshift('/usr/local/lib/ruby')
11+
12+
require 'facter'
13+
14+
15+
virtual_type = Facter.value('virtual')
16+
lshw_cmd = (virtual_type && virtual_type == 'kvm') ? 'lshw -disable dmi' : 'lshw'
17+
lshw_c_disk_str = %x[sudo #{lshw_cmd} -c disk 2> /dev/null]
18+
19+
# process the results from lshw -c disk
20+
lshw_c_disk_str.split(/\s\s\*-/).each do |definition|
21+
unless definition.empty?
22+
lines = definition.split(/\n/)
23+
# section title is on the first line
24+
disk = lines.shift.tr(':', '')
25+
# Create a hash of attributes for each section (i.e. cpu)
26+
attribs = Hash[ lines.collect { |l| l =~ /^\s*([^:]+):\s+(.*)\s*$/; v=$2; [$1.gsub(/\s/, '_'), v] } ]
27+
attribs.each_pair do |attrib, val|
28+
Facter.add("mk_hw_#{disk}_#{attrib}") do
29+
setcode { val }
30+
end
31+
end
32+
end
33+
end

0 commit comments

Comments
 (0)