Class: Specinfra::HostInventory::BlockDevice

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

Constant Summary collapse

BLOCK_DEVICE_REGEX =

examples:

/sys/block/sda/size	10000
/sys/block/sr0/device/model	CD-ROM
%r|\A/sys/block/(\w+)/(\w+)(?:/(\w+))?\t(.+)\z|

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


9
10
11
12
13
14
15
16
17
# File 'lib/specinfra/host_inventory/block_device.rb', line 9

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

#parse(ret) ⇒ Object


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/specinfra/host_inventory/block_device.rb', line 18

def parse(ret)
  block_device = {}
  ret.each_line do |line|
    line.strip!
    if m = line.match(BLOCK_DEVICE_REGEX)
      device = m[1].to_s
      check = m[3].nil? ? m[2].to_s : m[3].to_s
      value = m[4].to_s

      block_device[device] = {} if block_device[device].nil?
      block_device[device][check] = value
    end
  end
  block_device
end