Skip to content

Commit 90c990b

Browse files
author
Gerard Hickey
committed
Added counting facts to cpu, disk and nic modules
1 parent 01ae9e5 commit 90c990b

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

hanlon_microkernel/facter/hnl_mk_cpu.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
lshw_c_cpu_str = %x[sudo #{lshw_cmd} -c cpu 2> /dev/null]
1818

1919
# process the results from lshw -c cpu
20+
cpus = 0
2021
lshw_c_cpu_str.split(/\s\s\*-/).each do |definition|
2122
unless definition.empty?
2223
lines = definition.split(/\n/)
2324
# section title is on the first line
2425
cpu = lines.shift.tr(':', '')
26+
cpus += 1
2527
# Create a hash of attributes for each section (i.e. cpu)
2628
attribs = Hash[ lines.collect { |l| l =~ /^\s*([^:]+):\s+(.*)\s*$/; v=$2; [$1.gsub(/\s/, '_'), v] } ]
2729
attribs.each_pair do |attrib, val|
@@ -32,6 +34,10 @@
3234
end
3335
end
3436

37+
# report on the number of CPUs
38+
Facter.add("mk_hw_cpu_count") do
39+
setcode { cpus }
40+
end
3541

3642
# process the results from lscpu
3743
facts_to_report = %w{Architecture BogoMIPS Byte_Order CPU_MHz CPU_family CPU_op-modes

hanlon_microkernel/facter/hnl_mk_disk.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
lshw_c_disk_str = %x[sudo #{lshw_cmd} -c disk 2> /dev/null]
1818

1919
# process the results from lshw -c disk
20+
disks = 0
2021
lshw_c_disk_str.split(/\s\s\*-/).each do |definition|
2122
unless definition.empty?
2223
lines = definition.split(/\n/)
2324
# section title is on the first line
2425
disk = lines.shift.tr(':', '')
26+
disks += 1
2527
# Create a hash of attributes for each section (i.e. cpu)
2628
attribs = Hash[ lines.collect { |l| l =~ /^\s*([^:]+):\s+(.*)\s*$/; v=$2; [$1.gsub(/\s/, '_'), v] } ]
2729
attribs.each_pair do |attrib, val|
@@ -31,3 +33,7 @@
3133
end
3234
end
3335
end
36+
37+
Facter.add("mk_hw_disk_count") do
38+
setcode { disks }
39+
end

hanlon_microkernel/facter/hnl_mk_nic.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
lshw_c_network_str = %x[sudo #{lshw_cmd} -c network 2> /dev/null]
1818

1919
# process the results from lshw -c network
20+
nics = 0
2021
lshw_c_network_str.split(/\s\s\*-/).each do |definition|
2122
unless definition.empty?
2223
lines = definition.split(/\n/)
2324
# section title is on the first line
2425
network = lines.shift.tr(':', '')
26+
nics += 1
2527
# Create a hash of attributes for each section (i.e. cpu)
2628
attribs = Hash[ lines.collect { |l| l =~ /^\s*([^:]+):\s+(.*)\s*$/; v=$2; [$1.gsub(/\s/, '_'), v] } ]
2729
attribs.each_pair do |attrib, val|
@@ -31,3 +33,8 @@
3133
end
3234
end
3335
end
36+
37+
# report on the number NICs found
38+
Facter.add("mk_hw_nic_count") do
39+
setcode { nics }
40+
end

0 commit comments

Comments
 (0)