# File lib/rubyipmi/ipmitool/commands/fru.rb, line 9 def initialize(opts = ObservableHash.new) super("ipmitool", opts) @list = {} end
method to retrieve the raw fru data
# File lib/rubyipmi/ipmitool/commands/fru.rb, line 39 def getfrus command end
# File lib/rubyipmi/ipmitool/commands/fru.rb, line 18 def manufacturer list[DEFAULT_FRU]['product_manufacturer'] end
# File lib/rubyipmi/ipmitool/commands/fru.rb, line 26 def model list[DEFAULT_FRU]['product_manufacturer'] end
# File lib/rubyipmi/ipmitool/commands/fru.rb, line 14 def names list.keys end
# File lib/rubyipmi/ipmitool/commands/fru.rb, line 22 def serial list[DEFAULT_FRU]['board_serial'] end
run the command and return result
# File lib/rubyipmi/ipmitool/commands/fru.rb, line 92 def command @options["cmdargs"] = "fru" value = runcmd @options.delete_notify("cmdargs") if value return @result end end
I use method missing to allow the user to say Fru.<name> which returns a frudata object unless the user passes a keyname from the default fru device
# File lib/rubyipmi/ipmitool/commands/fru.rb, line 47 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 the fru information
# File lib/rubyipmi/ipmitool/commands/fru.rb, line 65 def parse(data) if ! data.nil? 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 end