Skip to content

Commit b9c0a40

Browse files
committed
Add gude8210 snmp support
Signed-off-by: Onur Celep <[email protected]>
1 parent 2ce9e24 commit b9c0a40

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

doc/configuration.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ Currently available are:
192192
``gude8031``
193193
Controls *Gude Expert Power Control 8031 PDUs* and *Gude Expert Power Control 87-1210-18 PDUs* via a simple HTTP API.
194194

195+
``gude8210``
196+
Controls *Gude Expert Power Control 8210 PDUs* via SNMP.
197+
195198
``gude8225``
196199
Controls *Gude Expert Power Control 8225 PDUs* via a simple HTTP API.
197200

labgrid/driver/power/gude8210.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
from ..exception import ExecutionError
2+
from ...util.snmp import SimpleSNMP
3+
4+
# Base OID for the Gude power switch as per the MIB file from gude8210
5+
POWER_OID_BASE = "1.3.6.1.4.1.28507.1.1.2.2.1.3"
6+
NUMBER_OF_OUTLETS = 8 # Max number of outlets from the MIB
7+
8+
9+
def power_set(host, port, index, value):
10+
"""
11+
Sets the power state of a specific outlet on the Gude power switch.
12+
13+
Args:
14+
host (str): The IP address of the power switch.
15+
port (int or None): SNMP port, default is 161 or None.
16+
index (int): Outlet index.
17+
value (bool): True to turn on, False to turn off.
18+
community (str): SNMP community string.
19+
"""
20+
# Validate index within allowable range
21+
if index is None or not (1 <= int(index) <= NUMBER_OF_OUTLETS):
22+
raise ExecutionError("Invalid outlet index. Ensure the index is within the range 1 to 8.")
23+
24+
# Setup SNMP connection and OID for the target outlet
25+
_snmp = SimpleSNMP(host, 'private', port=port)
26+
oid = f"{POWER_OID_BASE}.{index}"
27+
snmp_value = "1" if value else "0" # SNMP value for on/off
28+
29+
print(f"Debug: Attempting SNMP SET on host {host}, OID {oid}, value {snmp_value}")
30+
31+
try:
32+
# Set the power state for the specified outlet
33+
_snmp.set(oid, snmp_value)
34+
print(f"Debug: SNMP SET successful for OID {oid} with value {snmp_value}")
35+
except Exception as e:
36+
print(f"Debug: SNMP SET failed for OID {oid} with exception {e}")
37+
raise ExecutionError(f"Failed to set power state on outlet {index}: {e}")
38+
39+
40+
def power_get(host, port, index):
41+
"""
42+
Retrieves the current power state of a specific outlet on the Gude power switch.
43+
44+
Args:
45+
host (str): The IP address of the power switch.
46+
port (int or None): SNMP port, default is 161 or None.
47+
index (int): Outlet index.
48+
community (str): SNMP community string.
49+
50+
Returns:
51+
bool: True if the outlet is on, False if it's off.
52+
"""
53+
# Validate index within allowable range
54+
if index is None or not (1 <= int(index) <= NUMBER_OF_OUTLETS):
55+
raise ExecutionError("Invalid outlet index. Ensure the index is within the range 1 to 8.")
56+
57+
# Setup SNMP connection and OID for the target outlet
58+
_snmp = SimpleSNMP(host, 'public', port=port)
59+
oid = f"{POWER_OID_BASE}.{index}"
60+
61+
print(f"Debug: Attempting SNMP GET on host {host}, OID {oid}")
62+
63+
try:
64+
# Retrieve the current power state for the specified outlet
65+
value = _snmp.get(oid)
66+
print(f"Debug: SNMP GET returned value {value} for OID {oid}")
67+
68+
# Verify and interpret the SNMP response
69+
if str(value).strip() == "1":
70+
return True # Outlet is on
71+
elif str(value).strip() == "0":
72+
return False # Outlet is off
73+
else:
74+
raise ExecutionError(f"Unexpected SNMP value '{value}' for outlet {index}")
75+
except Exception as e:
76+
print(f"Debug: SNMP GET failed for OID {oid} with exception {e}")
77+
raise ExecutionError(f"Failed to get power state for outlet {index}: {e}")

tests/test_powerdriver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ def test_import_backends(self):
282282
import labgrid.driver.power.digitalloggers_restapi
283283
import labgrid.driver.power.eth008
284284
import labgrid.driver.power.gude
285+
import labgrid.driver.power.gude8210
285286
import labgrid.driver.power.gude24
286287
import labgrid.driver.power.netio
287288
import labgrid.driver.power.netio_kshell

0 commit comments

Comments
 (0)