Change in osmo-gsm-tester[master]: powersupply: Add support for Intellinet PDU

Pau Espin Pedrol gerrit-no-reply at lists.osmocom.org
Fri Apr 12 15:02:18 UTC 2019


Pau Espin Pedrol has uploaded this change for review. ( https://gerrit.osmocom.org/13621


Change subject: powersupply: Add support for Intellinet PDU
......................................................................

powersupply: Add support for Intellinet PDU

Based on original pdutool code from Joachim Steiger.

Change-Id: Iab4f7aec1c50f47da4cd734441bb36fa09d171a3
---
M check_dependencies.py
M src/osmo_gsm_tester/powersupply.py
A src/osmo_gsm_tester/powersupply_intellinet.py
3 files changed, 103 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/21/13621/1

diff --git a/check_dependencies.py b/check_dependencies.py
index 83df7a9..28bfdf7 100755
--- a/check_dependencies.py
+++ b/check_dependencies.py
@@ -26,5 +26,7 @@
 import sqlite3
 import sispm
 import smpplib
+import urllib.request
+import xml.etree.ElementTree
 
 print('dependencies ok')
diff --git a/src/osmo_gsm_tester/powersupply.py b/src/osmo_gsm_tester/powersupply.py
index 86fc010..1cf7106 100644
--- a/src/osmo_gsm_tester/powersupply.py
+++ b/src/osmo_gsm_tester/powersupply.py
@@ -1,6 +1,6 @@
 # osmo_gsm_tester: class defining a Power Supply object
 #
-# Copyright (C) 2018 by sysmocom - s.f.m.c. GmbH
+# Copyright (C) 2018-2019 by sysmocom - s.f.m.c. GmbH
 #
 # Author: Pau Espin Pedrol <pespin at sysmocom.de>
 #
@@ -51,10 +51,11 @@
         self.power_set(True)
 
 
-from . import powersupply_sispm
+from . import powersupply_sispm, powersupply_intellinet
 
 KNOWN_PWSUPPLY_TYPES = {
         'sispm' : powersupply_sispm.PowerSupplySispm,
+        'intellinet' : powersupply_intellinet.PowerSupplyIntellinet,
 }
 
 def register_type(name, clazz):
diff --git a/src/osmo_gsm_tester/powersupply_intellinet.py b/src/osmo_gsm_tester/powersupply_intellinet.py
new file mode 100644
index 0000000..c2bf2c8
--- /dev/null
+++ b/src/osmo_gsm_tester/powersupply_intellinet.py
@@ -0,0 +1,98 @@
+# osmo_gsm_tester: class defining a Power Supply object
+#
+# Copyright (C) 2019 by sysmocom - s.f.m.c. GmbH
+#
+# Author: Pau Espin Pedrol <pespin at sysmocom.de>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import urllib.request
+import xml.etree.ElementTree as ET
+
+from . import log
+from .powersupply import PowerSupply
+
+class PowerSupplyIntellinet(PowerSupply):
+    """PowerSupply implementation to controll Intellinet devices."""
+
+    # HTTP request timeout, in seconds
+    PDU_TIMEOUT = 5
+
+    PDU_CMD_ON = 0
+    PDU_CMD_OFF = 1
+
+    def _url_prefix(self):
+        return 'http://' + self.device_ip
+
+    def _url_status(self):
+        return self._url_prefix() + '/status.xml'
+
+    def _url_set_port_status(self, pdu_cmd):
+        return self._url_prefix() + "/control_outlet.htm?" + "outlet" + str(self.port - 1) + "=1" + "&op=" + str(pdu_cmd) + "&submit=Anwenden"
+
+    def _port_stat_name(self):
+        # Names start with idx 0, while in ogt we count sockets starting from 1.
+        return 'outletStat' + str(self.port - 1)
+
+    def _fetch_status(self):
+        data = urllib.request.urlopen(self._url_status(), timeout = self.PDU_TIMEOUT).read()
+        if not data:
+            raise log.Error('empty status xml')
+        return data
+
+    def _get_port_status(self):
+        data = self._fetch_status()
+        root = ET.fromstring(data)
+        for child in root:
+            if child.tag == self._port_stat_name():
+                return child.text
+        raise log.Error('no state for %s' % self._port_stat_name())
+
+    def _set_port_status(self, pdu_cmd):
+        urllib.request.urlopen(self._url_set_port_status(pdu_cmd),timeout = self.PDU_TIMEOUT).read()
+
+
+########################
+# PUBLIC - INTERNAL API
+########################
+    def __init__(self, conf):
+        super().__init__(conf, 'intellinet')
+        mydevid = conf.get('device')
+        if mydevid is None:
+            raise log.Error('No "device" attribute provided in supply conf!')
+        self.set_name('intellinet-'+mydevid)
+        myport = conf.get('port')
+        if myport is None:
+            raise log.Error('No "port" attribute provided in power_supply conf!')
+        if not int(myport):
+            raise log.Error('Wrong non numeric "port" attribute provided in power_supply conf!')
+        self.set_name('intellinet-'+mydevid+'-'+myport)
+        self.device_ip = mydevid
+        self.port = int(myport)
+
+    def is_powered(self):
+        """Get whether the device is powered on or off."""
+        return self._get_port_status() == 'on'
+
+    def power_set(self, onoff):
+        """Turn on (onoff=True) or off (onoff=False) the device."""
+        if onoff:
+            self.dbg('switchon')
+            self._set_port_status(self.PDU_CMD_ON)
+        else:
+            self.dbg('switchoff')
+            self._set_port_status(self.PDU_CMD_OFF)
+
+
+# vim: expandtab tabstop=4 shiftwidth=4

-- 
To view, visit https://gerrit.osmocom.org/13621
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iab4f7aec1c50f47da4cd734441bb36fa09d171a3
Gerrit-Change-Number: 13621
Gerrit-PatchSet: 1
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190412/50205d40/attachment.html>


More information about the gerrit-log mailing list