Debian Codegraph @

ansible_collections/community/routeros/plugins/terminal/routeros.py

raw
1 # Copyright (c) 2016 Red Hat Inc.
2 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
3 # SPDX-License-Identifier: GPL-3.0-or-later
4
5 from __future__ import (absolute_import, division, print_function)
6 __metaclass__ = type
7
8 import re
9
10 from ansible.errors import AnsibleConnectionFailure
11 from ansible.plugins.terminal import TerminalBase
12 from ansible.utils.display import Display
13
14 display = Display()
15
16
17 class TerminalModule(TerminalBase):
18
19 ansi_re = [
20 # check ECMA-48 Section 5.4 (Control Sequences)
21 re.compile(br'(\x1b\[\?1h\x1b=)'),
22 re.compile(br'((?:\x9b|\x1b\x5b)[\x30-\x3f]*[\x20-\x2f]*[\x40-\x7e])'),
23 re.compile(br'\x08.')
24 ]
25
26 terminal_initial_prompt = [
27 br'\x1bZ',
28 ]
29
30 terminal_initial_answer = b'\x1b/Z'
31
32 terminal_stdout_re = [
33 re.compile(br"\x1b<"),
34 re.compile(
35 br"((\[[\w\-\.]+\@)|(\r\<(([\w\-\.]*\@)|)))"
36 br"[\w\s\-\.\/]+\] ?(<SAFE)?> ?$"),
37 re.compile(br"Please press \"Enter\" to continue!"),
38 re.compile(br"Do you want to see the software license\? \[Y\/n\]: ?"),
39 ]
40
41 terminal_stderr_re = [
42 re.compile(br"\nbad command name"),
43 re.compile(br"\nno such item"),
44 re.compile(br"\ninvalid value for"),
45 ]
46
47 def on_open_shell(self):
48 prompt = self._get_prompt()
49 try:
50 if prompt.strip().endswith(b':'):
51 self._exec_cli_command(b' ')
52 if prompt.strip().endswith(b'!'):
53 self._exec_cli_command(b'\n')
54 except AnsibleConnectionFailure:
55 raise AnsibleConnectionFailure('unable to bypass license prompt')