Skip to content

Commit 68921f8

Browse files
author
Gerard Hickey
committed
Facter module for gathering system bus facts
1 parent bf63e84 commit 68921f8

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Gathers hardware-related facts from the underlying system (used by the
2+
# hnl_mk_registration_manager to gather these sorts of facts in order to
3+
# supplement the facts gathered using Facter during the node registration
4+
# process)
5+
#
6+
#
7+
8+
# add the '/usr/local/lib/ruby' directory to the LOAD_PATH
9+
# (this is where the hanlon_microkernel module files are placed by
10+
# our Dockerfile)
11+
$LOAD_PATH.unshift('/usr/local/lib/ruby')
12+
13+
require 'facter'
14+
15+
16+
17+
virtual_type = Facter.value('virtual')
18+
lshw_cmd = (virtual_type && virtual_type == 'kvm') ? 'lshw -disable dmi' : 'lshw'
19+
lshw_c_bus_str = %x[sudo #{lshw_cmd} -c bus 2> /dev/null]
20+
21+
# build the results into a Hash
22+
results = {}
23+
lshw_c_bus_str.split(/\s\s\*-/).each do |definition|
24+
unless definition.empty?
25+
lines = definition.split(/\n/)
26+
item = lines.shift.tr(':', '')
27+
attribs = Hash[ lines.collect { |l| l =~ /^\s*([^:]+):\s+(.*)\s*$/; [$1, $2] } ]
28+
results[item] = attribs
29+
end
30+
end
31+
32+
33+
# report out the core values
34+
%w{description product vendor version serial physical_id}.each do |fact|
35+
Facter.add("mk_hw_bus_#{fact}") do
36+
setcode { results['core'][fact] }
37+
end
38+
end
39+
40+
# now report the rest of the bus information
41+
results.delete('core')
42+
results.keys.each do |bus|
43+
results[bus].each do |attrib, val|
44+
Facter.add("mk_hw_bus_#{bus}_#{attrib}") do
45+
setcode { val }
46+
end
47+
end
48+
end

0 commit comments

Comments
 (0)