Class: Specinfra::HostInventory::Cpu

Inherits:
Base
  • Object
show all
Defined in:
lib/specinfra/host_inventory/cpu.rb

Instance Method Summary collapse

Methods inherited from Base

#backend, #initialize

Constructor Details

This class inherits a constructor from Specinfra::HostInventory::Base

Instance Method Details

#getObject



4
5
6
7
8
9
10
11
12
# File 'lib/specinfra/host_inventory/cpu.rb', line 4

def get
  cmd = backend.command.get(:get_inventory_cpu)
  ret = backend.run_command(cmd)
  if ret.exit_status == 0
     parse(ret.stdout)
  else
     nil
  end
end

#parse(cmd_ret) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/specinfra/host_inventory/cpu.rb', line 13

def parse(cmd_ret)
  cpuinfo = {}
  cpus = cmd_ret.split(/[^^]processor/)
  cpuinfo['total'] = cpus.length.to_s
  cpus.each_with_index do |cpu, idx|
    idx = idx.to_s
    cpuinfo[idx] = {}
    cpu.each_line do |line|
      case line
      when /^vendor_id\s*:\s+(.+)$/
        cpuinfo[idx]['vendor_id'] = $1
      when /^cpu family\s*:\s+(\d+)$/
        cpuinfo[idx]['cpu_family'] = $1
      when /^model\s*:\s+(\d+)$/
        cpuinfo[idx]['model'] = $1
      when /^model\sname\s*:\s+(.+)$/
        cpuinfo[idx]['model_name'] = $1
      when /^stepping\s*:\s+(\d+)$/
        cpuinfo[idx]['stepping'] = $1
      when /^microcode\s*:\s+(.+)$/
        cpuinfo[idx]['microcode'] = $1
      when /^cpu MHz\s*:\s+(.+)$/
        cpuinfo[idx]['cpu_mhz'] = $1
      when /^cache size\s*:\s+(\d+) (.+)$/
        cpuinfo[idx]['cache_size'] = "#{$1}#{$2}"
      when /^physical id\s*:\s+(\d+)$/
        cpuinfo[idx]['physical_id'] = $1
      when /^siblings\s*:\s+(\d+)$/
        cpuinfo[idx]['siblings'] = $1
      when /^core id\s*:\s+(\d+)$/
        cpuinfo[idx]['core_id'] = $1
      when /^cpu cores\s*:\s+(\d+)$/
        cpuinfo[idx]['cpu_cores'] = $1
      when /^apicid\s*:\s+(\d+)$/
        cpuinfo[idx]['apicid'] = $1
      when /^initial apicid\s*:\s+(\d+)$/
        cpuinfo[idx]['initial_apicid'] = $1
      when /^fpu\s*:\s+(.+)$/
        cpuinfo[idx]['fpu'] = $1
      when /^fpu_exception\s*:\s+(.+)$/
        cpuinfo[idx]['fpu_exception'] = $1
      when /^cpuid level\s*:\s+(\d+)$/
        cpuinfo[idx]['cpuid_level'] = $1
      when /^wp\s*:\s+(.+)$/
        cpuinfo[idx]['wp'] = $1
      when /^flags\s*:\s+(.+)$/
        cpuinfo[idx]['flags'] = $1.split(/\s/)
      when /^bogomips\s*:\s+(.+)$/
        cpuinfo[idx]['bogomips'] = $1
      when /^clflush size\s*:\s+(\d+)$/
        cpuinfo[idx]['clflush_size'] = $1
      when /^cache_alignment\s*:\s+(\d+)$/
        cpuinfo[idx]['cache_alignment'] = $1
      when /^address sizes\s*:\s+(.+)$/
        cpuinfo[idx]['address_sizes'] = $1
      when /^power management\s*:\s+(.*)$/
        cpuinfo[idx]['power_management'] = $1
      end
    end
  end
  cpuinfo
end