Class: VirtualEthAdapter

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

Overview

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 = '') ⇒ VirtualEthAdapter

Returns a new instance of VirtualEthAdapter.



20
21
22
23
24
25
26
27
28
29
30
31
32
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
58
59
60
# File 'lib/HMC/VirtualEthAdapter.rb', line 20

def initialize(string = '')

  super(string)

  @virtualSlotNumber = nil
  @isIEEE = 0
  @portVlanID = nil
  @additionalVlanIDs = ''
  @isTrunk = 0
  @trunkPriority = 0 #if trunk is true, trunk priority has to to be set up

  @virtualSwitch = nil

  @macAddress = nil
  @allowedOsMacAddresses = nil
  @qosPiority = nil

  @regexp_minimum 			       = %r{^\s*(\d+)/([01])/(\d+)/([\d,]+|)/(\d+)/([01]|)\s*$}
  @regexp_vswitch 			       = %r{^\s*(\d+)/([01])/(\d+)/([\d,]+|)/(\d+)/([01]|)/([\w\-]+|)\s*$}
  @regexp_mac_address 		     = %r{^\s*(\d+)/([01])/(\d+)/([\d,]+|)/(\d+)/([01]|)/([\w\-]+|)/(\w+|)\s*$}
  @regexp_allowed_mac_address = %r{^\s*(\d+)/([01])/(\d+)/([\d,]+|)/(\d+)/([01]|)/([\w\-]+|)/(\w+|)/([\w,]+|all|)\s*$}
  @regexp_qos_priority 	       = %r{^\s*(\d+)/([01])/(\d+)/([\d,]+|)/(\d+)/([01]|)/([\w\-]+|)/(\w+|)/([\w,]+|all|)/(\d+|none)\s*$}

  # '20/1/101/0/0///all/none'
  # virtual-slot-number/is-IEEE/port-vlan-ID/[additional-vlan-IDs]/[trunk-priority]/is-required[/[virtual-switch][/[MAC-address]/[allowed-OS-MAC-addresses]/[QoS-priority]]]

  # The first 5 ’/’ characters must be present. The 6th
  # ’/’ character is optional, but it must be present if
  #    virtual-switch or any of the values following
  # virtual-switch are specified. The last 3 ’/’
  # characters are optional, but all 3 must be present if
  #    MAC-address, allowed-OS-MAC-addresses, or QoS-priority
  # is specified.


  @params = %w[isIEEE portVlanID additionalVlanIDs trunkPriority isTrunk virtualSwitch macAddress allowedOsMacAddresses qosPiority]
  @params_real = %w[lpar_name lpar_id slot_num state is_required is_trunk trunk_priority ieee_virtual_eth port_vlan_id vswitch addl_vlan_ids mac_addr allowed_os_mac_addrs qos_priority]


  parse(string) unless string.empty?
end

Instance Attribute Details

#additionalVlanIDsObject

Returns the value of attribute additionalVlanIDs.



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

def additionalVlanIDs
  @additionalVlanIDs
end

#allowedOsMacAddressesObject

Returns the value of attribute allowedOsMacAddresses.



17
18
19
# File 'lib/HMC/VirtualEthAdapter.rb', line 17

def allowedOsMacAddresses
  @allowedOsMacAddresses
end

#isIEEEObject

Returns the value of attribute isIEEE.



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

def isIEEE
  @isIEEE
end

#isTrunkObject

Returns the value of attribute isTrunk.



14
15
16
# File 'lib/HMC/VirtualEthAdapter.rb', line 14

def isTrunk
  @isTrunk
end

#macAddressObject

Returns the value of attribute macAddress.



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

def macAddress
  @macAddress
end

#portVlanIDObject

Returns the value of attribute portVlanID.



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

def portVlanID
  @portVlanID
end

#qosPiorityObject

Returns the value of attribute qosPiority.



18
19
20
# File 'lib/HMC/VirtualEthAdapter.rb', line 18

def qosPiority
  @qosPiority
end

#trunkPriorityObject

Returns the value of attribute trunkPriority.



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

def trunkPriority
  @trunkPriority
end

#virtualSwitchObject

Returns the value of attribute virtualSwitch.



15
16
17
# File 'lib/HMC/VirtualEthAdapter.rb', line 15

def virtualSwitch
  @virtualSwitch
end

Instance Method Details

#can_parse?(string) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
93
94
95
96
97
98
99
100
# File 'lib/HMC/VirtualEthAdapter.rb', line 90

def can_parse?(string)

  return true if  @regexp_minimum.match(string)
  return true if  @regexp_vswitch.match(string)
  return true if  @regexp_mac_address.match(string)
  return true if  @regexp_allowed_mac_address.match(string)
  return true if  @regexp_qos_priority.match(string)
  return true if  can_parse_real?(string)

  false
end

#can_parse_real?(string) ⇒ Boolean

Returns:

  • (Boolean)


172
173
174
175
176
177
178
179
180
181
182
# File 'lib/HMC/VirtualEthAdapter.rb', line 172

def can_parse_real?(string)

  data = HmcString.parse(string)

  data.each_pair do |key, value|
    return false unless @params_real.include?(key.delete("\s"))
  end

  true

end

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



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/HMC/VirtualEthAdapter.rb', line 102

def decode(string)
  @data_string_raw = string

