blob: 7140948da82ecb4a154a7892a0a816f73626f39e [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 Hartd4a09982015-07-17 16:13:11 +010023log = logging.getLogger(__name__)
Matt Hart76fb2542014-06-01 14:24:56 +010024
Matt Hart2af71142014-07-22 10:40:41 +010025
26class APC7952(APCBase):
Matt Hart76fb2542014-06-01 14:24:56 +010027
Matt Hart132d43c2015-02-25 18:19:53 +000028 @classmethod
29 def accepts(cls, drivername):
30 if drivername == "apc7952":
31 return True
32 return False
33
Matt Hart76fb2542014-06-01 14:24:56 +010034 def _pdu_logout(self):
35 self._back_to_main()
Matt Hartd4a09982015-07-17 16:13:11 +010036 log.debug("Logging out")
Matt Hart76fb2542014-06-01 14:24:56 +010037 self.connection.send("4\r")
38
39 def _back_to_main(self):
Matt Hartd4a09982015-07-17 16:13:11 +010040 log.debug("Returning to main menu")
Matt Hart2af71142014-07-22 10:40:41 +010041 self.connection.send("\r")
Matt Hart76fb2542014-06-01 14:24:56 +010042 self.connection.expect('>')
Matt Hartfe042212015-07-09 14:13:29 +010043 for _ in range(1, 20):
Matt Hart76fb2542014-06-01 14:24:56 +010044 self.connection.send("\x1B")
45 self.connection.send("\r")
46 res = self.connection.expect(["4- Logout", "> "])
47 if res == 0:
Matt Hartd4a09982015-07-17 16:13:11 +010048 log.debug("Back at main menu")
Matt Hart76fb2542014-06-01 14:24:56 +010049 break
50
51 def _enter_outlet(self, outlet, enter_needed=True):
52 outlet = "%s" % outlet
Matt Hartd4a09982015-07-17 16:13:11 +010053 log.debug("Attempting to enter outlet %s", outlet)
Matt Hartfe042212015-07-09 14:13:29 +010054 if enter_needed:
Matt Hart76fb2542014-06-01 14:24:56 +010055 self.connection.expect("Press <ENTER> to continue...")
Matt Hartd4a09982015-07-17 16:13:11 +010056 log.debug("Sending enter")
Matt Hart76fb2542014-06-01 14:24:56 +010057 self.connection.send("\r")
58 self.connection.expect("> ")
Matt Hartd4a09982015-07-17 16:13:11 +010059 log.debug("Sending outlet number")
Matt Hart76fb2542014-06-01 14:24:56 +010060 self.connection.send(outlet)
61 self.connection.send("\r")
Matt Hartd4a09982015-07-17 16:13:11 +010062 log.debug("Finished entering outlet")
Matt Hart76fb2542014-06-01 14:24:56 +010063
64 def _port_interaction(self, command, port_number):
Matt Hartd4a09982015-07-17 16:13:11 +010065 log.debug("Attempting command: %s port: %i",
66 command, port_number)
Matt Hartfe042212015-07-09 14:13:29 +010067 # make sure in main menu here
Matt Hart76fb2542014-06-01 14:24:56 +010068 self._back_to_main()
69 self.connection.send("\r")
70 self.connection.expect("1- Device Manager")
71 self.connection.expect("> ")
Matt Hartd4a09982015-07-17 16:13:11 +010072 log.debug("Entering Device Manager")
Matt Hart76fb2542014-06-01 14:24:56 +010073 self.connection.send("1\r")
74 self.connection.expect("------- Device Manager")
75 self.connection.send("2\r")
Matt Hartfe042212015-07-09 14:13:29 +010076 self.connection.expect("1- Outlet Control/Configuration")
Matt Hart76fb2542014-06-01 14:24:56 +010077 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 Hartd4a09982015-07-17 16:13:11 +010084 log.debug("Stupid paging thingmy detected, pressing enter")
Matt Hart76fb2542014-06-01 14:24:56 +010085 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 Hartd4a09982015-07-17 16:13:11 +010096 log.debug("Unknown command!")
Matt Hart76fb2542014-06-01 14:24:56 +010097
98 def _do_it(self):
Matt Hartfe042212015-07-09 14:13:29 +010099 self.connection.expect("Enter 'YES' to continue or "
100 "<ENTER> to cancel :")
Matt Hart76fb2542014-06-01 14:24:56 +0100101 self.connection.send("YES\r")
102 self.connection.expect("Press <ENTER> to continue...")
Matt Hartfe042212015-07-09 14:13:29 +0100103 self.connection.send("\r")