Class: Ropian::Control::Generic

Inherits:
Object
  • Object
show all
Defined in:
lib/ropian/control/generic.rb

Direct Known Subclasses

APC, Raritan

Constant Summary collapse

States =
[:on, :off, :reboot]

Instance Method Summary collapse

Constructor Details

#initialize(ip_addr, community, version = :SNMPv2c) ⇒ Generic

Returns a new instance of Generic.



8
9
10
11
# File 'lib/ropian/control/generic.rb', line 8

def initialize(ip_addr, community, version = :SNMPv2c)
  @manager = SNMP::Manager.new(:Host => ip_addr,
    :Community => community, :Version => version)
end

Instance Method Details

#inspectObject



5
6
7
# File 'lib/ropian/control/generic.rb', line 5

def inspect
  "#<#{self.class} #{@manager.host}@#{@manager.community}>"
end

#reboot(port_index) ⇒ Object



18
19
20
# File 'lib/ropian/control/generic.rb', line 18

def reboot(port_index)
  set_state(:reboot, port_index)
end

#set_state(state, port_index) ⇒ Object

Raises:

  • (ArgumentError)


21
22
23
24
25
# File 'lib/ropian/control/generic.rb', line 21

def set_state(state, port_index)
  raise ArgumentError, "invalid state" unless States.include?(state)
  @manager.set(SNMP::VarBind.new(base_oid + port_index,
                                  SNMP::Integer.new(state_order.index(state))))
end

#turn_off(port_index) ⇒ Object



15
16
17
# File 'lib/ropian/control/generic.rb', line 15

def turn_off(port_index)
  set_state(:off, port_index)
end

#turn_on(port_index) ⇒ Object



12
13
14
# File 'lib/ropian/control/generic.rb', line 12

def turn_on(port_index)
  set_state(:on, port_index)
end