class Rubyipmi::Freeipmi::BaseCommand

Public Instance Methods

find_fix(result) click to toggle source

The findfix method acts like a recursive method and applies fixes defined in the errorcodes If a fix is found it is applied to the options hash, and then the last run command is retried until all the fixes are exhausted or a error not defined in the errorcodes is found

# File lib/rubyipmi/freeipmi/commands/basecommand.rb, line 55
def find_fix(result)
  return unless result
  # The errorcode code hash contains the fix
  begin
    fix = ErrorCodes.search(result)
    @options.merge_notify!(fix)
  rescue
    raise "Could not find fix for error code: \n#{result}"
  end
end
makecommand() click to toggle source
# File lib/rubyipmi/freeipmi/commands/basecommand.rb, line 17
def makecommand
  # need to format the options to freeipmi format
  args = @options.collect do |k, v|
    # must remove from command line as its handled via conf file
    next if k == 'password'
    next if k == 'username'
    if !v
      "--#{k}"
    else
      "--#{k}=#{v}"
    end
  end.join(" ")

  "#{cmd} #{args.rstrip}"
end
max_retry_count() click to toggle source
# File lib/rubyipmi/freeipmi/commands/basecommand.rb, line 13
def max_retry_count
  @max_retry_count ||= Rubyipmi::Freeipmi::ErrorCodes.length
end
setpass() click to toggle source
Calls superclass method Rubyipmi::BaseCommand#setpass
# File lib/rubyipmi/freeipmi/commands/basecommand.rb, line 5
def setpass
  super
  @options["config-file"] = @passfile.path
  @passfile.write "username #{@options['username']}\n"
  @passfile.write "password #{@options['password']}\n"
  @passfile.close
end
validate_status(exitstatus) click to toggle source

This method will check if the results are really valid as the exit code can be misleading and incorrect this is required because freeipmi in older version always returned 0 even if an error occured

Calls superclass method Rubyipmi::BaseCommand#validate_status
# File lib/rubyipmi/freeipmi/commands/basecommand.rb, line 35
def validate_status(exitstatus)
  case @cmdname
  when "ipmipower"
    # until ipmipower returns the correct exit status this is a hack
    # essentially any result greater than 23 characters is an error
    raise "Error occurred" if @result.length > 23
  when "bmc-config"
    if @result.length > 100 && exitstatus.success?
      return true
    else
      raise "Error occurred"
    end
  else
    super
  end
end