blob: e4bcf54320b3b559872460b448a6a43520fa427e [file] [log] [blame]
Matt Hart76fb2542014-06-01 14:24:56 +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
21import logging
Matt Hart132d43c2015-02-25 18:19:53 +000022from lavapdu.drivers.apcbase import APCBase
Matt Hart76fb2542014-06-01 14:24:56 +010023
24
Matt Hart2af71142014-07-22 10:40:41 +010025class APC8959(APCBase):
Matt Hart76fb2542014-06-01 14:24:56 +010026 pdu_commands = {"off": "olOff", "on": "olOn"}
27
Matt Hart132d43c2015-02-25 18:19:53 +000028 @classmethod
29 def accepts(cls, drivername):
30 if drivername == "apc8959":
31 return True
32 return False
33
Matt Hart76fb2542014-06-01 14:24:56 +010034 def _pdu_logout(self):
35 logging.debug("logging out")
36 self.connection.send("\r")
37 self.connection.send("exit")
38 self.connection.send("\r")
39 logging.debug("done")
40
41 def _pdu_get_to_prompt(self):
42 self.connection.send("\r")
43 self.connection.expect('apc>')
44
45 def _port_interaction(self, command, port_number):
Matt Hartfe042212015-07-09 14:13:29 +010046 logging.debug("Attempting %s on port %i", command, port_number)
Matt Hart76fb2542014-06-01 14:24:56 +010047 self._pdu_get_to_prompt()
Matt Hartfe042212015-07-09 14:13:29 +010048 self.connection.sendline(self.pdu_commands[command] +
49 (" %i" % port_number))
Matt Hart76fb2542014-06-01 14:24:56 +010050 self.connection.expect("E000: Success")
Matt Hart132d43c2015-02-25 18:19:53 +000051 self._pdu_get_to_prompt()
Matt Hartfe042212015-07-09 14:13:29 +010052 logging.debug("done")