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 | |
Matt Hart | 2af7114 | 2014-07-22 10:40:41 +0100 | [diff] [blame] | 25 | |
| 26 | class APC7952(APCBase): |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 27 | |
Matt Hart | 132d43c | 2015-02-25 18:19:53 +0000 | [diff] [blame] | 28 | @classmethod |
| 29 | def accepts(cls, drivername): |
| 30 | if drivername == "apc7952": |
| 31 | return True |
| 32 | return False |
| 33 | |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 34 | def _pdu_logout(self): |
| 35 | self._back_to_main() |
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("4\r") |
| 38 | |
| 39 | def _back_to_main(self): |
Matt Hart | d4a0998 | 2015-07-17 16:13:11 +0100 | [diff] [blame] | 40 | log.debug("Returning to main menu") |
Matt Hart | 2af7114 | 2014-07-22 10:40:41 +0100 | [diff] [blame] | 41 | self.connection.send("\r") |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 42 | self.connection.expect('>') |
Matt Hart | fe04221 | 2015-07-09 14:13:29 +0100 | [diff] [blame] | 43 | for _ in range(1, 20): |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 44 | self.connection.send("\x1B") |
| 45 | self.connection.send("\r") |
| 46 | res = self.connection.expect(["4- Logout", "> "]) |
| 47 | if res == 0: |
Matt Hart | d4a0998 | 2015-07-17 16:13:11 +0100 | [diff] [blame] | 48 | log.debug("Back at main menu") |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 49 | break |
| 50 | |
| 51 | def _enter_outlet(self, outlet, enter_needed=True): |
| 52 | outlet = "%s" % outlet |
Matt Hart | d4a0998 | 2015-07-17 16:13:11 +0100 | [diff] [blame] | 53 | log.debug("Attempting to enter outlet %s", outlet) |
Matt Hart | fe04221 | 2015-07-09 14:13:29 +0100 | [diff] [blame] | 54 | if enter_needed: |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 55 | self.connection.expect("Press <ENTER> to continue...") |
Matt Hart | d4a0998 | 2015-07-17 16:13:11 +0100 | [diff] [blame] | 56 | log.debug("Sending enter") |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 57 | self.connection.send("\r") |
| 58 | self.connection.expect("> ") |
Matt Hart | d4a0998 | 2015-07-17 16:13:11 +0100 | [diff] [blame] | 59 | log.debug("Sending outlet number") |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 60 | self.connection.send(outlet) |
| 61 | self.connection.send("\r") |
Matt Hart | d4a0998 | 2015-07-17 16:13:11 +0100 | [diff] [blame] | 62 | log.debug("Finished entering outlet") |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 63 | |
| 64 | def _port_interaction(self, command, port_number): |
Matt Hart | d4a0998 | 2015-07-17 16:13:11 +0100 | [diff] [blame] | 65 | log.debug("Attempting command: %s port: %i", |
| 66 | command, port_number) |
Matt Hart | fe04221 | 2015-07-09 14:13:29 +0100 | [diff] [blame] | 67 | # make sure in main menu here |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 68 | self._back_to_main() |
| 69 | self.connection.send("\r") |
| 70 | self.connection.expect("1- Device Manager") |
| 71 | self.connection.expect("> ") |
Matt Hart | d4a0998 | 2015-07-17 16:13:11 +0100 | [diff] [blame] | 72 | log.debug("Entering Device Manager") |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 73 | self.connection.send("1\r") |
| 74 | self.connection.expect("------- Device Manager") |
| 75 | self.connection.send("2\r") |
Matt Hart | fe04221 | 2015-07-09 14:13:29 +0100 | [diff] [blame] | 76 | self.connection.expect("1- Outlet Control/Configuration") |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 77 | self.connection.expect("> ") |
| 78 | self.connection.send("1\r") |
| 79 | self._enter_outlet(port_number, False) |
| 80 | self.connection.expect("> ") |
| 81 | self.connection.send("1\r") |
| 82 | res = self.connection.expect(["> ", "Press <ENTER> to continue..."]) |
| 83 | if res == 1: |
Matt Hart | d4a0998 | 2015-07-17 16:13:11 +0100 | [diff] [blame] | 84 | log.debug("Stupid paging thingmy detected, pressing enter") |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 85 | self.connection.send("\r") |
| 86 | self.connection.send("\r") |
| 87 | if command == "on": |
| 88 | self.connection.send("1\r") |
| 89 | self.connection.expect("Immediate On") |
| 90 | self._do_it() |
| 91 | elif command == "off": |
| 92 | self.connection.send("2\r") |
| 93 | self.connection.expect("Immediate Off") |
| 94 | self._do_it() |
| 95 | else: |
Matt Hart | d4a0998 | 2015-07-17 16:13:11 +0100 | [diff] [blame] | 96 | log.debug("Unknown command!") |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 97 | |
| 98 | def _do_it(self): |
Matt Hart | fe04221 | 2015-07-09 14:13:29 +0100 | [diff] [blame] | 99 | self.connection.expect("Enter 'YES' to continue or " |
| 100 | "<ENTER> to cancel :") |
Matt Hart | 76fb254 | 2014-06-01 14:24:56 +0100 | [diff] [blame] | 101 | self.connection.send("YES\r") |
| 102 | self.connection.expect("Press <ENTER> to continue...") |
Matt Hart | fe04221 | 2015-07-09 14:13:29 +0100 | [diff] [blame] | 103 | self.connection.send("\r") |