# rubyipmi This gem is a ruby wrapper for the freeipmi and ipmitool command line tools. It provides a ruby implementation of ipmi commands that will make it simple to connect to BMC devices from ruby. ## Using the library in your code ### Install 1. Install the freeipmi from source (http://www.gnu.org/software/freeipmi/) or ipmitool 2. gem install rubyipmi ### General Usage ` require 'rubyipmi' ` #### Create a connection object `conn = Rubyipmi.connect("username", "password", "hostname", "providertype) ` Providertype: optional (ipmitool or freeipmi) If you don't specify the provider type, Rubyipmi will detect if freeipmi or ipmitool is installed and load the first tool found. If you specify the provider type rubyipmi will only use that specific provider. #### Use power functions (not all listed)
conn.chassis.power.on conn.chassis.power.off conn.chassis.power.on? conn.chassis.power.off? conn.chassis.power.cycle#### Boot to specific device
conn.chassis.bootpxe(true, false) # reboot after setting, one time boot only - non persistent conn.chassis.bootdisk(false, false) # boot to disk on next reboot, don't reboot automatically## Testing There are a series of automated rspec tests that test the functionality of this library with the ipmi device. In order to perform use the following steps. DO NOT PERFORM THESE TEST ON ANY PRODUCTION SYSTEM. THESE TESTS WILL TURN OFF THE DEVICE! 1. Install gem via source 2. bundle install 3. rake ipmiuser=ipmiuser ipmipass=ipmiuserpass ipmihost=192.168.1.22 ipmiprovider=freeipmi (fill in your your details) 4. report any failures with your make/model/firmware revision to corey@logicminds.biz ## Security Currently security is not enforced in the development process. Furthermore, the rubyipmi library uses the same methods currently provided by the C based freeipmi command line tools. This includes the use of freeipmi.conf file. You can easily store credentials in this file which will be included automatically via the command line. ## How the library works Since this library is based off of running a suite of command line tools I have created a base class called baseCommand that performs the actual execution of the command. The baseCommand only executes the command with the supplied arguments and options and returns the exit status. Additionally the result of the executed command is stored in the result variable should we need to retrieve the output of the command. To further extend the baseCommand class. ### Creating a new command Creating a new command is actually quite simple. Follow these steps to wrap a freeipmi or ipmitool command. 1. Create a new subclass of BaseCommand 2. define the initialize function like so, and pass in the name of the command line tool to the super constructor. ``` def initialize(opts = {}) @options = opts super("bmc-info", opts) end ``` ``` def initialize(opts = {}) @options = opts super("ipmitool", opts) end ``` 3. Thats it. The rest of the class is related to running the command and interperting the results ### Writing a function for running a command The freeipmi command line tools have two different ways to run the commands. 1. ``` ipmipower --hostname=host --password=pass --username=user --off ``` (single action, multiple arguments) 2. ``` ipmi-chassis --hostname=host --password=pass --username=user --chassis-identify=FORCE ``` (multiple arguments, one main action with different qualifers) Because of the varying ways to run a command I have simplified them so it makes it easy to call the command line tools. 1. Each subclassed baseCommand class inherits runcmd, result, cmd, and runcmd_with_args. 2. The cmd executable gets set when instantiating a baseCommand class, where the class also finds the path of the executable. 3. The options variable gets set when instantiating a subclass of the baseCommand class. ### Running the cmd 1. To run the cmd, just call ``` runcmd ``` (which will automatically set all the options specified in the options hash) 2. To run the cmd, with arguments and options call ``` runcmd([]) ``` and pass in a array of the arguments. (Arguments are actions only and look like --off, --on, --action) 3. To run the cmd, with just arguments ``` runcmd_with_args([]) ``` and pass in a array of the arguments. (Example: 192.168.1.1) ### The Options hash The options hash can be considered a global hash that is passed in through the connection object. Most of the options will be set at the connection level. However, most commands require additional options that should be set at the subclassed BaseCommand level. You must not forget to unset the option after calling the runcmd command. Failure to do so will add previous options to subsequent run options. Example: ``` def ledlight(status=false, delay=300) if status if delay <= 0 options["chassis-identify"] = "FORCE" else options["chassis-identify"] = delay end else options["chassis-identify"] = "TURN-OFF" end # Run the command run # unset the option by deleting from hash options.delete("chassis-identify") end ``` ### How to get the results of the command After running a command it may be desirable to get the results for further processing. To get the results, follow the example below: Example: ``` def status command("--stat") @result.split(":").last.chomp.trim end def command(opt) status = run([opt]) return status end def on? status == "on" end ``` ### The command function Although its not necessary to implement the command function it may be desirable if your code starts to repeat itself. In this example the command function is just a wrapper command that calls run. Your implementation will vary, but be sure to always call it the "command" function, so its easily identified. Additionally, should this gem ever become out of date one could call the command function and pass in any arguments that have not already been implemented in the rest of the class. ``` def command(opt) status = runcmd([opt]) return status end def on command("--on") end ``` ## The following are tools bundled with freeipmi * ipmi-chassis * ipmi-oem * ipmi-chassis-config * ipmiping * ipmiconsole * ipmipower * ipmidetect * ipmi-raw * ipmi-fru * ipmi-sel * ipmi-locate * ipmi-sensors * ipmimonitoring * ipmi-sensors-config * bmc-config * bmc-device * bmc-info ## To contrast ipmitool has one command with many options * ipmitool ## Auto Detect workarounds IPMI is great for a vendor neutral management interface. However, not all servers are 100% compatible with the specifications. In order to overcome ipmi non-compliance there will be some workarounds built into this library ## Contributing to rubyipmi * Check out the latest code to make sure the feature hasn't been implemented or the bug hasn't been fixed yet. * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it. * Fork the project. * Start a feature/bugfix branch. * Commit and push until you are happy with your contribution. * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally. * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it. ## Copyright Copyright (c) 2012 Corey Osman. See LICENSE.txt for further details. ## Freeipmi Documented Workarounds One of my design goals is to raise exceptions and have the library try workarounds before ultimately failing since there is a whole list of workarounds that can be attempted.However, it would be nice to know the make and model of the server up front to decrease workaround attempts. So essentially I need to figure out how to save a command call and then retry if it doesn't work. With so many different vendors implementing their own IPMI solutions, different vendors may implement their IPMI protocols incorrectly. The following describes a number of workarounds currently available to handle discovered compliance issues. When possible, workarounds have been implemented so they will be transparent to the user. However, some will require the user to specify a workaround be used via the -W option. The hardware listed below may only indicate the hardware that a problem was discovered on. Newer versions of hardware may fix the problems indicated below. Similar machines from vendors may or may not exhibit the same problems. Different vendors may license their firmware from the same IPMI firmware developer, so it may be worthwhile to try workarounds listed below even if your motherboard is not listed. If you believe your hardware has an additional compliance issue that needs a workaround to be implemented, please contact the FreeIPMI maintainers on