lib/rubyipmi.rb in rubyipmi-0.6.0 vs lib/rubyipmi.rb in rubyipmi-0.7.0
- old
+ new
@@ -1,17 +1,16 @@
require 'rubyipmi/ipmitool/connection'
require 'rubyipmi/freeipmi/connection'
-require 'net/smtp'
module Rubyipmi
# 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
- def self.connect(user, pass, host, provider="any")
+ def self.connect(user, pass, host, provider="any",debug=false)
# use this variable to reduce cmd calls
installed = false
# use the first available provider
@@ -28,13 +27,13 @@
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)
+ @conn = Rubyipmi::Freeipmi::Connection.new(user, pass, host, debug)
elsif provider == "ipmitool"
- @conn = Rubyipmi::Ipmitool::Connection.new(user,pass,host)
+ @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?
@@ -46,21 +45,31 @@
def self.connection
return @conn if @conn
raise "No Connection available, please use the connect method"
end
+ # method used to find the command which also makes it easier to mock with
+ def self.locate_command(commandname)
+ location = `which #{commandname}`.strip
+ if not $?.success?
+ location = nil
+ end
+ return location
+ end
+
# Return true or false if the provider is available
def self.is_provider_installed?(provider)
case provider
when "freeipmi"
- cmdpath = `which ipmipower`.strip
+ cmdpath = locate_command('ipmipower')
when "ipmitool"
- cmdpath = `which ipmitool`.strip
+ cmdpath = locate_command('ipmitool')
else
raise "Invalid BMC provider type"
end
- return $?.success?
+ # return false if command was not found
+ return ! cmdpath.nil?
end
def self.providers
["freeipmi", "ipmitool"]
end
@@ -78,14 +87,27 @@
end
end
return available
end
- 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
+ # gets data from the bmc device and puts in a hash for diagnostics
+ 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
+
end