matthew.hart@linaro.org | 5e4fce9 | 2013-08-22 11:29:21 +0100 | [diff] [blame] | 1 | #! /usr/bin/python |
| 2 | |
| 3 | # Copyright 2013 Linaro Limited |
| 4 | # Author Matt Hart <matthew.hart@linaro.org> |
| 5 | # |
| 6 | # This program is free software; you can redistribute it and/or modify |
| 7 | # it under the terms of the GNU General Public License as published by |
| 8 | # the Free Software Foundation; either version 2 of the License, or |
| 9 | # (at your option) any later version. |
| 10 | # |
| 11 | # This program is distributed in the hope that it will be useful, |
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | # GNU General Public License for more details. |
| 15 | # |
| 16 | # You should have received a copy of the GNU General Public License |
| 17 | # along with this program; if not, write to the Free Software |
| 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
| 19 | # MA 02110-1301, USA. |
| 20 | |
Matt Hart | 2af7114 | 2014-07-22 10:40:41 +0100 | [diff] [blame^] | 21 | import time |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 22 | import logging |
Neil Williams | 16579dc | 2014-02-13 11:20:04 +0000 | [diff] [blame] | 23 | |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 24 | class PDUDriver(object): |
matthew.hart@linaro.org | 5e4fce9 | 2013-08-22 11:29:21 +0100 | [diff] [blame] | 25 | connection = None |
Matt Hart | 2af7114 | 2014-07-22 10:40:41 +0100 | [diff] [blame^] | 26 | hostname = "" |
matthew.hart@linaro.org | 5e4fce9 | 2013-08-22 11:29:21 +0100 | [diff] [blame] | 27 | |
Matt Hart | 2af7114 | 2014-07-22 10:40:41 +0100 | [diff] [blame^] | 28 | def __init__(self, pdu_hostname): |
| 29 | self.hostname = pdu_hostname |
| 30 | #super(PDUDriver,self).__init__(pdu_hostname) |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 31 | |
Matt Hart | 2af7114 | 2014-07-22 10:40:41 +0100 | [diff] [blame^] | 32 | def handle(self, request, port_number, delay=0): |
| 33 | logging.debug("Driving PDU: %s PORT: %s REQUEST: %s (delay %s)" %(self.hostname,port_number,request,delay)) |
| 34 | if request == "reboot": |
| 35 | self.port_off(port_number) |
| 36 | time.sleep(delay) |
| 37 | self.port_on(port_number) |
| 38 | elif request == "on": |
| 39 | self.port_on(port_number) |
| 40 | elif request == "off": |
| 41 | self.port_off(port_number) |
| 42 | else: |
| 43 | logging.debug("Unknown request to handle - oops") |
| 44 | raise |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 45 | |
Matt Hart | 2af7114 | 2014-07-22 10:40:41 +0100 | [diff] [blame^] | 46 | #def _port_interaction(self, command, port_number): |
| 47 | # super(PDUDriver, self).port_interaction(command,port_number) |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 48 | |
| 49 | def port_on(self, port_number): |
Matt Hart | 2af7114 | 2014-07-22 10:40:41 +0100 | [diff] [blame^] | 50 | self.port_interaction("on", port_number) |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 51 | |
| 52 | def port_off(self, port_number): |
Matt Hart | 2af7114 | 2014-07-22 10:40:41 +0100 | [diff] [blame^] | 53 | self.port_interaction("off", port_number) |