Skip to content

Commit 35ac03b

Browse files
committed
driver/power: Add sentry_sequential backend for single-bank models
Add a new power driver for Sentry PDUs that use sequential OID mapping. This supports single-bank models like CW-16V1 which number ports sequentially (1.1.1 through 1.1.16) rather than using the multi-bank scheme (6 banks of 8 outlets) used by models like CW-24VDD. Documentation now describes both backends and explains when to use each one. Signed-off-by: Matt Porter <[email protected]>
1 parent 2f0bdf1 commit 35ac03b

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

doc/configuration.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,15 @@ Currently available are:
222222
for details.
223223

224224
``sentry``
225-
Controls *Sentry PDUs* via SNMP using Sentry3-MIB.
226-
It was tested on *CW-24VDD* and *4805-XLS-16*.
225+
Controls *Sentry PDUs* via SNMP using Sentry3-MIB with multi-bank OID mapping.
226+
Supports up to 48 outlets organized as 6 banks of 8 outlets each.
227+
Tested on *CW-24VDD* and *4805-XLS-16*.
228+
For single-bank sequential models like *CW-16V1*, use ``sentry_sequential`` instead.
229+
230+
``sentry_sequential``
231+
Controls *Sentry PDUs* via SNMP using Sentry3-MIB with sequential OID mapping.
232+
Supports up to 16 outlets numbered sequentially (1.1.1 through 1.1.16).
233+
Suitable for single-bank models like *CW-16V1*.
227234

228235
``shelly_gen1``
229236
Controls relays of *Shelly* devices using the Gen 1 Device API.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"""
2+
Sentry PDU driver with sequential OID mapping for single-bank models.
3+
4+
This driver was tested on CW-16V1 but should work on all devices
5+
implementing Sentry3-MIB with sequential OID numbering.
6+
7+
This driver uses sequential OID mapping with 16 outlets numbered
8+
1.1.1 through 1.1.16. For multi-bank models like CW-24VDD or
9+
4805-XLS-16, use 'sentry' instead.
10+
"""
11+
12+
from ..exception import ExecutionError
13+
from ...util.helper import processwrapper
14+
15+
INDEX_TO_OID = {
16+
1: "1.1.1", 2: "1.1.2", 3: "1.1.3", 4: "1.1.4",
17+
5: "1.1.5", 6: "1.1.6", 7: "1.1.7", 8: "1.1.8",
18+
9: "1.1.9", 10: "1.1.10", 11: "1.1.11", 12: "1.1.12",
19+
13: "1.1.13", 14: "1.1.14", 15: "1.1.15", 16: "1.1.16",
20+
}
21+
22+
BASE_STATUS_OID = ".1.3.6.1.4.1.1718.3.2.3.1.10"
23+
BASE_CTRL_OID = ".1.3.6.1.4.1.1718.3.2.3.1.11"
24+
25+
def _snmp_get(host, oid):
26+
out = processwrapper.check_output(
27+
f"snmpget -v1 -c private -O qn {host} {oid}".split()
28+
).decode('ascii')
29+
out_oid, value = out.strip().split(' ', 1)
30+
assert oid == out_oid
31+
if value == "3" or value == "5":
32+
return True
33+
if value == "4":
34+
return False
35+
36+
def _snmp_set(host, oid, value):
37+
try:
38+
processwrapper.check_output(
39+
f"snmpset -v1 -c private {host} {oid} {value}".split()
40+
)
41+
except Exception as e:
42+
raise ExecutionError("failed to set SNMP value") from e
43+
44+
def power_set(host, port, index, value):
45+
assert port is None
46+
47+
index = int(index)
48+
value = 1 if value else 2
49+
assert 1 <= index <= 16
50+
51+
_snmp_set(host, f"{BASE_CTRL_OID}.{INDEX_TO_OID[index]}", f"int {value}")
52+
53+
54+
def power_get(host, port, index):
55+
assert port is None
56+
57+
index = int(index)
58+
assert 1 <= index <= 16
59+
60+
return _snmp_get(host, f"{BASE_STATUS_OID}.{INDEX_TO_OID[index]}")

tests/test_powerdriver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ def test_import_backends(self):
287287
import labgrid.driver.power.netio_kshell
288288
import labgrid.driver.power.rest
289289
import labgrid.driver.power.sentry
290+
import labgrid.driver.power.sentry_sequential
290291
import labgrid.driver.power.eg_pms2_network
291292
import labgrid.driver.power.shelly_gen1
292293
import labgrid.driver.power.ubus

0 commit comments

Comments
 (0)