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