Skip to content

driver/pe6216: add support for Aten PE6216 PDU #1324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ Currently available are:
``netio_kshell``
Controls *NETIO 4C PDUs* via a Telnet interface.

``pe6216``
Controls an Aten PE6216 PDU via a simple HTTP API.

``raritan``
Controls *Raritan PDUs* via SNMP.

Expand Down
49 changes: 49 additions & 0 deletions labgrid/driver/power/pe6216.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Tested with Aten PE6216.

HTTP API is defined by in the aten PDU PE6216 specification:
https://assets.aten.com/product/manual/Restful-API-Guide-for-PDU_2022-11-18.pdf
"""
import re
import requests

PORT = 80

MIN_OUTLET_INDEX = 1
MAX_OUTLET_INDEX = 16
headers = {'Content-Type': 'application/x-www-form-urlencoded'}

def power_set(host, port, index, value):
index = int(index)
assert MIN_OUTLET_INDEX <= index <= MAX_OUTLET_INDEX
value = 'on' if value else 'off'

requests.post(
f'http://{host}:{port}/api/outlet/relay',
headers=headers,
data={
'usr': 'administrator',
'pwd': 'password',
'index': index,
'method': value,
}
)


def power_get(host, port, index):
index = int(index)
assert MIN_OUTLET_INDEX <= index <= MAX_OUTLET_INDEX

response = requests.get(
f'http://{host}:{port}/api/outlet/relay',
headers=headers,
params={
'usr': 'administrator',
'pwd': 'password',
'index': index,
}
)

m = re.search( r'<\d+>(?P<state>(ON|OFF|PENDING))<.*', response.text)
if m is None:
raise RuntimeError('PE6216: could not match reponse')
return m.group('state') == 'ON'