~gandelman-a/ubuntu/precise/facter/merge922788

« back to all changes in this revision

Viewing changes to lib/facter/processor.rb

  • Committer: Package Import Robot
  • Author(s): Adam Gandelman
  • Date: 2011-10-18 10:32:42 UTC
  • mfrom: (1.3.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: package-import@ubuntu.com-20111018103242-ag8i8vejfp8v7b1b
Tags: upstream-1.6.1
ImportĀ upstreamĀ versionĀ 1.6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Fact: processor
 
2
#
 
3
# Purpose:
 
4
#   Additional Facts about the machine's CPUs.
 
5
#
 
6
# Resolution:
 
7
#   On Linux and kFreeBSD, parse '/proc/cpuinfo' for each processor.
 
8
#   On AIX, parse the output of 'lsdev' for it's processor section.
 
9
#   On OpenBSD, use 'uname -p' and the sysctl variable for 'hw.ncpu' for CPU
 
10
#   count.
 
11
#
 
12
# Caveats:
 
13
#
 
14
 
1
15
# processor.rb
2
 
# Additional Facts about the machine's CPUs
3
16
#
4
17
# Copyright (C) 2006 Mooter Media Ltd
5
18
# Author: Matthew Palmer <matt@solutionsfirst.com.au>
91
104
        end
92
105
    end
93
106
end
 
107
 
 
108
if Facter.value(:kernel) == "windows"
 
109
  processor_list = []
 
110
 
 
111
  Thread::exclusive do
 
112
    require 'facter/util/wmi'
 
113
 
 
114
    # get each physical processor
 
115
    Facter::Util::WMI.execquery("select * from Win32_Processor").each do |proc|
 
116
      # not supported before 2008
 
117
      begin
 
118
        processor_num = proc.NumberOfLogicalProcessors
 
119
      rescue RuntimeError => e
 
120
        processor_num = 1
 
121
      end
 
122
 
 
123
      processor_num.times do |i|
 
124
        processor_list << proc.Name.squeeze(" ")
 
125
      end
 
126
    end
 
127
  end
 
128
 
 
129
  processor_list.each_with_index do |name, i|
 
130
    Facter.add("Processor#{i}") do
 
131
      confine :kernel => :windows
 
132
      setcode do
 
133
        name
 
134
      end
 
135
    end
 
136
  end
 
137
 
 
138
  Facter.add("ProcessorCount") do
 
139
    confine :kernel => :windows
 
140
    setcode do
 
141
      processor_list.length.to_s
 
142
    end
 
143
  end
 
144
end