|
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) |
| 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. |
5 | 4 | #
|
6 | 5 | #
|
7 | 6 |
|
|
13 | 12 | require 'facter'
|
14 | 13 |
|
15 | 14 |
|
16 |
| - |
17 | 15 | virtual_type = Facter.value('virtual')
|
18 | 16 | lshw_cmd = (virtual_type && virtual_type == 'kvm') ? 'lshw -disable dmi' : 'lshw'
|
19 | 17 | lshw_c_cpu_str = %x[sudo #{lshw_cmd} -c cpu 2> /dev/null]
|
20 | 18 |
|
21 |
| -# build the results into a Hash |
22 |
| -results = {} |
| 19 | +# process the results from lshw -c cpu |
23 | 20 | lshw_c_cpu_str.split(/\s\s\*-/).each do |definition|
|
24 | 21 | unless definition.empty?
|
25 | 22 | lines = definition.split(/\n/)
|
26 |
| - item = lines.shift.tr(':', '') |
| 23 | + # section title is on the first line |
| 24 | + cpu = lines.shift.tr(':', '') |
| 25 | + # Create a hash of attributes for each section (i.e. cpu) |
27 | 26 | attribs = Hash[ lines.collect { |l| l =~ /^\s*([^:]+):\s+(.*)\s*$/; v=$2; [$1.gsub(/\s/, '_'), v] } ]
|
28 |
| - results[item] = attribs |
29 |
| - end |
30 |
| -end |
31 |
| - |
32 |
| - |
33 |
| - |
34 |
| -results.keys.each do |cpu| |
35 |
| - results[cpu].each_pair do |k, v| |
36 |
| - Facter.add("mk_hw_#{cpu}_#{k}") do |
37 |
| - setcode { v } |
| 27 | + attribs.each_pair do |attrib, val| |
| 28 | + Facter.add("mk_hw_#{cpu}_#{attrib}") do |
| 29 | + setcode { val } |
| 30 | + end |
38 | 31 | end
|
39 | 32 | end
|
40 | 33 | end
|
|
47 | 40 | %x[lscpu].split(/\n/).each do |line|
|
48 | 41 | line =~ /^([^:]+):\s*(.*)\s*$/
|
49 | 42 | if $1
|
50 |
| - key = $1 |
| 43 | + # map out chars that should not be part of the key |
| 44 | + key = $1.tr(' ', '_').tr('()', '') |
51 | 45 | val = $2
|
52 |
| - key.tr!(' ', '_') |
53 |
| - key.tr!('()', '') |
54 | 46 | if facts_to_report.include? key
|
55 | 47 | Facter.add("mk_hw_lscpu_#{key}") do
|
56 | 48 | setcode { val }
|
|
0 commit comments