Class: Rubyipmi::Freeipmi::BaseCommand

Inherits:
BaseCommand show all
Defined in:
lib/rubyipmi/freeipmi/commands/basecommand.rb

Direct Known Subclasses

Bmc, BmcConfig, BmcDevice, BmcInfo, Chassis, ChassisConfig, Fru, Power, Sensors

Instance Attribute Summary

Attributes inherited from BaseCommand

#cmd, #lastcall, #options, #passfile, #result

Instance Method Summary collapse

Methods inherited from BaseCommand

#dump_command, #initialize, #locate_command, #removepass, #run, #runcmd, #update

Constructor Details

This class inherits a constructor from Rubyipmi::BaseCommand

Instance Method Details

#find_fix(result) ⇒ Object

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



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/rubyipmi/freeipmi/commands/basecommand.rb', line 63

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

#makecommandObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rubyipmi/freeipmi/commands/basecommand.rb', line 20

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_countObject



16
17
18
# File 'lib/rubyipmi/freeipmi/commands/basecommand.rb', line 16

def max_retry_count
  @max_retry_count ||= Rubyipmi::Freeipmi::ErrorCodes.length
end

#setpassObject



7
8
9
10
11
12
13
14
# 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) ⇒ Object

This method will check if the results are really valid as the exit code can be misleading and incorrect



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# 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
        return true
      else
        raise "Error occurred"
      end
    else
      if exitstatus.success?
        return true
      else
        raise "Error occurred"
      end

  end
end