Skip to content

Commit de501bc

Browse files
author
Gerard Hickey
committed
Enhancements and comments for cpu fact generation
1 parent 90212a1 commit de501bc

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

hanlon_microkernel/facter/hnl_mk_cpu.rb

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
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.
54
#
65
#
76

@@ -13,28 +12,22 @@
1312
require 'facter'
1413

1514

16-
1715
virtual_type = Facter.value('virtual')
1816
lshw_cmd = (virtual_type && virtual_type == 'kvm') ? 'lshw -disable dmi' : 'lshw'
1917
lshw_c_cpu_str = %x[sudo #{lshw_cmd} -c cpu 2> /dev/null]
2018

21-
# build the results into a Hash
22-
results = {}
19+
# process the results from lshw -c cpu
2320
lshw_c_cpu_str.split(/\s\s\*-/).each do |definition|
2421
unless definition.empty?
2522
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)
2726
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
3831
end
3932
end
4033
end
@@ -47,10 +40,9 @@
4740
%x[lscpu].split(/\n/).each do |line|
4841
line =~ /^([^:]+):\s*(.*)\s*$/
4942
if $1
50-
key = $1
43+
# map out chars that should not be part of the key
44+
key = $1.tr(' ', '_').tr('()', '')
5145
val = $2
52-
key.tr!(' ', '_')
53-
key.tr!('()', '')
5446
if facts_to_report.include? key
5547
Facter.add("mk_hw_lscpu_#{key}") do
5648
setcode { val }

0 commit comments

Comments
 (0)