Skip to content

Commit 247ce00

Browse files
author
Gerard Hickey
committed
Added sys Facter module
1 parent 2c10a31 commit 247ce00

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Gathers hardware-related facts from the underlying system pertaining
2+
# to the system. 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_system_str = %x[sudo #{lshw_cmd} -c system 2> /dev/null]
18+
19+
# process the results from lshw -c disk
20+
disks = 0
21+
lshw_c_system_str.split(/\s\s\*-/).each do |definition|
22+
unless definition.empty?
23+
lines = definition.split(/\n/)
24+
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_sys_#{attrib}") do
29+
setcode { val }
30+
end
31+
end
32+
end
33+
end
34+

0 commit comments

Comments
 (0)