Matt Hart | 76fb254 | 2014-06-01 14:24:56 +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 | |
| 21 | import logging |
Matt Hart | 132d43c | 2015-02-25 18:19:53 +0000 | [diff] [blame] | 22 | from lavapdu.drivers.apcbase import APCBase |
Matt Hart | d4a0998 | 2015-07-17 16:13:11 +0100 | [diff] [blame] | 23 | log = logging.getLogger(__name__) |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 24 | |
| 25 | |
Matt Hart | 2af7114 | 2014-07-22 10:40:41 +0100 | [diff] [blame] | 26 | class APC8959(APCBase): |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 27 | pdu_commands = {"off": "olOff", "on": "olOn"} |
| 28 | |
Matt Hart | 132d43c | 2015-02-25 18:19:53 +0000 | [diff] [blame] | 29 | @classmethod |
| 30 | def accepts(cls, drivername): |
| 31 | if drivername == "apc8959": |
| 32 | return True |
| 33 | return False |
| 34 | |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 35 | def _pdu_logout(self): |
Matt Hart | d4a0998 | 2015-07-17 16:13:11 +0100 | [diff] [blame] | 36 | log.debug("logging out") |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 37 | self.connection.send("\r") |
| 38 | self.connection.send("exit") |
| 39 | self.connection.send("\r") |
Matt Hart | d4a0998 | 2015-07-17 16:13:11 +0100 | [diff] [blame] | 40 | log.debug("done") |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 41 | |
| 42 | def _pdu_get_to_prompt(self): |
| 43 | self.connection.send("\r") |
| 44 | self.connection.expect('apc>') |
| 45 | |
| 46 | def _port_interaction(self, command, port_number): |
Matt Hart | d4a0998 | 2015-07-17 16:13:11 +0100 | [diff] [blame] | 47 | log.debug("Attempting %s on port %i", command, port_number) |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 48 | self._pdu_get_to_prompt() |
Matt Hart | fe04221 | 2015-07-09 14:13:29 +0100 | [diff] [blame] | 49 | self.connection.sendline(self.pdu_commands[command] + |
| 50 | (" %i" % port_number)) |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 51 | self.connection.expect("E000: Success") |
Matt Hart | 132d43c | 2015-02-25 18:19:53 +0000 | [diff] [blame] | 52 | self._pdu_get_to_prompt() |
Matt Hart | d4a0998 | 2015-07-17 16:13:11 +0100 | [diff] [blame] | 53 | log.debug("done") |