blob: 73254733ab0568a0b0face4a868c2d07407e1593 [file] [log] [blame]
matthew.hart@linaro.org5e4fce92013-08-22 11:29:21 +01001#! /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 Hart2af71142014-07-22 10:40:41 +010021import time
Matt Hart76fb2542014-06-01 14:24:56 +010022import logging
Neil Williams16579dc2014-02-13 11:20:04 +000023
Matt Hart76fb2542014-06-01 14:24:56 +010024class PDUDriver(object):
matthew.hart@linaro.org5e4fce92013-08-22 11:29:21 +010025 connection = None
Matt Hart2af71142014-07-22 10:40:41 +010026 hostname = ""
matthew.hart@linaro.org5e4fce92013-08-22 11:29:21 +010027
Matt Hart2af71142014-07-22 10:40:41 +010028 def __init__(self, pdu_hostname):
29 self.hostname = pdu_hostname
30 #super(PDUDriver,self).__init__(pdu_hostname)
Matt Hart76fb2542014-06-01 14:24:56 +010031
Matt Hart2af71142014-07-22 10:40:41 +010032 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 Hart76fb2542014-06-01 14:24:56 +010045
Matt Hart2af71142014-07-22 10:40:41 +010046 #def _port_interaction(self, command, port_number):
47 # super(PDUDriver, self).port_interaction(command,port_number)
Matt Hart76fb2542014-06-01 14:24:56 +010048
49 def port_on(self, port_number):
Matt Hart2af71142014-07-22 10:40:41 +010050 self.port_interaction("on", port_number)
Matt Hart76fb2542014-06-01 14:24:56 +010051
52 def port_off(self, port_number):
Matt Hart2af71142014-07-22 10:40:41 +010053 self.port_interaction("off", port_number)