Class: Yast2::HwDetection

Inherits:
Object
  • Object
show all
Includes:
Yast::Logger
Defined in:
library/system/src/lib/yast2/hw_detection.rb

Overview

Module for detecting hardware

Constant Summary

MEMORY_CLASS =

this is from <hd.h> include (in hwinfo-devel)

257
MEMORY_SUBCLASS =

“bc_internal” value

2

Class Method Summary collapse

Class Method Details

.memoryObject

Return size of the system memory (in bytes)



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'library/system/src/lib/yast2/hw_detection.rb', line 42

def self.memory
  memory = Yast::SCR.Read(Yast::Path.new(".probe.memory"))
  log.debug("hwinfo memory: #{memory}")

  raise "Memory detection failed" unless memory

  memory_size = 0
  memory.each do |info|
    # internal class, main memory
    next if info["class_id"] != MEMORY_CLASS || info["sub_class_id"] != MEMORY_SUBCLASS

    info.fetch("resource", {}).fetch("phys_mem", []).each do |phys_mem|
      memory_size += phys_mem.fetch("range", 0)
    end
  end

  log.info("Detected memory size: #{memory_size} (#{memory_size / 1024 / 1024}MiB)")
  memory_size
end