Sha256: f2433be1eda827279eb7404e6aff87d9128eb34da6b961c62238b0f32af121e6

Contents?: true

Size: 1.18 KB

Versions: 7

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    module Linux
      class Lscpu < BaseResolver
        init_resolver

        ITEMS = { threads_per_core: "-e 'Thread(s)'",
                  cores_per_socket: "-e 'Core(s)'" }.freeze

        class << self
          # :cores_per_socket
          # :threads_per_core

          private

          def post_resolve(fact_name, _options)
            @fact_list.fetch(fact_name) { read_cpuinfo(fact_name) }
          end

          def read_cpuinfo(fact_name)
            lscpu_output = Facter::Core::Execution.execute("lscpu | grep #{ITEMS.values.join(' ')}", logger: log)
            build_fact_list(lscpu_output.split("\n"))
            @fact_list[fact_name]
          end

          def build_fact_list(processors_data)
            build_threads_per_core(processors_data[0])
            build_cores_per_socket(processors_data[1])
          end

          def build_threads_per_core(index)
            @fact_list[:threads_per_core] = index.split(': ')[1].to_i
          end

          def build_cores_per_socket(index)
            @fact_list[:cores_per_socket] = index.split(': ')[1].to_i
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
facter-4.10.0 lib/facter/resolvers/processors_lscpu.rb
facter-4.9.0 lib/facter/resolvers/processors_lscpu.rb
facter-4.8.0 lib/facter/resolvers/processors_lscpu.rb
facter-4.7.1 lib/facter/resolvers/processors_lscpu.rb
facter-4.7.0 lib/facter/resolvers/processors_lscpu.rb
facter-4.6.1 lib/facter/resolvers/processors_lscpu.rb
facter-4.6.0 lib/facter/resolvers/processors_lscpu.rb