# virtual-slot-number/is-IEEE/port-vlan-ID/[additional-vlan-IDs]/[trunk-priority]/is-required[/[virtual-switch][/[MAC-address]/
# [allowed-OS-MAC-addresses]/[QoS-priority]]]

  if can_parse_real?(string)
    parse_real(string)
  elsif match = @regexp_minimum.match(string)

    @virtualSlotNumber	= match[1].to_i
    @isIEEE	= match[2].to_i
    @portVlanID	= match[3].to_i
    @additionalVlanIDs	= match[4]
    @trunkPriority	= match[5].to_i
    @isRequired	= match[6].to_i

  elsif match = @regexp_vswitch.match(string)

    @virtualSlotNumber	= match[1].to_i
    @isIEEE	= match[2].to_i
    @portVlanID	= match[3].to_i
    @additionalVlanIDs	= match[4]
    @trunkPriority	= match[5].to_i
    @isRequired	= match[6].to_i
    @virtualSwitch	= match[7].to_i

  elsif match = @regexp_mac_address.match(string)

    @virtualSlotNumber	= match[1].to_i
    @isIEEE	= match[2].to_i
    @portVlanID	= match[3].to_i
    @additionalVlanIDs	= match[4]
    @trunkPriority	= match[5].to_i
    @isRequired	= match[6].to_i
    @virtualSwitch	= match[7]
    @macAddress	= match[8]

  elsif match = @regexp_allowed_mac_address.match(string)

    @virtualSlotNumber	= match[1].to_i
    @isIEEE	= match[2].to_i
    @portVlanID = match[3].to_i
    @additionalVlanIDs	= match[4]
    @trunkPriority	= match[5].to_i
    @isRequired	= match[6].to_i
    @virtualSwitch = match[7]
    @macAddress	= match[8]
    @allowedOsMacAddresses = match[9]

  elsif match = @regexp_qos_priority.match(string)

    @virtualSlotNumber	= match[1].to_i
    @isIEEE	= match[2].to_i
    @portVlanID	= match[3].to_i
    @additionalVlanIDs	= match[4]
    @trunkPriority	= match[5].to_i
    @isRequired	= match[6].to_i
    @virtualSwitch	= match[7]
    @macAddress	= match[8]
    @allowedOsMacAddresses = match[9]
    @qosPiority	= match[10]

  else
    raise "class:VirtualEthAdapter, function:parse, RegExp couldn't decode string >#{string}<"
  end
end

#parse_real(string) ⇒ Object



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/HMC/VirtualEthAdapter.rb', line 184

def parse_real(string)

  data = HmcString.parse(string)
  data.each_pair do |key, value|
    case key.delete("\s")
    when 'lpar_name' then @lpar_name = value
    when 'lpar_id' then @lpar_id = value.to_i
    when 'slot_num' then @virtualSlotNumber = value.to_i
    when 'state' then @state = value.to_i
    when 'is_required' then @isRequired = value.to_i
    when 'is_trunk' then @isTrunk = value.to_i
    when 'trunk_priority' then @trunkPriority = value.to_i
    when 'ieee_virtual_eth' then @isIEEE = value.to_i
    when 'port_vlan_id' then @portVlanID = value.to_i
    when 'addl_vlan_ids' then @additionalVlanIDs = value
    when 'mac_addr' then @macAddress = value
    when 'vswitch' then @virtualSwitch = value
    when 'allowed_os_mac_addrs'  then @allowedOsMacAddresses = value
    when 'qos_priority' then @qosPiority = value
    else
      raise Exception, "Can't parse string, wrong key: '#{key}'"
    end
  end
  @_type = 'real'

end

#to_sObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/HMC/VirtualEthAdapter.rb', line 68

def to_s

  validate

  if @_type == 'real'
    result  = "lpar_name=#{@lpar_name},lpar_id=#{@lpar_id},slot_num=#{@virtualSlotNumber},state=#{@state},is_required=#{@isRequired},"
    result += "is_trunk=#{@isTrunk},"
    result += "trunk_priority=#{@trunkPriority}," if @isTrunk == 1
    result += "ieee_virtual_eth=#{@isIEEE},port_vlan_id=#{@portVlanID},addl_vlan_ids=,mac_addr=#{@macAddress}"
  else
    result = "#{@virtualSlotNumber}/#{@isIEEE}/#{@portVlanID}/#{@additionalVlanIDs}/#{@trunkPriority}/#{@isRequired}"
    result += "/#{@virtualSwitch}" unless @virtualSwitch.nil?
    result += "/#{@macAddress}" unless @macAddress.nil?
    result += "/#{@allowedOsMacAddresses}" unless @allowedOsMacAddresses.nil?
    result += "/#{@qosPiority}" unless @qosPiority.nil?

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

  result
end

#validateObject



62
63
64
65
66
# File 'lib/HMC/VirtualEthAdapter.rb', line 62

def validate
  raise 'class: VirtualEthAdapter: function: validation, virtualSlotNumber not defined' unless (@virtualSlotNumber.is_a? Numeric)
  raise 'class: VirtualEthAdapter: function: validation, isIEEE not defined' unless (@isIEEE.is_a? Numeric)
  raise 'class: VirtualEthAdapter: function: validation, isRequired not defined' unless (@isRequired.is_a? Numeric)
end