Rubyipmi

Public Class Methods

connect(user, pass, host, provider="any") 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 12
def self.connect(user, pass, host, provider="any")

  # 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)
    elsif provider == "ipmitool"
      @conn = Rubyipmi::Ipmitool::Connection.new(user,pass,host)
    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 46
def self.connection
  return @conn if @conn
  raise "No Connection available, please use the connect method"
end
is_provider_installed?(provider) click to toggle source

Return true or false if the provider is available

# File lib/rubyipmi.rb, line 52
def self.is_provider_installed?(provider)
  case provider
    when "freeipmi"
      cmdpath = `which ipmipower`.strip
    when "ipmitool"
      cmdpath = `which ipmitool`.strip
    else
      raise "Invalid BMC provider type"
  end
  return $?.success?
end
printdiag(user, pass, host) click to toggle source
# File lib/rubyipmi.rb, line 83
def self.printdiag(user, pass, host)
  @conn = Rubyipmi::connect(user, pass, host)
  puts "Product: #{@conn.fru.product}"
  puts "Manufacturer: #{@conn.fru.manufacturer}"
  puts "BMC Info #{@conn.bmc.info.inspect}\n"
  puts "Please email to corey@logicminds.biz when troubleshooting"
  return true
end
provider_installed?() click to toggle source

returns true if any of the providers are installed

# File lib/rubyipmi.rb, line 69
def self.provider_installed?
  providers_installed?.length > 0
end
providers() click to toggle source
# File lib/rubyipmi.rb, line 64
def self.providers
  ["freeipmi", "ipmitool"]
end
providers_installed?() click to toggle source
# File lib/rubyipmi.rb, line 73
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.