class Rubyipmi::Freeipmi::Fru

Constants

DEFAULT_FRU

Attributes

list[RW]

Public Class Methods

new(opts = ObservableHash.new) click to toggle source
Calls superclass method Rubyipmi::BaseCommand.new
# File lib/rubyipmi/freeipmi/commands/fru.rb, line 9
def initialize(opts = ObservableHash.new)
    super("ipmi-fru", opts)
    @list = {}
end

Public Instance Methods

board_serial() click to toggle source
# File lib/rubyipmi/freeipmi/commands/fru.rb, line 28
def board_serial
  get_from_list('board_serial_number')
end
get_from_list(key) click to toggle source
# File lib/rubyipmi/freeipmi/commands/fru.rb, line 14
def get_from_list(key)
  if list.has_key?(DEFAULT_FRU)
    if list[DEFAULT_FRU].has_key?(key)
       list[DEFAULT_FRU][key]
     else
       nil
     end
  end
end
getfrus() click to toggle source

method to retrieve the raw fru data

# File lib/rubyipmi/freeipmi/commands/fru.rb, line 41
def getfrus
  command
  return @result
end
manufacturer() click to toggle source
# File lib/rubyipmi/freeipmi/commands/fru.rb, line 24
def manufacturer
  get_from_list('board_manufacturer')
end
model() click to toggle source
# File lib/rubyipmi/freeipmi/commands/fru.rb, line 36
def model
  get_from_list('board_product_name')
end
names() click to toggle source
# File lib/rubyipmi/freeipmi/commands/fru.rb, line 46
def names
  list.keys
end
serial() click to toggle source
# File lib/rubyipmi/freeipmi/commands/fru.rb, line 32
def serial
  get_from_list('board_serial_number')
end

Private Instance Methods

command() click to toggle source

run the command and return result

# File lib/rubyipmi/freeipmi/commands/fru.rb, line 106
def command
   value = runcmd
   if value
     return @result
   end
end
method_missing(method, *args, &block) click to toggle source
# File lib/rubyipmi/freeipmi/commands/fru.rb, line 60
def method_missing(method, *args, &block)
  name = method.to_s
  fru = list.fetch(name, nil)
  # if the user wanted some data from the default fru, lets show the data for the fru.  Otherwise
  # we return the Fru with the given name
  if fru.nil?
    if list[DEFAULT_FRU].keys.include?(name)
      return list[DEFAULT_FRU][name]
    else
      # maybe we should return nil instead? hmm...
      raise NoMethodError
    end
  else
    return fru
  end
end
parse(data) click to toggle source

parse the fru information

# File lib/rubyipmi/freeipmi/commands/fru.rb, line 78
def parse(data)
  if ! data.nil? and ! data.empty?
    parsed_data = []
    data.lines.each do |line|
      if line =~ /^FRU.*/
        # this is the either the first line of of the fru or another fru
        if parsed_data.count != 0
          # we have reached a new fru device so lets record the previous fru
          new_fru = FruData.new(parsed_data)
          parsed_data = []
          @list[new_fru[:name]] = new_fru
        end

      end
      parsed_data << line
    end
    # process the last fru
    if parsed_data.count != 0
      # we have reached a new fru device so lets record the previous fru
      new_fru = FruData.new(parsed_data)
      parsed_data = []
      @list[new_fru[:name]] = new_fru
    end
  end
  return @list
end