blob: 447bac168004ce6cef54a28c4e49615e2fd5108b [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
22from driver import PDUDriver
23
24class apc7952(PDUDriver):
25
26 def _pdu_logout(self):
27 self._back_to_main()
28 logging.debug("Logging out")
29 self.connection.send("4\r")
30
31 def _back_to_main(self):
32 logging.debug("Returning to main menu")
33 self.connection.expect('>')
34 for i in range(1, 20):
35 self.connection.send("\x1B")
36 self.connection.send("\r")
37 res = self.connection.expect(["4- Logout", "> "])
38 if res == 0:
39 logging.debug("Back at main menu")
40 break
41
42 def _enter_outlet(self, outlet, enter_needed=True):
43 outlet = "%s" % outlet
44 logging.debug("Attempting to enter outlet %s", outlet)
45 if (enter_needed):
46 self.connection.expect("Press <ENTER> to continue...")
47 logging.debug("Sending enter")
48 self.connection.send("\r")
49 self.connection.expect("> ")
50 logging.debug("Sending outlet number")
51 self.connection.send(outlet)
52 self.connection.send("\r")
53 logging.debug("Finished entering outlet")
54
55 def _port_interaction(self, command, port_number):
56 print("Attempting command: %s port: %i" % (command, port_number))
57 ### make sure in main menu here
58 self._back_to_main()
59 self.connection.send("\r")
60 self.connection.expect("1- Device Manager")
61 self.connection.expect("> ")
62 logging.debug("Entering Device Manager")
63 self.connection.send("1\r")
64 self.connection.expect("------- Device Manager")
65 self.connection.send("2\r")
66 res = self.connection.expect("1- Outlet Control/Configuration")
67 self.connection.expect("> ")
68 self.connection.send("1\r")
69 self._enter_outlet(port_number, False)
70 self.connection.expect("> ")
71 self.connection.send("1\r")
72 res = self.connection.expect(["> ", "Press <ENTER> to continue..."])
73 if res == 1:
74 logging.debug("Stupid paging thingmy detected, pressing enter")
75 self.connection.send("\r")
76 self.connection.send("\r")
77 if command == "on":
78 self.connection.send("1\r")
79 self.connection.expect("Immediate On")
80 self._do_it()
81 elif command == "off":
82 self.connection.send("2\r")
83 self.connection.expect("Immediate Off")
84 self._do_it()
85 else:
86 logging.debug("Unknown command!")
87
88 def _do_it(self):
89 self.connection.expect("Enter 'YES' to continue or <ENTER> to cancel :")
90 self.connection.send("YES\r")
91 self.connection.expect("Press <ENTER> to continue...")
92 self.connection.send("\r")
93
94 class Meta():
95 handled_firmware = ["v3.7.3"]