Rubyipmi

Public Class Methods

connect(user, pass, host, provider="any",debug=false) click to toggle source

The connect method will create a connection object based the provider type passed in If provider is left blank the function will use the first available provider

# File lib/rubyipmi.rb, line 11
def self.connect(user, pass, host, provider="any",debug=false)

  # use this variable to reduce cmd calls
  installed = false

  # use the first available provider
  if provider == "any"
    if is_provider_installed?("freeipmi")
      provider = "freeipmi"
      installed = true
    elsif is_provider_installed?("ipmitool")
      provider = "ipmitool"
      installed = true
    else
      raise "No IPMI provider is installed, please install freeipmi or ipmitool"
    end
  end

  # If the provider is available create a connection object
  if installed or is_provider_installed?(provider)
    if provider == "freeipmi"
      @conn = Rubyipmi::Freeipmi::Connection.new(user, pass, host, debug)
    elsif provider == "ipmitool"
      @conn = Rubyipmi::Ipmitool::Connection.new(user,pass,host, debug)
    else
      raise "Incorrect provider given, must use freeipmi or ipmitool"
    end
  else
    # Can't find the provider command line tool, maybe try other provider?
    raise "The IPMI provider: #{provider} is not installed"

  end
end
connection() click to toggle source
# File lib/rubyipmi.rb, line 45
def self.connection
  return @conn if @conn
  raise "No Connection available, please use the connect method"
end
get_diag(user, pass, host) click to toggle source

gets data from the bmc device and puts in a hash for diagnostics

# File lib/rubyipmi.rb, line 93
def self.get_diag(user, pass, host)
  data = {}

  if Rubyipmi.is_provider_installed?('freeipmi')
    @freeconn = Rubyipmi::connect(user, pass, host, 'freeipmi')
    if @freeconn
      puts "Retrieving freeipmi data"
      data['freeipmi'] = @freeconn.get_diag
    end
  end
  if Rubyipmi.is_provider_installed?('ipmitool')
    @ipmiconn = Rubyipmi::connect(user, pass, host, 'ipmitool')
    if @ipmiconn
      puts "Retrieving ipmitool data"
      data['ipmitool'] = @ipmiconn.get_diag
    end
  end
  return data
end
is_provider_installed?(provider) click to toggle source

Return true or false if the provider is available

# File lib/rubyipmi.rb, line 60
def self.is_provider_installed?(provider)
  case provider
    when "freeipmi"
      cmdpath = locate_command('ipmipower')
    when "ipmitool"
      cmdpath = locate_command('ipmitool')
    else
      raise "Invalid BMC provider type"
  end
  # return false if command was not found
  return ! cmdpath.nil?
end
locate_command(commandname) click to toggle source

method used to find the command which also makes it easier to mock with

# File lib/rubyipmi.rb, line 51
def self.locate_command(commandname)
  location = `which #{commandname}`.strip
  if not $?.success?
    location = nil
  end
  return location
end
provider_installed?() click to toggle source

returns true if any of the providers are installed

# File lib/rubyipmi.rb, line 78
def self.provider_installed?
  providers_installed?.length > 0
end
providers() click to toggle source
# File lib/rubyipmi.rb, line 73
def self.providers
  ["freeipmi", "ipmitool"]
end
providers_installed?() click to toggle source
# File lib/rubyipmi.rb, line 82
def self.providers_installed?
  available = []
  providers.each do |prov|
    if is_provider_installed?(prov)
      available << prov
    end
  end
  return available
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.