Class: VirtualScsiAdapter
- Inherits:
-
VirtualAdapter
- Object
- VirtualAdapter
- VirtualScsiAdapter
- Defined in:
- lib/HMC/VirtualScsiAdapter.rb
Instance Attribute Summary collapse
-
#clientOrServer ⇒ Object
TODO: analyze if in case that remote lpar or slot is ‘any’ can we do simpler code (not so many if..elsif…).
-
#remoteLparID ⇒ Object
Returns the value of attribute remoteLparID.
-
#remoteLparName ⇒ Object
Returns the value of attribute remoteLparName.
-
#remoteSlotNumber ⇒ Object
Returns the value of attribute remoteSlotNumber.
Attributes inherited from VirtualAdapter
#_type, #frame, #isRequired, #lpar_id, #lpar_name, #state, #vios, #virtualSlotNumber
Instance Method Summary collapse
- #can_parse?(string) ⇒ Boolean
- #decode(string) ⇒ Object (also: #parse)
-
#initialize(string = '') ⇒ VirtualScsiAdapter
constructor
A new instance of VirtualScsiAdapter.
-
#to_s ⇒ Object
virtual-slot-number/client-or-server//[remote-lpar-name]//is-required.
- #validate ⇒ Object
Methods inherited from VirtualAdapter
Constructor Details
#initialize(string = '') ⇒ VirtualScsiAdapter
Returns a new instance of VirtualScsiAdapter.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/HMC/VirtualScsiAdapter.rb', line 11 def initialize(string = '') super(string) @clientOrServer = nil @remoteLparID = nil @remoteLparName = nil @remoteSlotNumber = nil @params = %w[virtualSlotNumber clientOrServer remoteLparID remoteLparName remoteSlotNumber isRequired lpar_name lpar_id] @regExp = %r{^\s*(\d+)/(server|client)/(\d+)/([\w\-\.]+|)/(\d+)/([01])\s*$} @regExp_any = %r{^\s*(\d+)/(server|client)/(any)/([\w\-\.]+|)/(any)/([01])\s*$} @regExp_long = %r{^\s*slot_num=(\d+),state=([01]),is_required=([01]),adapter_type=(client|server),remote_lpar_id=(\d+|any),remote_lpar_name=([\w\-]+|),remote_slot_num=(\d+|any)\s*$} @regExp_real = %r{^\s*lpar_name=([\w\-]+),lpar_id=(\d+),slot_num=(\d+),state=([01]),is_required=([01]),adapter_type=(client|server),remote_lpar_id=(\d+|any),remote_lpar_name=([\w\-]+|),remote_slot_num=(\d+|any)\s*$} parse(string) unless string.empty? end |
Instance Attribute Details
#clientOrServer ⇒ Object
TODO: analyze if in case that remote lpar or slot is ‘any’ can we do simpler code (not so many if..elsif…)
6 7 8 |
# File 'lib/HMC/VirtualScsiAdapter.rb', line 6 def clientOrServer @clientOrServer end |
#remoteLparID ⇒ Object
Returns the value of attribute remoteLparID.
7 8 9 |
# File 'lib/HMC/VirtualScsiAdapter.rb', line 7 def remoteLparID @remoteLparID end |
#remoteLparName ⇒ Object
Returns the value of attribute remoteLparName.
8 9 10 |
# File 'lib/HMC/VirtualScsiAdapter.rb', line 8 def remoteLparName @remoteLparName end |
#remoteSlotNumber ⇒ Object
Returns the value of attribute remoteSlotNumber.
9 10 11 |
# File 'lib/HMC/VirtualScsiAdapter.rb', line 9 def remoteSlotNumber @remoteSlotNumber end |
Instance Method Details
#can_parse?(string) ⇒ Boolean
63 64 65 66 67 |
# File 'lib/HMC/VirtualScsiAdapter.rb', line 63 def can_parse?(string) return true if @regExp.match(string) or @regExp_any.match(string) or @regExp_long.match(string) or @regExp_real.match(string) false end |
#decode(string) ⇒ Object Also known as: parse
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/HMC/VirtualScsiAdapter.rb', line 69 def decode(string) @data_string_raw = string if match = @regExp.match(string) @virtualSlotNumber = match[1].to_i @clientOrServer = match[2] @remoteLparID = match[3].to_i @remoteLparName = match[4] @remoteSlotNumber = match[5].to_i @isRequired = match[6].to_i elsif match = @regExp_any.match(string) @virtualSlotNumber = match[1].to_i @clientOrServer = match[2] @remoteLparID = match[3] @remoteLparName = match[4] @remoteSlotNumber = match[5] @isRequired = match[6].to_i elsif match = @regExp_long.match(string) @virtualSlotNumber = match[1].to_i @state = match[2].to_i @isRequired = match[3].to_i @clientOrServer = match[4] @remoteLparID = match[5].to_i @remoteLparName = match[6] @remoteSlotNumber = match[7].to_i elsif match = @regExp_real.match(string) @lpar_name = match[1] @lpar_id = match[2].to_i @virtualSlotNumber = match[3].to_i @state = match[4].to_i @isRequired = match[5].to_i @clientOrServer = match[6] @remoteLparID = match[7].to_i @remoteLparName = match[8] @remoteSlotNumber = match[9].to_i @_type = 'real' else raise Exception, "Class VirtualScsiAdapter:RegExp couldn't decode string #{string}" end end |
#to_s ⇒ Object
virtual-slot-number/client-or-server//[remote-lpar-name]//is-required
30 31 32 33 34 35 36 37 |
# File 'lib/HMC/VirtualScsiAdapter.rb', line 30 def to_s validate if @_type == 'real' "lpar_name=#{@lpar_name},lpar_id=#{@lpar_id},slot_num=#{@virtualSlotNumber},state=#{@state},is_required=#{@isRequired},adapter_type=#{@clientOrServer},remote_lpar_id=#{@remoteLparID},remote_lpar_name=#{@remoteLparName},remote_slot_num=#{@remoteSlotNumber}" else "#{@virtualSlotNumber}/#{@clientOrServer}/#{@remoteLparID}/#{@remoteLparName}/#{@remoteSlotNumber}/#{@isRequired}" end end |
#validate ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/HMC/VirtualScsiAdapter.rb', line 39 def validate raise 'virtualSlotNumber not defined' if @virtualSlotNumber == nil raise 'virtualSlotNumber is not number' unless @virtualSlotNumber.is_a? Numeric raise "virtualSlotNumber has wrong value: #{@virtualSlotNumber}" if @virtualSlotNumber < 1 raise 'clinetOrServer not defined' if @clientOrServer.nil? clientOrServer_allowed = %w[ client server ] raise "clientOrServer has wrong value #{@clientOrServer}" unless clientOrServer_allowed.include?(@clientOrServer) raise 'remoteLparID not defined' if @remoteLparID.nil? raise 'remoteLparID is not number or "any"' unless @remoteLparID.is_a? Numeric or @remoteLparID == 'any' raise 'remoteLparName not defined' if @remoteLparName.nil? raise 'remoteLparName is not string' unless @remoteLparName.is_a? String raise 'remoteSlotNumber not defined' if @remoteSlotNumber.nil? raise 'remoteSlotNumber is not number or "any"' unless @remoteSlotNumber.is_a? Numeric or @remoteSlotNumber == "any" raise 'isRequired not defined' if @isRequired.nil? raise 'isRequired is not number' unless @isRequired.is_a? Numeric raise "isRequired has wrong value #{@isRequired} " unless @isRequired == 0 or @isRequired == 1 end |