Skip to content

Commit

Permalink
labgrid/driver/power: add poe-mib backend
Browse files Browse the repository at this point in the history
The PoE MiB backend uses SNMP enable and disable PoE on a switch port.
Compatibility was tested on a Cisco CBS350.

Signed-off-by: Rouven Czerwinski <[email protected]>
  • Loading branch information
Emantor committed Jan 10, 2024
1 parent 1c3aac1 commit e7d83ea
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')
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')
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 e7d83ea

Please sign in to comment.