Class: Elesai::Megacli

Inherits:
Object
  • Object
show all
Includes:
Workflow
Defined in:
lib/elesai/megacli.rb

Direct Known Subclasses

AdpBbuCmd_aAll, LDPDinfo_aAll, PDlist_aAll

Defined Under Namespace

Classes: Context

Constant Summary collapse

ADAPTER_RE =
/^Adapter\s+#*(?<value>\d+)/
VIRTUALDRIVE_RE =
/^Virtual\s+Drive:\s+\d+\s+\((?<key>Target\s+Id):\s+(?<value>\d+)\)/
SPAN_RE =
/^Span:\s+(?<value>\d+)/
PHYSICALDRIVE_RE =
/^(?<key>Enclosure\s+Device\s+ID):\s+(?<value>\d+)/
ATTRIBUTE_RE =
/^(?<key>[A-Za-z0-9()\s#'-.&]+)[:|=](?<value>.*)/
EXIT_RE =
/^Exit Code: /
BBU_RE =
/^BBU status for Adapter:\s+(?<value>\d+)/
BBU_FIRMWARESTATUS_RE =
/^BBU Firmware Status:/
BBU_DESIGNINFO_RE =
/^BBU Design Info for Adapter:\s+(?<value>\d+)/
BBU_PROPERTIES_RE =
/^BBU Properties for Adapter:\s+(?<value>\d+)/
BBU_GASGAUGESTATUS_RE =
/^GasGuageStatus:/
BBU_CAPACITYINFO_RE =
/^BBU Capacity Info for Adapter:\s+(?<value>\d+)/

Instance Method Summary collapse

Instance Method Details

#adapter_line(adapter, key, value) ⇒ Object

Adapter



130
131
132
133
# File 'lib/elesai/megacli.rb', line 130

def adapter_line(adapter,key,value)
  @log.debug "  [#{current_state}] event adapter_line: new #{adapter.inspect}"
  adapter[key.to_sym] = value.to_i
end

#adapter_match(match) ⇒ Object

Adapter



366
367
368
369
370
371
# File 'lib/elesai/megacli.rb', line 366

def adapter_match(match)
  @log.debug "ADAPTER! #{match.string}"
  key = 'id'
  value = match[:value]
  adapter_line!(LSIArray::Adapter.new,key,value)
end

#attribute_line(key, value) ⇒ Object

Attribute



190
191
192
# File 'lib/elesai/megacli.rb', line 190

def attribute_line(key,value)
  @log.debug "  [#{current_state}] event: attribute_line: #{key} => #{value}"
end

#attribute_match(match) ⇒ Object

Attribute



393
394
395
396
397
398
# File 'lib/elesai/megacli.rb', line 393

def attribute_match(match)
  @log.debug "ATTRIBUTE! #{match.string}"
  key = match[:key].gsub(/\s+/,"").downcase
  value = match[:value].strip
  attribute_line!(key,value)
end

#bbu_capacityinfo_lineObject

BBU Capacity Info



322
323
324
# File 'lib/elesai/megacli.rb', line 322

def bbu_capacityinfo_line
  @log.debug "  [#{current_state}] event: bbu_capacityinfo_line:"
end

#bbu_capacityinfo_match(match) ⇒ Object



424
425
426
427
# File 'lib/elesai/megacli.rb', line 424

def bbu_capacityinfo_match(match)
  @log.debug "BBU CAPACITY INFO! #{match.string}"
  bbu_capacityinfo_line!
end

#bbu_designinfo_lineObject

BBU DesignInfo Status



271
272
273
# File 'lib/elesai/megacli.rb', line 271

def bbu_designinfo_line
  @log.debug "  [#{current_state}] event: bbu_designinfo_line:"
end

#bbu_designinfo_match(match) ⇒ Object



414
415
416
417
# File 'lib/elesai/megacli.rb', line 414

def bbu_designinfo_match(match)
  @log.debug "BBU DESIGN INFO! #{match.string}"
  bbu_designinfo_line!
end

#bbu_firmwarestatus_lineObject

BBU Firmware Status



255
256
257
# File 'lib/elesai/megacli.rb', line 255

def bbu_firmwarestatus_line
  @log.debug "  [#{current_state}] event: bbu_firmware_line:"
end

#bbu_firmwarestatus_match(match) ⇒ Object



409
410
411
412
# File 'lib/elesai/megacli.rb', line 409

def bbu_firmwarestatus_match(match)
  @log.debug "BBU FIRMWARE! #{match.string}"
  bbu_firmwarestatus_line!
end

#bbu_gasgaugestatus_lineObject

BBU GasGuage Status



305
306
307
# File 'lib/elesai/megacli.rb', line 305

def bbu_gasgaugestatus_line
  @log.debug "  [#{current_state}] event: bbu_gasgaugestatus_line:"
end

#bbu_gasgaugestatus_match(match) ⇒ Object



429
430
431
432
# File 'lib/elesai/megacli.rb', line 429

def bbu_gasgaugestatus_match(match)
  @log.debug "BBU GAS GUAGE STATUS! #{match.string}"
  bbu_gasgaugestatus_line!
end

#bbu_line(bbu, key, value) ⇒ Object

BBU



238
239
240
241
# File 'lib/elesai/megacli.rb', line 238

def bbu_line(bbu,key,value)
  @log.debug "  [#{current_state}] event: bbu_line: new #{bbu.inspect}"
  bbu[key.to_sym] = value.to_i
end

#bbu_match(match) ⇒ Object

BBU



401
402
403
404
405
406
407
# File 'lib/elesai/megacli.rb', line 401

def bbu_match(match)
  @log.debug "BBU! #{match.string}"
  key = 'id'
  value = match[:value]
  adapter_line(LSIArray::Adapter.new,key,value)
  bbu_line!(LSIArray::BBU.new,key,value)
end

#bbu_properties_lineObject

BBU Properties Status



288
289
290
# File 'lib/elesai/megacli.rb', line 288

def bbu_properties_line
  @log.debug "  [#{current_state}] event: bbu_designinfo_line:"
end

#bbu_properties_match(match) ⇒ Object



419
420
421
422
# File 'lib/elesai/megacli.rb', line 419

def bbu_properties_match(match)
  @log.debug "BBU PROPERTIES! #{match.string}"
  bbu_properties_line!
end

#exit_lineObject

Exit



340
341
342
# File 'lib/elesai/megacli.rb', line 340

def exit_line
  @log.debug "  [#{current_state}] event: exit_line"
end

#exit_match(match) ⇒ Object

Exit



436
437
438
439
# File 'lib/elesai/megacli.rb', line 436

def exit_match(match)
  @log.debug "EXIT! #{match.string}"
  exit_line!
end

#on_adapter_entry(old_state, event, *args) ⇒ Object



135
136
137
138
139
140
# File 'lib/elesai/megacli.rb', line 135

def on_adapter_entry(old_state, event, *args)
  @log.debug "        [#{current_state}] on_entry: leaving #{old_state}; args: #{args}"

  @context.close unless @context.current.nil? or @context.current === Elesai::LSIArray::Adapter
  @context.open args[0]
end

#on_adapter_exit(new_state, event, *args) ⇒ Object



142
143
144
145
# File 'lib/elesai/megacli.rb', line 142

def on_adapter_exit(new_state, event, *args)
  @log.debug "      [#{current_state}] on_exit: entering #{new_state}; args: #{args}"
  @context.flash!(new_state)
end

#on_attribute_entry(old_state, event, *args) ⇒ Object



194
195
196
197
198
199
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
# File 'lib/elesai/megacli.rb', line 194

def on_attribute_entry(old_state, event, *args)
  @log.debug "        [#{current_state}] entry: leaving #{old_state}; args: #{args}; context: #{@context.current.class}"


  c = @context.current
  k = args[0].to_sym
  v = args[1]

  # Some attributes require special treatment for our purposes

  case k
    when :coercedsize, :noncoercedsize, :rawsize, :size
      m = /(?<number>[0-9\.]+)\s+(?<unit>[A-Z]+)/.match(v)
      v = LSIArray::PhysicalDrive::Size.new(m[:number],m[:unit])
    when :raidlevel
      m = /Primary-(?<primary>\d+),\s+Secondary-(?<secondary>\d+)/.match(v)
      v = LSIArray::VirtualDrive::RaidLevel.new(m[:primary],m[:secondary])
    when :firmwarestate
      st,sp = v.gsub(/\s/,'').split(/,/)
      state = st.gsub(/\s/,'_').downcase.to_sym
      spin = sp.gsub(/\s/,'_').downcase.to_sym unless sp.nil?
      v = LSIArray::PhysicalDrive::FirmwareState.new(state,spin)
    when :state
      v = v.gsub(/\s/,'_').downcase.to_sym
    when :mediatype
      v = v.scan(/[A-Z]/).join
    when :inquirydata
      v = v.gsub(/\s+/,' ')
    when :relativedtateofcharge, :absolutestateofcharge, :remainingcapacityalarm, :remainingcapacity
      m = /(?<number>[0-9\.]+)\s+(?<unit>[A-Za-z%]+)/.match(v)
      v = LSIArray::BBU::NumberUnit.new(m[:number].to_f,m[:unit])
  end
  c[k] = v
end

#on_attribute_exit(new_state, event, *args) ⇒ Object



229
230
231
232
233
234
# File 'lib/elesai/megacli.rb', line 229

def on_attribute_exit(new_state, event, *args)
  @log.debug "      [#{current_state}] exit: entering #{new_state} throught event #{event}; args: #{args}"
  @context.close if @context.current.class == Elesai::LSIArray::PhysicalDrive and event != :attribute_line

  @context.flash!(new_state)
end

#on_bbu_capacityinfo_entry(old_state, event, *args) ⇒ Object



326
327
328
329
330
# File 'lib/elesai/megacli.rb', line 326

def on_bbu_capacityinfo_entry(old_state, event, *args)
  @log.debug "        [#{current_state}] on_entry: leaving #{old_state}; args: #{args}"
  @context.close
  @context.open @context.current[:capacityinfo]
end

#on_bbu_capacityinfo_exit(new_state, event, *args) ⇒ Object



332
333
334
335
# File 'lib/elesai/megacli.rb', line 332

def on_bbu_capacityinfo_exit(new_state, event, *args)
  @log.debug "      [#{current_state}] on_exit: entering #{new_state}; args: #{args}"
  @context.flash!(new_state)
end

#on_bbu_designinfo_entry(old_state, event, *args) ⇒ Object



275
276
277
278
279
# File 'lib/elesai/megacli.rb', line 275

def on_bbu_designinfo_entry(old_state, event, *args)
  @log.debug "        [#{current_state}] on_entry: leaving #{old_state}; args: #{args}"
  @context.close
  @context.open @context.current[:designinfo]
end

#on_bbu_designinfo_exit(new_state, event, *args) ⇒ Object



281
282
283
284
# File 'lib/elesai/megacli.rb', line 281

def on_bbu_designinfo_exit(new_state, event, *args)
  @log.debug "      [#{current_state}] on_exit: entering #{new_state}; args: #{args}"
  @context.flash!(new_state)
end

#on_bbu_entry(old_state, event, *args) ⇒ Object



243
244
245
246
# File 'lib/elesai/megacli.rb', line 243

def on_bbu_entry(old_state, event, *args)
  @log.debug "        [#{current_state}] on_entry: leaving #{old_state}; args: #{args}"
  @context.open args[0]
end

#on_bbu_exit(new_state, event, *args) ⇒ Object



248
249
250
251
# File 'lib/elesai/megacli.rb', line 248

def on_bbu_exit(new_state, event, *args)
  @log.debug "      [#{current_state}] on_exit: entering #{new_state}; args: #{args}"
  @context.flash!(new_state)
end

#on_bbu_firmwarestatus_entry(old_state, event, *args) ⇒ Object



259
260
261
262
# File 'lib/elesai/megacli.rb', line 259

def on_bbu_firmwarestatus_entry(old_state, event, *args)
  @log.debug "        [#{current_state}] on_entry: leaving #{old_state}; args: #{args}"
  @context.open @context.current[:firmwarestatus]
end

#on_bbu_firmwarestatus_exit(new_state, event, *args) ⇒ Object



264
265
266
267
# File 'lib/elesai/megacli.rb', line 264

def on_bbu_firmwarestatus_exit(new_state, event, *args)
  @log.debug "      [#{current_state}] on_exit: entering #{new_state}; args: #{args}"
  @context.flash!(new_state)
end

#on_bbu_gasgaugestatus_entry(old_state, event, *args) ⇒ Object



309
310
311
312
313
# File 'lib/elesai/megacli.rb', line 309

def on_bbu_gasgaugestatus_entry(old_state, event, *args)
  @log.debug "        [#{current_state}] on_entry: leaving #{old_state}; args: #{args}"
  @context.close
  @context.open @context.current[:gasgaugestatus]
end

#on_bbu_gasgaugestatus_exit(new_state, event, *args) ⇒ Object



315
316
317
318
# File 'lib/elesai/megacli.rb', line 315

def on_bbu_gasgaugestatus_exit(new_state, event, *args)
  @log.debug "      [#{current_state}] on_exit: entering #{new_state}; args: #{args}"
  @context.flash!(new_state)
end

#on_bbu_properties_entry(old_state, event, *args) ⇒ Object



292
293
294
295
296
# File 'lib/elesai/megacli.rb', line 292

def on_bbu_properties_entry(old_state, event, *args)
  @log.debug "        [#{current_state}] on_entry: leaving #{old_state}; args: #{args}"
  @context.close
  @context.open @context.current[:properties]
end

#on_bbu_properties_exit(new_state, event, *args) ⇒ Object



298
299
300
301
# File 'lib/elesai/megacli.rb', line 298

def on_bbu_properties_exit(new_state, event, *args)
  @log.debug "      [#{current_state}] on_exit: entering #{new_state}; args: #{args}"
  @context.flash!(new_state)
end

#on_exit_entry(new_state, event, *args) ⇒ Object



344
345
346
347
348
349
# File 'lib/elesai/megacli.rb', line 344

def on_exit_entry(new_state, event, *args)
  @log.debug "      [#{current_state}] exit: entering #{new_state} throught event #{event}; args: #{args}"
  until @context.current.nil? do
    @context.close
  end
end

#on_physicaldrive_entry(old_state, event, *args) ⇒ Object



178
179
180
181
# File 'lib/elesai/megacli.rb', line 178

def on_physicaldrive_entry(old_state, event, *args)
  @log.debug "        [#{current_state}] on_entry: leaving #{old_state}; args: #{args}"
  @context.open args[0]
end

#on_physicaldrive_exit(new_state, event, *args) ⇒ Object



183
184
185
186
# File 'lib/elesai/megacli.rb', line 183

def on_physicaldrive_exit(new_state, event, *args)
  @log.debug "      [#{current_state}] on_exit: entering #{new_state}; args: #{args}"
  @context.flash!(new_state)
end

#on_start_exit(new_state, event, *args) ⇒ Object

Start



123
124
125
126
# File 'lib/elesai/megacli.rb', line 123

def on_start_exit(new_state, event, *args)
  @log.debug "      [#{current_state}]: on_exit : #{event} -> #{new_state}; args: #{args}"
  @context = Context.new(current_state,@lsi)
end

#on_virtualdrive_entry(old_state, event, *args) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
# File 'lib/elesai/megacli.rb', line 154

def on_virtualdrive_entry(old_state, event, *args)
  @log.debug "        [#{current_state}] on_entry: leaving #{old_state}; args: #{args}"

  unless @context.current.nil?
    if @context.current === Elesai::LSIArray::VirtualDrive
      @context.close
    end
  end
  virtualdrive = args[0]
  @context.open virtualdrive
end

#on_virtualdrive_exit(new_state, event, *args) ⇒ Object



166
167
168
169
# File 'lib/elesai/megacli.rb', line 166

def on_virtualdrive_exit(new_state, event, *args)
  @log.debug "      [#{current_state}] on_exit: entering #{new_state}; args: #{args}"
  @context.flash!(new_state)
end

#parse!(lsi, opts) ⇒ Object

Parse!



443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
# File 'lib/elesai/megacli.rb', line 443

def parse!(lsi,opts)

  @lsi = lsi
  @log = Elesai::Logger.instance.log
  output = nil

  if STDIN.ready?
    output = $stdin.read
  else
    if opts[:fake].start_with? '-'
      megacli = opts[:megacli].nil? ? "Megacli" : opts[:megacli]
      command = "#{megacli} #{opts[:fake]} -nolog"
      command = Process.uid == 0 ? command : "sudo " << command
      output, stderr_str, status = Open3.capture3(command)
      raise RuntimeError, stderr_str unless status.exitstatus == 0
    else
      output = File.read(opts[:fake])
    end
  end

  output.each_line do |line|
    line.strip!
    next if line == ''

    begin
      case line
        when ADAPTER_RE              then  adapter_match(ADAPTER_RE.match(line))
        when BBU_RE                  then  bbu_match(BBU_RE.match(line))
        when VIRTUALDRIVE_RE         then  virtualdrive_match(VIRTUALDRIVE_RE.match(line))
        when PHYSICALDRIVE_RE        then  physicaldrive_match(PHYSICALDRIVE_RE.match(line))
        when BBU_FIRMWARESTATUS_RE   then  bbu_firmwarestatus_match(BBU_FIRMWARESTATUS_RE.match(line))
        when BBU_DESIGNINFO_RE       then  bbu_designinfo_match(BBU_DESIGNINFO_RE.match(line))
        when BBU_PROPERTIES_RE       then  bbu_properties_match(BBU_PROPERTIES_RE.match(line))
        when BBU_CAPACITYINFO_RE     then  bbu_capacityinfo_match(BBU_CAPACITYINFO_RE.match(line))
        when BBU_GASGAUGESTATUS_RE   then  bbu_gasgaugestatus_match(BBU_GASGAUGESTATUS_RE.match(line))
        when EXIT_RE                 then  exit_match(EXIT_RE.match(line))
        when ATTRIBUTE_RE            then  attribute_match(ATTRIBUTE_RE.match(line))
        else raise StandardError, "cannot parse '#{line}'"
      end
    rescue ArgumentError # ignore lines with invalid byte sequence in UTF-8
      next
    end

    @log.debug "\n\n"
  end
end

#physicaldrive_line(physicaldrive, key, value) ⇒ Object

Physical Drive



173
174
175
176
# File 'lib/elesai/megacli.rb', line 173

def physicaldrive_line(physicaldrive,key,value)
  @log.debug "  [#{current_state}] event: physicaldrive_line: new #{physicaldrive.inspect}"
  physicaldrive[key.to_sym] = value.to_i
end

#physicaldrive_match(match) ⇒ Object

Physical Drive



384
385
386
387
388
389
# File 'lib/elesai/megacli.rb', line 384

def physicaldrive_match(match)
  @log.debug "PHYSICALDRIVE! #{match.string}"
  key = match[:key].gsub(/\s+/,"").downcase
  value = match[:value]
  physicaldrive_line!(LSIArray::PhysicalDrive.new,key,value)
end

#virtualdrive_line(virtualdrive, key, value) ⇒ Object

Virtual Drive



149
150
151
152
# File 'lib/elesai/megacli.rb', line 149

def virtualdrive_line(virtualdrive,key,value)
  @log.debug "  [#{current_state}] event: virtualdrive_line: new #{virtualdrive.inspect}"
  virtualdrive[key.to_sym] = value.to_i
end

#virtualdrive_match(match) ⇒ Object

Virtual Drive



375
376
377
378
379
380
# File 'lib/elesai/megacli.rb', line 375

def virtualdrive_match(match)
  @log.debug "VIRTUALDRIVE! #{match.string}"
  key = match[:key].gsub(/\s+/,"").downcase
  value = match[:value]
  virtualdrive_line!(LSIArray::VirtualDrive.new,key,value)
end