Class: Storcs::Parsers::Ibm

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/storcs/parsers/ibm.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#parse_size

Constructor Details

#initialize(name, file) ⇒ Ibm

Returns a new instance of Ibm.



7
8
9
10
11
# File 'lib/storcs/parsers/ibm.rb', line 7

def initialize(name,file)
  @device = Storcs::Device.new(name)
  @lines = File.readlines(file)
  parse!(@lines)
end

Instance Attribute Details

#deviceObject

Returns the value of attribute device.



5
6
7
# File 'lib/storcs/parsers/ibm.rb', line 5

def device
  @device
end

Instance Method Details

#arraysObject



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
# File 'lib/storcs/parsers/ibm.rb', line 33

def arrays
  return @arrays if @arrays
  @arrays = []
  current_array = nil
  logical_drive_list = false
  sections[:arrays].map do |line|
    if line.match /^   (ARRAY \d+)\s+\(RAID (\w+)\)/
      current_array = Storcs::Device.new($1)
      current_array.raid = $2
      @arrays << current_array
    elsif line.match /^\s{8,}LOGICAL DRIVE NAME/
      logical_drive_list = true
    elsif line.match /^\s*$/
      logical_drive_list = false
    elsif current_array && logical_drive_list
      line.gsub!(/Free Capacity/,"free")
      name, raw_size = line.strip.scan(/(\S+)\s+(.+)/).first
      ld = Storcs::Device.new(name)
      ld.real_size = parse_size(raw_size)
      ld.real_used = (name == "free" ? 0 : ld.real_size)
      current_array.children << ld
    end
  end.compact
  @arrays
end

#parse!(content) ⇒ Object



13
14
15
16
# File 'lib/storcs/parsers/ibm.rb', line 13

def parse!(content)
  @device.children = arrays
  @device.real_unassigned = unassigned
end

#sectionsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/storcs/parsers/ibm.rb', line 18

def sections
  return @sections if @sections
  @sections = {}
  current_section = nil
  @lines.each do |line|
    if line.chomp.match(/^([A-Z ]{3,}).*-------$/)
      current_section = $1.downcase.to_sym
      @sections[current_section] = []
    elsif current_section
      @sections[current_section] << line
    end
  end
  @sections
end

#unassignedObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/storcs/parsers/ibm.rb', line 59

def unassigned
  return @unassigned if @unassigned
  @unassigned = 0
  in_unassigned = false
  sections[:drives].map do |line|
    if line.match /Unassigned/
      in_unassigned = true
    elsif line.match /^\s*$/
      in_unassigned = false
    elsif in_unassigned && line.match(/Usable capacity:\s+(.+)$/)
      @unassigned += parse_size($1)
    end
  end.compact
  @unassigned
end