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 62
def find_fix(result)
  if 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
end
makecommand() click to toggle source
# File lib/rubyipmi/freeipmi/commands/basecommand.rb, line 19
def makecommand
  # need to format the options to freeipmi format
  args = @options.collect { |k, v|
    # must remove from command line as its handled via conf file
    next if k == 'password'
    next if k == 'username'
    if not v
      "--#{k}"
    else
      "--#{k}=#{v}"
    end
  }.join(" ")
  return "#{cmd} #{args.rstrip}"
end
max_retry_count() click to toggle source
# File lib/rubyipmi/freeipmi/commands/basecommand.rb, line 15
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 7
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

# File lib/rubyipmi/freeipmi/commands/basecommand.rb, line 36
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
      if @result.length > 23
        raise "Error occurred"
      end
    when "bmc-config"
      if @result.length > 100 and exitstatus.success?
        return true
      else
        raise "Error occurred"
      end
    else
      if exitstatus.success?
        return true
      else
        raise "Error occurred"
      end
  end
end