Skip to content

Commit

Permalink
Merge pull request #1316 from Emantor/topic/power-backend-poe-mib
Browse files Browse the repository at this point in the history
labgrid/driver/power: add poe-mib backend
  • Loading branch information
Bastian-Krause committed Jan 11, 2024
2 parents 71c7e23 + 9aa2684 commit 3ab7ab6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ Currently available are:
Controls TP-Link power strips via `python-kasa
<https://github.com/python-kasa/python-kasa>`_.

``poe_mib``
Controls PoE switches using the PoE SNMP administration MiBs.

Used by:
- `NetworkPowerDriver`_

Expand Down
27 changes: 27 additions & 0 deletions labgrid/driver/power/poe_mib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
""" tested with Cisco CBS350, should be compatible with switches implementing the PoE administration MiB"""

from ..exception import ExecutionError
from ...util.snmp import SimpleSNMP

OID = "1.3.6.1.2.1.105.1.1.1.3.1"

def power_set(host, port, index, value):
_snmp = SimpleSNMP(host, 'private', port=port)
outlet_control_oid = "{}.{}".format(OID, index)

oid_value = "1" if value else "2"

_snmp.set(outlet_control_oid, oid_value)

def power_get(host, port, index):
_snmp = SimpleSNMP(host, 'private', port=port)
output_status_oid = "{}.{}".format(OID, index)

value = _snmp.get(output_status_oid)

if value == 1: # On
return True
if value == 2: # Off
return False

raise ExecutionError("failed to get SNMP value")
4 changes: 4 additions & 0 deletions tests/test_powerdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,7 @@ def test_import_backend_tplink(self):
def test_import_backend_siglent(self):
pytest.importorskip("vxi11")
import labgrid.driver.power.siglent

def test_import_backend_poe_mib(self):
pytest.importorskip("pysnmp")
import labgrid.driver.power.poe_mib

0 comments on commit 3ab7ab6

Please sign in to comment.