Class: Lsnports

Inherits:
Object
  • Object
show all
Defined in:
lib/HMC/lsnports.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Lsnports

Returns a new instance of Lsnports.



6
7
8
9
10
11
# File 'lib/HMC/lsnports.rb', line 6

def initialize(string)
  @data = {}
  @data_string_raw = ''

  parse(string) unless string.empty?
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/HMC/lsnports.rb', line 3

def data
  @data
end

#data_string_rawObject (readonly)

Returns the value of attribute data_string_raw.



4
5
6
# File 'lib/HMC/lsnports.rb', line 4

def data_string_raw
  @data_string_raw
end

Instance Method Details

#parse(string) ⇒ 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
# File 'lib/HMC/lsnports.rb', line 13

def parse(string)
  @data_string_raw = string

  string.split("\n").each do |line|
    if line =~ %r{^\s*name\s+physloc\s+fabric\s+tports\s+aports\s+swwpns\s+awwpns\s*$}
      next
    elsif match = %r{(fcs\d+)\s+(\w{5}.\d{3}.\w{7}-P\d+-C\d+-T\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s*$}.match(line)

      fcs = {}
      fcs['name'] = match[1]
      fcs['physloc'] = match[2]
      fcs['fabric'] = match[3].to_i
      fcs['tports'] = match[4].to_i
      fcs['aports'] = match[5].to_i
      fcs['swwpns'] = match[6].to_i
      fcs['awwpns'] = match[7].to_i

      @data[fcs['name']] = fcs
    else
      raise Exception, "Wrong string >#{line}"
    end

  end

end