Debian Codegraph @

ansible_collections/cisco/iosxr/plugins/terminal/iosxr.py

raw
1 #
2 # (c) 2016 Red Hat Inc.
3 #
4 # This file is part of Ansible
5 #
6 # Ansible 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 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Ansible 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 Ansible. If not, see <http://www.gnu.org/licenses/>.
18 #
19 from __future__ import absolute_import, division, print_function
20
21
22 __metaclass__ = type
23
24 import re
25
26 from ansible.errors import AnsibleConnectionFailure
27 from ansible_collections.ansible.netcommon.plugins.plugin_utils.terminal_base import TerminalBase
28
29
30 class TerminalModule(TerminalBase):
31 terminal_stdout_re = [
32 re.compile(rb"[\r\n]*[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:>|#) ?$"),
33 re.compile(rb"]]>]]>[\r\n]?"),
34 ]
35
36 terminal_stderr_re = [
37 re.compile(rb"% ?Error"),
38 re.compile(rb"% ?Bad secret"),
39 re.compile(rb"% ?This command is not authorized"),
40 re.compile(rb"invalid input", re.I),
41 re.compile(rb"(?:incomplete|ambiguous) command", re.I),
42 re.compile(rb"(?<!\()connection timed out(?!\))", re.I),
43 re.compile(rb"[^\r\n]+ not found", re.I),
44 re.compile(rb"'[^']' +returned error code: ?\d+"),
45 re.compile(rb"Failed to commit", re.I),
46 re.compile(rb"show configuration failed \[inheritance\]", re.I),
47 ]
48
49 terminal_config_prompt = re.compile(r"^.+\(config(-.*)?\)#$")
50
51 def on_open_shell(self):
52 try:
53 for cmd in (
54 b"terminal length 0",
55 b"terminal width 512",
56 b"terminal exec prompt no-timestamp",
57 ):
58 self._exec_cli_command(cmd)
59 except AnsibleConnectionFailure:
60 raise AnsibleConnectionFailure("unable to set terminal parameters")