logicminds / rubyipmi

Command line wrapper for ipmitool and freeipmi
GNU Lesser General Public License v2.1
35 stars 32 forks source link

Add support for raw IPMI commands #45

Open korekhov opened 7 years ago

korekhov commented 7 years ago

Something like this, I'd imagine (very simplified version, but even that does not work for me, so looking for your guidance here):


module Rubyipmi::Ipmitool
  class Raw < Rubyipmi::Ipmitool::BaseCommand
    def initialize(opts = ObservableHash.new)
      super("ipmitool", opts)
    end

    def raw_cmd(opt)
      @options["cmdargs"] = "raw #{opt}"
      value = runcmd
      @options.delete_notify("cmdargs")
      if value
        @result
      end
    end

    def test
      raw_cmd("0x00")
    end

  end
end

WIth the following added to lib/rubyipmi/ipmitool/connection.rb

      def raw
        @raw ||= Rubyipmi::Ipmitool::Raw.new(@options)
      end

I get the following output:

# irb
irb(main):001:0> require 'rubyipmi'
=> true
irb(main):002:0> conn = Rubyipmi.connect("root", "root", "<IP>", "ipmitool")
=> #<Rubyipmi::Ipmitool::Connection:0x000000011b2898 @options={"H"=>"<IP>", "U"=>"root", "P"=>"root", "I"=>"lanplus"}>
irb(main):003:0>
irb(main):004:0* conn.raw.test
=> nil
irb(main):005:0>
korekhov commented 7 years ago

The expected result from above:

# ipmitool -I lanplus -U root -P root -H <IP> raw 0x00
Not enough parameters given.
RAW Commands:  raw <netfn> <cmd> [data]

Network Function Codes:

  VAL   HEX STRING
==============================================
  0 0x00    Chassis
  2 0x02    Bridge
  4 0x04    SensorEvent
  6 0x06    Application
  8 0x08    Firmware
  10    0x0a    Storage
  12    0x0c    Transport

(can also use raw hex values)
korekhov commented 7 years ago

Never mind - since the exit code of running "raw 0x00" is actually "1", the code works properly as "value" does not get set to true so never returns the output received from BMC.

If change the code to this:

    def raw_cmd(opt)
      @options["cmdargs"] = "raw #{opt}"
      value = runcmd
      @options.delete_notify("cmdargs")
      @result
    end

everything works fine and I get this output:

irb(main):006:0* conn.raw.test
=> "Not enough parameters given.\nRAW Commands:  raw <netfn> <cmd> [data]\n\nNetwork Function Codes:\n\n  VAL\tHEX\tSTRING\n==============================================\n  0\t0x00\tChassis\n  2\t0x02\tBridge\n  4\t0x04\tSensorEvent\n  6\t0x06\tApplication\n  8\t0x08\tFirmware\n  10\t0x0a\tStorage\n  12\t0x0c\tTransport\n\n(can also use raw hex values)\n"
irb(main):007:0>