Sha256: 9ea9870eea37f4d9f7b4a15f44359c1673f5e42849b8c8be46a8f3e53726baaf

Contents?: true

Size: 1.93 KB

Versions: 2

Compression:

Stored size: 1.93 KB

Contents

module Rubyipmi::Ipmitool

  class Bmc < Rubyipmi::Ipmitool::BaseCommand

    attr_accessor :config

    def initialize(opts = ObservableHash.new)
      super("ipmitool", opts)
      @bmcinfo = {}
    end

    def lan
      @lan ||= Rubyipmi::Ipmitool::Lan.new(@options)
    end

    def info
      if @bmcinfo.length > 0
        @bmcinfo
      else
        retrieve
      end
    end

    # reset the bmc device, useful for troubleshooting
    def reset(type='cold')
      if ['cold', 'warm'].include?(type)
         @options["cmdargs"] = "bmc reset #{type}"
         value = runcmd()
         @options.delete_notify("cmdargs")
         return value
      else
        raise "reset type: #{type} is not a valid choice, use warm or cold"
      end

    end

    def guid
      @options["cmdargs"] = "bmc guid"
      value = runcmd()
      @options.delete_notify("cmdargs")
      if value
        @result.lines.each { | line |
          line.chomp
          if line =~ /GUID/
            line.split(":").last.strip
          end
        }
      end

    end

    # This function will get the bmcinfo and return a hash of each item in the info
    def retrieve
      @options["cmdargs"] = "bmc info"
      status = runcmd
      @options.delete_notify("cmdargs")
      subkey = nil
      if not status
        raise @result
      else
        @result.lines.each do |line|
          # clean up the data from spaces
          item = line.split(':')
          key = item.first.strip
          value = item.last.strip
          # if the following condition is met we have subvalues
          if value.empty?
            subkey = key
            @bmcinfo[subkey] = []
          elsif key == value and subkey
            # subvalue found
            @bmcinfo[subkey] << value
          else
            # Normal key/value pair with no subkeys
            subkey = nil
            @bmcinfo[key] = value
          end
        end
        return @bmcinfo
      end
    end


  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubyipmi-0.8.1 lib/rubyipmi/ipmitool/commands/bmc.rb
rubyipmi-0.7.0 lib/rubyipmi/ipmitool/commands/bmc.rb