]>
Commit | Line | Data |
---|---|---|
b5159817 DE |
1 | #!/usr/bin/python3 |
2 | # | |
250b1eec SG |
3 | # pyconsole: Example program showing use of console functions |
4 | # in the lxc python binding | |
5 | # | |
6 | # (C) Copyright Oracle. 2013 | |
7 | # | |
8 | # Authors: | |
9 | # Dwight Engen <dwight.engen@oracle.com> | |
10 | # | |
11 | # This library is free software; you can redistribute it and/or | |
12 | # modify it under the terms of the GNU Lesser General Public | |
13 | # License as published by the Free Software Foundation; either | |
14 | # version 2.1 of the License, or (at your option) any later version. | |
15 | # | |
16 | # This library is distributed in the hope that it will be useful, | |
17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 | # Lesser General Public License for more details. | |
20 | # | |
21 | # You should have received a copy of the GNU Lesser General Public | |
22 | # License along with this library; if not, write to the Free Software | |
23 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
b5159817 DE |
24 | # |
25 | ||
26 | import warnings | |
27 | warnings.filterwarnings("ignore", "The python-lxc API isn't yet stable") | |
28 | ||
29 | import lxc | |
30 | import sys | |
31 | import time | |
32 | ||
33 | if __name__ == '__main__': | |
34 | ttynum = -1 | |
35 | escape = 1 | |
36 | if len(sys.argv) < 2: | |
37 | sys.exit("Usage: %s container-name [ttynum [escape]]" % sys.argv[0]) | |
38 | if len(sys.argv) > 2: | |
39 | ttynum = int(sys.argv[2]) | |
40 | if len(sys.argv) > 3: | |
41 | escape = ord(sys.argv[3]) - ord('a') + 1 | |
42 | ||
43 | ct = lxc.Container(sys.argv[1]) | |
44 | ||
39ffde30 SG |
45 | print("Container:%s tty:%d Ctrl-%c q to quit" % |
46 | (ct.name, ttynum, ord('a') + escape-1)) | |
b5159817 DE |
47 | time.sleep(1) |
48 | if not ct.defined: | |
49 | sys.exit("Container %s not defined" % ct.name) | |
50 | if not ct.running: | |
51 | sys.exit("Container %s not running" % ct.name) | |
52 | ||
53 | ct.console(ttynum, 0, 1, 2, escape) | |
54 | print("Console done") |