class Elesai::Megacli::Megacli
Public Instance Methods
adapter_line(adapter,key,value)
click to toggle source
Adapter
# File lib/elesai/megacli/megacli.rb, line 115 def adapter_line(adapter,key,value) @log.debug " [#{current_state}] event adapter_line: new #{adapter.inspect}" adapter[key.to_sym] = value.to_i @lsi.add(adapter) end
adapter_match(k,match)
click to toggle source
Adapter
# File lib/elesai/megacli/megacli.rb, line 80 def adapter_match(k,match) @log.debug "ADAPTER! #{match.string}" key = 'id' value = match[:value] adapter_line!(LSI::Adapter.new,key,value) end
attribute_line(key,value)
click to toggle source
Attribute
# File lib/elesai/megacli/megacli.rb, line 135 def attribute_line(key,value) @log.debug " [#{current_state}] event: attribute_line: #{key} => #{value}" end
attribute_match(k,match)
click to toggle source
Attribute
# File lib/elesai/megacli/megacli.rb, line 89 def attribute_match(k,match) @log.debug "ATTRIBUTE! #{match.string}" key = match[:key].gsub(/\s+/,"").downcase value_tmp = match[:value] value = value_tmp.nil? ? nil : value_tmp.strip attribute_line!(key,value) end
exit_line()
click to toggle source
Exit
# File lib/elesai/megacli/megacli.rb, line 182 def exit_line @log.debug " [#{current_state}] event: exit_line" end
exit_match(k,match)
click to toggle source
Exit
# File lib/elesai/megacli/megacli.rb, line 99 def exit_match(k,match) @log.debug "EXIT! #{match.string}" exit_line! end
on_adapter_entry(old_state, event, *args)
click to toggle source
# File lib/elesai/megacli/megacli.rb, line 121 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 Elesai::LSI::Adapter === @context.current @context.open args[0] end
on_adapter_exit(new_state, event, *args)
click to toggle source
# File lib/elesai/megacli/megacli.rb, line 128 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)
click to toggle source
# File lib/elesai/megacli/megacli.rb, line 139 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 = LSI::PhysicalDrive::Size.new(m[:number],m[:unit]) when :raidlevel m = /Primary-(?<primary>\d+),\s+Secondary-(?<secondary>\d+)/.match(v) v = LSI::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 = LSI::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 :relativestateofcharge, :absolutestateofcharge, :remainingcapacity, :designcapacity # :remainingcapacityalarm is treated a plain string m = /(?<number>[0-9\.]+)\s+(?<unit>[A-Za-z%]+)/.match(v) v = LSI::BBU::NumberUnit.new(m[:number].to_f,m[:unit]) end c[k] = v end
on_attribute_exit(new_state, event, *args)
click to toggle source
# File lib/elesai/megacli/megacli.rb, line 173 def on_attribute_exit(new_state, event, *args) @log.debug " [#{current_state}] exit: entering #{new_state} throught event #{event}; args: #{args}" @context.close if Elesai::LSI::PhysicalDrive === @context.current and event != :attribute_line @context.flash!(new_state) end
on_exit_entry(new_state, event, *args)
click to toggle source
# File lib/elesai/megacli/megacli.rb, line 186 def on_exit_entry(new_state, event, *args) @log.debug " [#{current_state}] exit: entering #{new_state} through event #{event}; args: #{args}" until @context.current.nil? do @context.close end end
on_start_exit(new_state, event, *args)
click to toggle source
Start
# File lib/elesai/megacli/megacli.rb, line 108 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
parse!(lsi,opts)
click to toggle source
Parse!
# File lib/elesai/megacli/megacli.rb, line 195 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| begin line.strip! line.gsub!(/^=+$/,'') next if line == '' match_flag = false @megacli.each do |k, v| if line =~ v[:re] v[:method].call(k,v[:re].match(line)) match_flag = true break else match_flag = false next end end raise StandardError, "cannot parse '#{line}'" unless match_flag rescue ArgumentError # ignore lines with invalid byte sequence in UTF-8 next end end end