Class: Ropian::Control::Generic
- Inherits:
-
Object
- Object
- Ropian::Control::Generic
- Defined in:
- lib/ropian/control/generic.rb
Constant Summary collapse
- States =
[:on, :off, :reboot]
Instance Method Summary collapse
-
#initialize(ip_addr, community, version = :SNMPv2c) ⇒ Generic
constructor
A new instance of Generic.
- #inspect ⇒ Object
- #reboot(port_index) ⇒ Object
- #set_state(state, port_index) ⇒ Object
- #turn_off(port_index) ⇒ Object
- #turn_on(port_index) ⇒ Object
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
#inspect ⇒ Object
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
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 |