Skip to content
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
7 changes: 7 additions & 0 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@ Currently available are:
<https://github.com/labgrid-project/labgrid/blob/master/labgrid/driver/power/rest.py>`__
for details.

``rpm1521``
Controls *Minuteman RPM1521* series networked power switches (2, 4 and 8 port
variants) via an HTTP CGI interface.
See the `docstring in the module
<https://github.com/labgrid-project/labgrid/blob/master/labgrid/driver/power/rpm1521.py>`__
for details.

``sentry``
Controls *Sentry PDUs* via SNMP using Sentry3-MIB.
It was tested on *CW-24VDD* and *4805-XLS-16*.
Expand Down
58 changes: 58 additions & 0 deletions labgrid/driver/power/rpm1521.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""Power backend for the Minuteman RPM1521 networked power controller.

The RPM1521 is controlled via an HTTP CGI endpoint using HTTP basic auth::

curl --user user:pwd \\
"http://192.168.1.100/nagios_powerctrl.csp?slave_id=1&port=<PORT>&ctrl_kind=<KIND>"

where ``ctrl_kind=1`` turns the outlet on and ``ctrl_kind=2`` turns it off.

The outlet state is read back from a separate status CGI::

curl --user user:pwd "http://192.168.1.100/nagios_power_status.csp"

which returns a list whose second to last element holds the on/off state of each
outlet (0 = off, 1 = on).

NetworkPowerPort:
model: rpm1521
host: 'http://admin:secret@192.168.1.10'
index: 1
"""

import json

import requests

SLAVE_ID = 1
CTRL_KIND_ON = 1
CTRL_KIND_OFF = 2


def power_set(host, port, index, value):
index = int(index)
ctrl_kind = CTRL_KIND_ON if value else CTRL_KIND_OFF
params = {
"slave_id": SLAVE_ID,
"port": index,
"ctrl_kind": ctrl_kind,
}
r = requests.get(f"{host}/nagios_powerctrl.csp", params=params)
r.raise_for_status()


def power_get(host, port, index):
index = int(index)
params = {
"slave_id": SLAVE_ID,
}
r = requests.get(f"{host}/nagios_power_status.csp", params=params)
r.raise_for_status()

# The status CGI returns a list literal, e.g.
# ['RPM1521E','0.0','NULL','1','1','109.9',['1','0'],['0','1'],['0.0','0.0']]
# It contains several bracketed sub-lists; the second to last one holds the
# on/off status of each outlet.
data = json.loads(r.text.replace("'", '"'))
socket_states = data[-2]
return int(socket_states[index - 1]) == 1
Comment on lines +52 to +58

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like JSON... Is there a reason not to use json.loads instead of regex?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the driver to switch from regex to json.loads. Thanks for the review Jan!

1 change: 1 addition & 0 deletions tests/test_powerdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ def test_import_backends(self):
import labgrid.driver.power.pe6216
import labgrid.driver.power.poe_netgear_plus
import labgrid.driver.power.rest
import labgrid.driver.power.rpm1521
import labgrid.driver.power.sentry
import labgrid.driver.power.eg_pms2_network
import labgrid.driver.power.shelly_gen1
Expand Down
Loading