Sha256: 0439decf9d9640051b7886c9eedd5872256ed524cb93696572194015291444d1

Contents?: true

Size: 1.9 KB

Versions: 3

Compression:

Stored size: 1.9 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    class Processors < BaseResolver
      init_resolver

      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 = Facter::Util::Windows::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

3 entries across 3 versions & 1 rubygems

Version Path
facter-4.0.49 lib/facter/resolvers/windows/processors.rb
facter-4.0.48 lib/facter/resolvers/windows/processors.rb
facter-4.0.47 lib/facter/resolvers/windows/processors_resolver.rb