Class: Storcs::Parsers::Nss

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#parse_size

Constructor Details

#initialize(name, file) ⇒ Nss

Returns a new instance of Nss.



7
8
9
10
11
# File 'lib/storcs/parsers/nss.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/nss.rb', line 5

def device
  @device
end

Instance Method Details

#parse!(content) ⇒ Object



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

def parse!(content)
  @device.children = pools
end

#poolsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/storcs/parsers/nss.rb', line 17

def pools
  return @pools if @pools
  @pools = []

  current_allocated = nil
  @lines.each do |line|
    if line =~ /^Total (Available|Allocated) Space in "([^"]*)" \(ID: \d+\): (.*) MB/
      size = $3.tr(',', '').to_i * 1024 * 1024
      case $1
      when 'Allocated'
        current_allocated = size
      when 'Available'
        current_available = size
        @pools << Storcs::Device.new($2)
        @pools.last.real_size = current_allocated + current_available
        @pools.last.real_used = current_allocated
        current_allocated = nil
      end
    end
  end
  @pools
end