Skip to content

Commit

Permalink
Merge pull request labgrid-project#595 from avoine/master
Browse files Browse the repository at this point in the history
driver/power: add support for Sentry PDU
  • Loading branch information
jluebbe authored May 6, 2020
2 parents 708c758 + 06184ff commit ada461a
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
99 changes: 99 additions & 0 deletions labgrid/driver/power/sentry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
"""
This driver was tested on those models: CW-24VDD and 4805-XLS-16
but should be working on all devices implementing Sentry3-MIB
"""

from ..exception import ExecutionError
from ...util.helper import processwrapper

INDEX_TO_OID = {
1: "1.1.1",
2: "1.1.2",
3: "1.1.3",
4: "1.1.4",
5: "1.1.5",
6: "1.1.6",
7: "1.1.7",
8: "1.1.8",
9: "1.2.1",
10: "1.2.2",
11: "1.2.3",
12: "1.2.4",
13: "1.2.5",
14: "1.2.6",
15: "1.2.7",
16: "1.2.8",
17: "1.3.1",
18: "1.3.2",
19: "1.3.3",
20: "1.3.4",
21: "1.3.5",
22: "1.3.6",
23: "1.3.7",
24: "1.3.8",
25: "1.4.1",
26: "1.4.2",
27: "1.4.3",
28: "1.4.4",
29: "1.4.5",
30: "1.4.6",
31: "1.4.7",
32: "1.4.8",
33: "1.5.1",
34: "1.5.2",
35: "1.5.3",
36: "1.5.4",
37: "1.5.5",
38: "1.5.6",
39: "1.5.7",
40: "1.5.8",
41: "1.6.1",
42: "1.6.2",
43: "1.6.3",
44: "1.6.4",
45: "1.6.5",
46: "1.6.6",
47: "1.6.7",
48: "1.6.8",
}


BASE_STATUS_OID = ".1.3.6.1.4.1.1718.3.2.3.1.10"
BASE_CTRL_OID = ".1.3.6.1.4.1.1718.3.2.3.1.11"

def _snmp_get(host, oid):
out = processwrapper.check_output(
"snmpget -v1 -c private -O qn {} {}".format(host, oid).split()
).decode('ascii')
out_oid, value = out.strip().split(' ', 1)
assert oid == out_oid
if value == "3" or value == "5":
return True
if value == "4":
return False

def _snmp_set(host, oid, value):
try:
processwrapper.check_output(
"snmpset -v1 -c private {} {} {}".format(host, oid, value).split()
)
except Exception as e:
raise ExecutionError("failed to set SNMP value") from e

def power_set(host, port, index, value):
assert port is None

index = int(index)
value = 1 if value else 2
assert 1 <= index <= 48

_snmp_set(host, "{}.{}".format(BASE_CTRL_OID, INDEX_TO_OID[index]), "int {}".format(value))


def power_get(host, port, index):
assert port is None

index = int(index)
assert 1 <= index <= 48

return _snmp_get(host, "{}.{}".format(BASE_STATUS_OID, INDEX_TO_OID[index]))
1 change: 1 addition & 0 deletions tests/test_powerdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,4 @@ def test_import_backends(self):
import labgrid.driver.power.gude24
import labgrid.driver.power.netio
import labgrid.driver.power.netio_kshell
import labgrid.driver.power.sentry

0 comments on commit ada461a

Please sign in to comment.