diff options
author | luke <luke@1f5c1d6a-bddf-0310-8f58-fc49e503516a> | 2006-05-30 23:44:06 +0000 |
---|---|---|
committer | luke <luke@1f5c1d6a-bddf-0310-8f58-fc49e503516a> | 2006-05-30 23:44:06 +0000 |
commit | 59cea90bd77383b9aa70e9ba41a54428f21b0538 (patch) | |
tree | daef237f6a5cfc4149b6b660c9bbf17836fd457d | |
parent | f3cc5e30a913a9236f6c54e880593ec5a1f8450e (diff) | |
download | facter-59cea90bd77383b9aa70e9ba41a54428f21b0538.tar.gz facter-59cea90bd77383b9aa70e9ba41a54428f21b0538.tar.xz facter-59cea90bd77383b9aa70e9ba41a54428f21b0538.zip |
Adding patch from #11, with slight modifications.
git-svn-id: http://reductivelabs.com/svn/facter/trunk@118 1f5c1d6a-bddf-0310-8f58-fc49e503516a
-rw-r--r-- | lib/facter/processor.rb | 45 | ||||
-rw-r--r-- | tests/tc_simple.rb | 7 |
2 files changed, 52 insertions, 0 deletions
diff --git a/lib/facter/processor.rb b/lib/facter/processor.rb new file mode 100644 index 0000000..bbb476c --- /dev/null +++ b/lib/facter/processor.rb @@ -0,0 +1,45 @@ +# +# processor.rb +# Additional Facts about the machine's CPUs +# +# Copyright (C) 2006 Mooter Media Ltd +# Author: Matthew Palmer <matt@solutionsfirst.com.au> +# +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation (version 2 of the License) +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA +# + +processor_num = -1 +processor_list = [] +File.readlines("/proc/cpuinfo").each do |l| + if l =~ /processor\s+:\s+(\d+)/ + processor_num = $1.to_i + elsif l =~ /model name\s+:\s+(.*)\s*$/ + processor_list[processor_num] = $1 unless processor_num == -1 + processor_num = -1 + end +end + +Facter.add("ProcessorCount") do + setcode do + processor_list.length + end +end + +processor_list.each_with_index do |desc, i| + Facter.add("Processor#{i}") do + tag :kernel => "Linux" + setcode do + desc + end + end +end diff --git a/tests/tc_simple.rb b/tests/tc_simple.rb index 66abf23..9dd847f 100644 --- a/tests/tc_simple.rb +++ b/tests/tc_simple.rb @@ -453,6 +453,13 @@ some random stuff assert(Facter.memorysize, "Did not get memory") } end + + def test_processor_on_linux + assert_nothing_raised { + assert(Facter.processorcount, "Did not get proc count") + assert(Facter.processor0, "Did not get proc 0") + } + end end end |