Class: VirtualFCAdapter

Inherits:
VirtualAdapter show all
Defined in:
lib/HMC/VirtualFCAdapter.rb

Instance Attribute Summary collapse

Attributes inherited from VirtualAdapter

#_type, #frame, #isRequired, #lpar_id, #lpar_name, #state, #vios, #virtualSlotNumber

Instance Method Summary collapse

Methods inherited from VirtualAdapter

#==, #diff

Constructor Details

#initialize(string = '') ⇒ VirtualFCAdapter

Returns a new instance of VirtualFCAdapter.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/HMC/VirtualFCAdapter.rb', line 19

def initialize(string = '')

  super(string)

  @clientOrServer = nil
  @remoteLparID = nil
  @remoteLparName = nil
  @remoteSlotNumber = nil
  @wwpn1 = nil
  @wwpn2 = nil

  @reg_exp = %r{^\s*["]{0,2}(\d+)/(server|client)/(\d+)/([\w\-]+|)/(\d+)/(\w{16},\w{16}|\w{16}|)/([01])["]{0,2}\s*$}

  @params = %w[virtualSlotNumber isRequired clientOrServer remoteLparID remoteLparName remoteSlotNumber wwpn1 wwpn2]

  @_type = ''
  parse(string) unless string.empty?
end

Instance Attribute Details

#clientOrServerObject



8
9
10
# File 'lib/HMC/VirtualFCAdapter.rb', line 8

def clientOrServer
  @clientOrServer
end

#connectStatusObject

below data can be taken only from lshwres, they are exist only for running lpars



16
17
18
# File 'lib/HMC/VirtualFCAdapter.rb', line 16

def connectStatus
  @connectStatus
end

#remoteLparIDObject

Returns the value of attribute remoteLparID.



9
10
11
# File 'lib/HMC/VirtualFCAdapter.rb', line 9

def remoteLparID
  @remoteLparID
end

#remoteLparNameObject

Returns the value of attribute remoteLparName.



10
11
12
# File 'lib/HMC/VirtualFCAdapter.rb', line 10

def remoteLparName
  @remoteLparName
end

#remoteSlotNumberObject

Returns the value of attribute remoteSlotNumber.



11
12
13
# File 'lib/HMC/VirtualFCAdapter.rb', line 11

def remoteSlotNumber
  @remoteSlotNumber
end

#wwpn1Object

Returns the value of attribute wwpn1.



12
13
14
# File 'lib/HMC/VirtualFCAdapter.rb', line 12

def wwpn1
  @wwpn1
end

#wwpn2Object

Returns the value of attribute wwpn2.



13
14
15
# File 'lib/HMC/VirtualFCAdapter.rb', line 13

def wwpn2
  @wwpn2
end

Instance Method Details

#can_parse?(string) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
59
60
# File 'lib/HMC/VirtualFCAdapter.rb', line 56

def can_parse?(string)
  # TODO: change it to "one liner"
  return true if @reg_exp.match(string)
  false
end

#decode(string) ⇒ Object Also known as: parse



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/HMC/VirtualFCAdapter.rb', line 62

def decode(string)
  @data_string_raw = string

  match = @reg_exp.match(string)
  raise "RegExp couldn't decode string #{string}" unless match

  @virtualSlotNumber 	= match[1].to_i
  @clientOrServer 	  = match[2]
  @remoteLparID 		  = match[3].to_i
  @remoteLparName		  = match[4]
  @remoteSlotNumber 	= match[5].to_i
  wwpns	= match[6]
  @isRequired	= match[7].to_i

  if match2 = %r{^\s*(\w{16})\,(\w{16})\s*$}.match(wwpns)
    @wwpn1 = match2[1]
    @wwpn2 = match2[2]
  elsif match3 = %r{^\s*(\w{16})\s*$}.match(wwpns)
    @wwpn1 = match3[1]
    @wwpn2 = nil
  end

end

#to_sObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/HMC/VirtualFCAdapter.rb', line 42

def to_s
  validate

  # virtual-slot-number/client-or-server/[remote-lpar-ID]/[remote-lpar-name]/remote-slot-number/[wwpns]/is-required
  result = "#{@virtualSlotNumber}/#{clientOrServer}/#{@remoteLparID}/#{@remoteLparName}/#{@remoteSlotNumber}/"
  result += @wwpn1 unless @wwpn1.nil?
  result += ",#{@wwpn2}" unless @wwpn2.nil?
  result += "/#{@isRequired}"

  result = '""' + result + '""' if result.include?(',')

  result
end

#validateObject



38
39
40
# File 'lib/HMC/VirtualFCAdapter.rb', line 38

def validate
  raise 'virtualSlotNumber not defined' unless @virtualSlotNumber.is_a? Numeric
end