Class: Lpar_virtual_slots

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_virtual_slots = 65_000) ⇒ Lpar_virtual_slots

TODO: check max virtual slots number



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/HMC/Lpar_virtual_slots.rb', line 34

def initialize(max_virtual_slots = 65_000)
  @max_virtual_slots = max_virtual_slots
  @virtual_slots = {}

  @virtual_vasi_adapters    = []
  @virtual_eth_vsi_profiles = []
  @virtual_vasi_adapters_raw    = nil
  @virtual_eth_vsi_profiles_raw = nil

  @virtual_fc_adapters      = []
  @virtual_scsi_adapters    = []
  @virtual_serial_adapters  = []
  @virtual_eth_adapters     = []

  @virtual_fc_adapters_raw      = nil
  @virtual_scsi_adapters_raw    = nil
  @virtual_serial_adapters_raw  = nil
  @virtual_eth_adapters_raw     = nil

  @profile_name = nil
end

Instance Attribute Details

#max_virtual_slotsObject

Returns the value of attribute max_virtual_slots.



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

def max_virtual_slots
  @max_virtual_slots
end

#profile_nameObject

it is helper for diff functions, much easier to say, which profile has different settings



31
32
33
# File 'lib/HMC/Lpar_virtual_slots.rb', line 31

def profile_name
  @profile_name
end

#virtual_eth_adaptersObject (readonly)

Returns the value of attribute virtual_eth_adapters.



24
25
26
# File 'lib/HMC/Lpar_virtual_slots.rb', line 24

def virtual_eth_adapters
  @virtual_eth_adapters
end

#virtual_eth_adapters_rawObject

Returns the value of attribute virtual_eth_adapters_raw.



29
30
31
# File 'lib/HMC/Lpar_virtual_slots.rb', line 29

def virtual_eth_adapters_raw
  @virtual_eth_adapters_raw
end

#virtual_eth_vsi_profilesObject (readonly)

Returns the value of attribute virtual_eth_vsi_profiles.



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

def virtual_eth_vsi_profiles
  @virtual_eth_vsi_profiles
end

#virtual_eth_vsi_profiles_rawObject

Returns the value of attribute virtual_eth_vsi_profiles_raw.



19
20
21
# File 'lib/HMC/Lpar_virtual_slots.rb', line 19

def virtual_eth_vsi_profiles_raw
  @virtual_eth_vsi_profiles_raw
end

#virtual_fc_adaptersObject (readonly)

Returns the value of attribute virtual_fc_adapters.



21
22
23
# File 'lib/HMC/Lpar_virtual_slots.rb', line 21

def virtual_fc_adapters
  @virtual_fc_adapters
end

#virtual_fc_adapters_rawObject

Returns the value of attribute virtual_fc_adapters_raw.



26
27
28
# File 'lib/HMC/Lpar_virtual_slots.rb', line 26

def virtual_fc_adapters_raw
  @virtual_fc_adapters_raw
end

#virtual_scsi_adaptersObject (readonly)

Returns the value of attribute virtual_scsi_adapters.



23
24
25
# File 'lib/HMC/Lpar_virtual_slots.rb', line 23

def virtual_scsi_adapters
  @virtual_scsi_adapters
end

#virtual_scsi_adapters_rawObject

Returns the value of attribute virtual_scsi_adapters_raw.



28
29
30
# File 'lib/HMC/Lpar_virtual_slots.rb', line 28

def virtual_scsi_adapters_raw
  @virtual_scsi_adapters_raw
end

#virtual_serial_adaptersObject (readonly)

Returns the value of attribute virtual_serial_adapters.



22
23
24
# File 'lib/HMC/Lpar_virtual_slots.rb', line 22

def virtual_serial_adapters
  @virtual_serial_adapters
end

#virtual_serial_adapters_rawObject

Returns the value of attribute virtual_serial_adapters_raw.



27
28
29
# File 'lib/HMC/Lpar_virtual_slots.rb', line 27

def virtual_serial_adapters_raw
  @virtual_serial_adapters_raw
end

#virtual_slotsObject

Returns the value of attribute virtual_slots.



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

def virtual_slots
  @virtual_slots
end

#virtual_vasi_adaptersObject (readonly)

TODO: implement functions for virtual vasi and vsi adapters



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

def virtual_vasi_adapters
  @virtual_vasi_adapters
end

#virtual_vasi_adapters_rawObject

Returns the value of attribute virtual_vasi_adapters_raw.



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

def virtual_vasi_adapters_raw
  @virtual_vasi_adapters_raw
end

Instance Method Details

#adapters_to_s(type) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/HMC/Lpar_virtual_slots.rb', line 157

