Class: Rubyipmi::Freeipmi::Power

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

Instance Attribute Summary

Attributes inherited from BaseCommand

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

Instance Method Summary collapse

Methods inherited from BaseCommand

#find_fix, #makecommand, #max_retry_count, #setpass, #validate_status

Methods inherited from BaseCommand

#dump_command, #find_fix, #locate_command, #makecommand, #removepass, #run, #runcmd, #setpass, #update, #validate_status

Constructor Details

#initialize(opts = ObservableHash.new) ⇒ Power

Returns a new instance of Power.



4
5
6
# File 'lib/rubyipmi/freeipmi/commands/power.rb', line 4

def initialize(opts = ObservableHash.new)
  super("ipmipower", opts)
end

Instance Method Details

#command(opt) ⇒ Object

The command function is a wrapper that actually calls the run method



9
10
11
12
13
14
# File 'lib/rubyipmi/freeipmi/commands/power.rb', line 9

def command(opt)
  @options[opt] = false
  value = runcmd
  @options.delete_notify(opt)
  return @result
end

#cycleObject

Power cycle the system



27
28
29
30
31
32
33
34
35
# File 'lib/rubyipmi/freeipmi/commands/power.rb', line 27

def cycle
  # if the system is off turn it on
  if off?
    on
  else
    command("cycle")
  end

end

#offObject

Turn off the system



22
23
24
# File 'lib/rubyipmi/freeipmi/commands/power.rb', line 22

def off
  command("off")
end

#off?Boolean

Test to see if the power is off

Returns:

  • (Boolean)


65
66
67
# File 'lib/rubyipmi/freeipmi/commands/power.rb', line 65

def off?
  status == "off"
end

#onObject

Turn on the system



17
18
19
# File 'lib/rubyipmi/freeipmi/commands/power.rb', line 17

def on
  command("on")
end

#on?Boolean

Test to see if the power is on

Returns:

  • (Boolean)


60
61
62
# File 'lib/rubyipmi/freeipmi/commands/power.rb', line 60

def on?
  status == "on"
end

#powerInterruptObject



47
48
49
# File 'lib/rubyipmi/freeipmi/commands/power.rb', line 47

def powerInterrupt
  command("pulse")
end

#resetObject

Perform a power reset on the system



38
39
40
# File 'lib/rubyipmi/freeipmi/commands/power.rb', line 38

def reset
  command("reset")
end

#softShutdownObject

Perform a soft shutdown, like briefly pushing the power button



43
44
45
# File 'lib/rubyipmi/freeipmi/commands/power.rb', line 43

def softShutdown
  command("soft")
end

#statusObject

Get the power status of the system, will show either on or off



52
53
54
55
56
57
# File 'lib/rubyipmi/freeipmi/commands/power.rb', line 52

def status
  value = command("stat")
  if value
    @result.split(":").last.chomp.strip
  end
end