Sha256: 4f32cf8051485663a19832e3200da449df833b2fd61283099e121571b2b34adb

Contents?: true

Size: 1.95 KB

Versions: 6

Compression:

Stored size: 1.95 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    class Processors < BaseResolver
      @log = Facter::Log.new(self)
      @semaphore = Mutex.new
      @fact_list ||= {}
      class << self
        # Count
        # Isa
        # Models
        # PhysicalCount

        private

        def post_resolve(fact_name)
          @fact_list.fetch(fact_name) { read_fact_from_win32_processor(fact_name) }
        end

        def read_fact_from_win32_processor(fact_name)
          win = Win32Ole.new
          proc = win.exec_query('SELECT Name,Architecture,NumberOfLogicalProcessors FROM Win32_Processor')
          unless proc
            @log.debug 'WMI query returned no results'\
            'for Win32_Processor with values Name, Architecture and NumberOfLogicalProcessors.'
            return
          end
          result = iterate_proc(proc)
          build_fact_list(result)
          @fact_list[fact_name]
        end

        def iterate_proc(result)
          models = []
          isa = nil
          logical_count = 0
          result.each do |proc|
            models << proc.Name
            logical_count += proc.NumberOfLogicalProcessors if proc.NumberOfLogicalProcessors
            isa ||= find_isa(proc.Architecture)
          end

          { models: models, isa: isa, logical_count: logical_count.zero? ? models.count : logical_count }
        end

        def find_isa(arch)
          architecture_hash =
            { 0 => 'x86', 1 => 'MIPS', 2 => 'Alpha', 3 => 'PowerPC', 5 => 'ARM', 6 => 'Itanium', 9 => 'x64' }
          isa = architecture_hash[arch]
          return isa if isa

          @log.debug 'Unable to determine processor type: unknown architecture'
        end

        def build_fact_list(result)
          @fact_list[:count] = result[:logical_count]
          @fact_list[:isa] = result[:isa]
          @fact_list[:models] = result[:models]
          @fact_list[:physicalcount] = result[:models].size
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
facter-4.0.12 lib/resolvers/windows/processors_resolver.rb
facter-4.0.11 lib/resolvers/windows/processors_resolver.rb
facter-4.0.10.pre lib/resolvers/windows/processors_resolver.rb
facter-4.0.9.pre lib/resolvers/windows/processors_resolver.rb
facter-4.0.8.pre lib/resolvers/windows/processors_resolver.rb
facter-4.0.7.pre lib/resolvers/windows/processors_resolver.rb