def adapters_to_s(type)

  return nil if type == 'virtual_fc_adapters'     && @virtual_fc_adapters_raw.nil?
  return nil if type == 'virtual_eth_adapters'    && @virtual_eth_adapters_raw.nil?
  return nil if type == 'virtual_serial_adapters' && @virtual_serial_adapters_raw.nil?
  return nil if type == 'virtual_scsi_adapters'   && @virtual_scsi_adapters_raw.nil?

  adapters_tmp = case type
                 when 'virtual_fc_adapters'     then @virtual_fc_adapters
                 when 'virtual_eth_adapters'    then @virtual_eth_adapters
                 when 'virtual_scsi_adapters'   then @virtual_scsi_adapters
                 when 'virtual_serial_adapters' then @virtual_serial_adapters
                 else
                   raise 'unknown type ' + type
 end

  if adapters_tmp.empty?
    'none'
  else
    adapters = []
    adapters_tmp.each do |adapter|
      adapters.push(adapter.to_s)
    end
    adapters.join(',')
  end
end

#diff(other_lpar_virtual_slots, type, null_zero_none_equal = 0) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/HMC/Lpar_virtual_slots.rb', line 200

def diff(other_lpar_virtual_slots, type, null_zero_none_equal = 0)

  diff = {}
  max_virtual_slots = [self.max_virtual_slots, other_lpar_virtual_slots.max_virtual_slots].max

  1.upto(max_virtual_slots) do |i|

    if virtual_slots.key?(i) && other_lpar_virtual_slots.virtual_slots.key?(i)

      self_slot =  virtual_slots[i]
      other_slot = other_lpar_virtual_slots.virtual_slots[i]
      self_profile_name = profile_name
      other_profile_name = other_lpar_virtual_slots.profile_name

      # let's check type of slots

      if type == 'virtual_serial_adapters'
        next unless self_slot.class.name == 'VirtualSerialAdapter' or other_slot.class.name == 'VirtualSerialAdapter'
      end

      if type == 'VirtualScsiAdapter'
        next unless self_slot.class.name == 'VirtualScsiAdapter' or other_slot.class.name == 'VirtualScsiAdapter'
      end
      if type == 'virtual_eth_adapters'
        next unless self_slot.class.name == 'VirtualEthAdapter' or other_slot.class.name == 'VirtualEthAdapter'
      end

      if type == 'virtual_fc_adapters'
        next unless self_slot.class.name == 'VirtualFCAdapter' or other_slot.class.name == 'VirtualFCAdapter'
      end

      # let's check if slot are the same type (ethernet, fcs etc)

      if self_slot.class.name != other_slot.class.name
        entry = {}
        entry[self_profile_name] =  "The slot type is #{self_slot.class.name}"
        entry[other_profile_name] = "The slot type is #{other_slot.class.name}"
        diff["VirtualSlot #{i}"] = entry

        next
      end

      if self_slot.class.name == 'VirtualFCAdapter' ||
         self_slot.class.name == 'VirtualEthAdapter' ||
         self_slot.class.name == 'VirtualScsiAdapter'

        diff_entry_slot = self_slot.diff(other_slot, self_profile_name, other_profile_name, null_zero_none_equal)

        diff_entry_slot.each do |key, entry_tmp|
          diff["VirtualSlot #{i} #{key}"] = entry_tmp
        end
      else
        raise("unsupported type of adapter #{self_slot.class.name} ")
      end


    elsif virtual_slots.key?(i) && !other_lpar_virtual_slots.virtual_slots.key?(i)

      self_slot = virtual_slots[i]
      self_profile_name = profile_name
      other_profile_name = other_lpar_virtual_slots.profile_name

      # let's check type of slots

      if type == 'virtual_serial_adapters'
        next unless self_slot.class.name == 'VirtualSerialAdapter'
      elsif type == 'VirtualScsiAdapter'
        next unless self_slot.class.name == 'VirtualScsiAdapter'
      elsif type == 'virtual_eth_adapters'
        next unless self_slot.class.name == 'VirtualEthAdapter'
      elsif type == 'virtual_fc_adapters'
        next unless self_slot.class.name == 'VirtualFCAdapter'
      end


      entry = {}
      entry[self_profile_name]  = "A profile use it: #{self_slot.class.name} #{self_slot.to_s}"
      entry[other_profile_name] = "A profile doesn't use slot"
      diff["VirtualSlot #{i}"] = entry

    elsif !virtual_slots.key?(i) && other_lpar_virtual_slots.virtual_slots.key?(i)

      other_slot = other_lpar_virtual_slots.virtual_slots[i]
      self_profile_name = profile_name
      other_profile_name = other_lpar_virtual_slots.profile_name

      # let's check type of slots

      if type == 'virtual_serial_adapters'
        next unless other_slot.class.name == 'VirtualSerialAdapter'
      elsif type == 'VirtualScsiAdapter'
        next unless other_slot.class.name == 'VirtualScsiAdapter'
      elsif type == 'virtual_eth_adapters'
        next unless other_slot.class.name == 'VirtualEthAdapter'
      elsif type == 'virtual_fc_adapters'
        next unless other_slot.class.name == 'VirtualFCAdapter'
      end

      entry = {}
      entry[self_profile_name]  = "A profile doesn't use slot"
      entry[other_profile_name] = 'A profile use it: ' + other_slot.class.name + ' ' + other_slot.to_s

      diff["VirtualSlot #{i}"] = entry
    end
  end

  diff
end

#virtual_adapter_add(adapter) ⇒ Object Also known as: add



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/HMC/Lpar_virtual_slots.rb', line 56

def virtual_adapter_add(adapter)

  case adapter.class.to_s
  when 'VirtualEthAdapter'    then virtual_eth_adapters_add(adapter)
  when 'VirtualScsiAdapter'   then virtual_scsi_adapters_add(adapter)
  when 'VirtualSerialAdapter' then virtual_serial_adapters_add(adapter)
  when 'VirtualFCAdapter'     then virtual_fc_adapters_add(adapter)
  else
    pp 'adapter class:' +  adapter.class
    raise 'unknown type of adapter'
  end
end

#virtual_adapters_raw(string, adapter_type) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/HMC/Lpar_virtual_slots.rb', line 116

def virtual_adapters_raw(string, adapter_type)

  unless string == 'none'
    HmcString.parse_value(string).each do |adapter|
      case adapter_type
      when 'virtual_fc_adapters' then virtual_adapter_add(VirtualFCAdapter.new(adapter))
      when 'virtual_eth_adapters' then virtual_adapter_add(VirtualEthAdapter.new(adapter))
      when 'virtual_scsi_adapters' then virtual_adapter_add(VirtualScsiAdapter.new(adapter))
      when 'virtual_serial_adapters' then virtual_adapter_add(VirtualSerialAdapter.new(adapter))
      else
        raise 'unknown type of virtual adapter'
      end
    end
  end

  case adapter_type
  when 'virtual_fc_adapters' then @virtual_fc_adapters_raw = string
  when 'virtual_eth_adapters' then @virtual_eth_adapters_raw = string
  when 'virtual_scsi_adapters' then @virtual_scsi_adapters_raw = string
  when 'virtual_serial_adapters' then @virtual_serial_adapters_raw = string
  else
    raise 'unknown type of virtual adapter'
  end
end

#virtual_eth_adapters_add(adapter) ⇒ Object



71
72
73
74
75
76
77
78
79
80
# File 'lib/HMC/Lpar_virtual_slots.rb', line 71

def virtual_eth_adapters_add(adapter)
  @virtual_eth_adapters.push(adapter)
  @virtual_slots[adapter.virtualSlotNumber] = adapter

  if @virtual_eth_adapters_raw.nil?
    @virtual_eth_adapters_raw = adapter.to_s
  else
    @virtual_eth_adapters_raw += adapter.to_s
  end
end

#virtual_eth_adapters_to_sObject



192
193
194
# File 'lib/HMC/Lpar_virtual_slots.rb', line 192

def virtual_eth_adapters_to_s
  adapters_to_s('virtual_eth_adapters')
end

#virtual_fc_adapters_add(adapter) ⇒ Object



82
83
84
85
86
87
88
89
90
91
# File 'lib/HMC/Lpar_virtual_slots.rb', line 82

def virtual_fc_adapters_add(adapter)
  @virtual_fc_adapters.push(adapter)
  @virtual_slots[adapter.virtualSlotNumber] = adapter

  if @virtual_fc_adapters_raw.nil?
    @virtual_fc_adapters_raw = adapter.to_s + ','
  else
    @virtual_fc_adapters_raw += adapter.to_s + ','
  end
end

#virtual_fc_adapters_to_sObject



184
185
186
# File 'lib/HMC/Lpar_virtual_slots.rb', line 184

def virtual_fc_adapters_to_s
  adapters_to_s('virtual_fc_adapters')
end

#virtual_scsi_adapters_add(adapter) ⇒ Object



93
94
95
96
97
98
99
100
101
102
# File 'lib/HMC/Lpar_virtual_slots.rb', line 93

def virtual_scsi_adapters_add(adapter)
  @virtual_scsi_adapters.push(adapter)
  @virtual_slots[adapter.virtualSlotNumber] = adapter

  if @virtual_scsi_adapters_raw.nil?
    @virtual_scsi_adapters_raw = adapter.to_s + ','
  else
    @virtual_scsi_adapters_raw += adapter.to_s + ','
  end
end

#virtual_scsi_adapters_to_sObject



188
189
190
# File 'lib/HMC/Lpar_virtual_slots.rb', line 188

def virtual_scsi_adapters_to_s
  adapters_to_s('virtual_scsi_adapters')
end

#virtual_serial_adapters_add(adapter) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
# File 'lib/HMC/Lpar_virtual_slots.rb', line 104

def virtual_serial_adapters_add(adapter)
  @virtual_serial_adapters.push(adapter)
  # TODO: add this part of code

  # @virtual_slots[adapter.virtualSlotNumber] = adapter


  if @virtual_serial_adapters_raw.nil?
    @virtual_serial_adapters_raw = adapter.to_s + ','
  else
    @virtual_serial_adapters_raw += adapter.to_s + ','
  end
end

#virtual_serial_adapters_to_sObject



196
197
198
# File 'lib/HMC/Lpar_virtual_slots.rb', line 196

def virtual_serial_adapters_to_s
  adapters_to_s('virtual_serial_adapters')
end