summaryrefslogtreecommitdiff
path: root/lib/ansible/plugins/terminal
diff options
context:
space:
mode:
authorAnsible Core Team <info@ansible.com>2020-03-09 09:40:29 +0000
committerMatt Martz <matt@sivel.net>2020-03-23 11:14:21 -0500
commit4e488d8435b3b3458de08bb2e4532bfbe6318121 (patch)
tree05eb51738d05d26c992b439214c3dd7ffd1af538 /lib/ansible/plugins/terminal
parent58e8a91f4dbb7c5b631dd855b357ebef6bc11283 (diff)
downloadansible-4e488d8435b3b3458de08bb2e4532bfbe6318121.tar.gz
Migrated to community.general
Diffstat (limited to 'lib/ansible/plugins/terminal')
-rw-r--r--lib/ansible/plugins/terminal/aireos.py59
-rw-r--r--lib/ansible/plugins/terminal/apconos.py35
-rw-r--r--lib/ansible/plugins/terminal/aruba.py68
-rw-r--r--lib/ansible/plugins/terminal/ce.py60
-rw-r--r--lib/ansible/plugins/terminal/cnos.py83
-rw-r--r--lib/ansible/plugins/terminal/edgeos.py35
-rw-r--r--lib/ansible/plugins/terminal/edgeswitch.py87
-rw-r--r--lib/ansible/plugins/terminal/enos.py83
-rw-r--r--lib/ansible/plugins/terminal/eric_eccli.py59
-rw-r--r--lib/ansible/plugins/terminal/exos.py59
-rw-r--r--lib/ansible/plugins/terminal/icx.py81
-rw-r--r--lib/ansible/plugins/terminal/ironware.py78
-rw-r--r--lib/ansible/plugins/terminal/netvisor.py39
-rw-r--r--lib/ansible/plugins/terminal/nos.py54
-rw-r--r--lib/ansible/plugins/terminal/onyx.py80
-rw-r--r--lib/ansible/plugins/terminal/routeros.py69
-rw-r--r--lib/ansible/plugins/terminal/slxos.py54
-rw-r--r--lib/ansible/plugins/terminal/sros.py43
-rw-r--r--lib/ansible/plugins/terminal/voss.py89
19 files changed, 0 insertions, 1215 deletions
diff --git a/lib/ansible/plugins/terminal/aireos.py b/lib/ansible/plugins/terminal/aireos.py
deleted file mode 100644
index 240b1dff3f..0000000000
--- a/lib/ansible/plugins/terminal/aireos.py
+++ /dev/null
@@ -1,59 +0,0 @@
-#
-# (c) 2016 Red Hat Inc.
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import json
-import re
-import time
-
-from ansible.errors import AnsibleConnectionFailure
-from ansible.plugins.terminal import TerminalBase
-
-
-class TerminalModule(TerminalBase):
-
- terminal_stdout_re = [
- re.compile(br"[\r\n]?[\w]*\(.+\)?[>#\$](?:\s*)$"),
- re.compile(br"User:")
- ]
-
- terminal_stderr_re = [
- re.compile(br"% ?Error"),
- re.compile(br"% ?Bad secret"),
- re.compile(br"invalid input", re.I),
- re.compile(br"incorrect usage", re.I),
- re.compile(br"(?:incomplete|ambiguous) command", re.I),
- re.compile(br"connection timed out", re.I),
- re.compile(br"[^\r\n]+ not found", re.I),
- re.compile(br"'[^']' +returned error code: ?\d+"),
- ]
-
- def on_open_shell(self):
- try:
- commands = ('{"command": "' + self._connection._play_context.remote_user + '", "prompt": "Password:", "answer": "' +
- self._connection._play_context.password + '"}',
- '{"command": "config paging disable"}')
- for cmd in commands:
- self._exec_cli_command(cmd)
- except AnsibleConnectionFailure:
- try:
- self._exec_cli_command(b'config paging disable')
- except AnsibleConnectionFailure:
- raise AnsibleConnectionFailure('unable to set terminal parameters')
diff --git a/lib/ansible/plugins/terminal/apconos.py b/lib/ansible/plugins/terminal/apconos.py
deleted file mode 100644
index 0cbd74f649..0000000000
--- a/lib/ansible/plugins/terminal/apconos.py
+++ /dev/null
@@ -1,35 +0,0 @@
-# (C) 2017 Red Hat Inc.
-# Copyright (C) 2019 APCON.
-#
-# GNU General Public License v3.0+
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-#
-# Contains terminal Plugin methods for apconos Config Module
-# Apcon Networking
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import json
-import re
-
-from ansible.errors import AnsibleConnectionFailure
-from ansible.module_utils._text import to_text, to_bytes
-from ansible.plugins.terminal import TerminalBase
-
-
-class TerminalModule(TerminalBase):
-
- terminal_stdout_re = [
- re.compile(br'>>\ |#\ |\$\ ')
- ]
-
- terminal_stderr_re = [
- re.compile(br"connection timed out", re.I),
- ]
diff --git a/lib/ansible/plugins/terminal/aruba.py b/lib/ansible/plugins/terminal/aruba.py
deleted file mode 100644
index 79bce7a2e1..0000000000
--- a/lib/ansible/plugins/terminal/aruba.py
+++ /dev/null
@@ -1,68 +0,0 @@
-#
-# (c) 2016 Red Hat Inc.
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import json
-import re
-
-from ansible.errors import AnsibleConnectionFailure
-from ansible.module_utils._text import to_text, to_bytes
-from ansible.plugins.terminal import TerminalBase
-
-
-class TerminalModule(TerminalBase):
-
- ansi_re = [
- # check ECMA-48 Section 5.4 (Control Sequences)
- re.compile(br'(\x1b\[\?1h\x1b=)'),
- re.compile(br'((?:\x9b|\x1b\x5b)[\x30-\x3f]*[\x20-\x2f]*[\x40-\x7e])'),
- re.compile(br'\x08.')
- ]
-
- terminal_stdout_re = [
- re.compile(br"[\r\n]?[\w]*\(.+\)\s*[\^\*]?(?:\[.+\])? ?#(?:\s*)$"),
- re.compile(br"[pP]assword:$"),
- re.compile(br"(?<=\s)[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?\s*#\s*$"),
- re.compile(br"[\r\n]?[\w\+\-\.:\/\[\]]+(?:\([^\)]+\)){0,3}(?:[>#]) ?$"),
- ]
-
- terminal_stderr_re = [
- re.compile(br"% ?Error"),
- re.compile(br"Error:", re.M),
- re.compile(br"^% \w+", re.M),
- re.compile(br"% ?Bad secret"),
- re.compile(br"invalid input", re.I),
- re.compile(br"(?:incomplete|ambiguous) command", re.I),
- re.compile(br"connection timed out", re.I),
- re.compile(br"[^\r\n]+ not found", re.I),
- re.compile(br"'[^']' +returned error code: ?\d+"),
- ]
-
- terminal_initial_prompt = b'Press any key to continue'
-
- terminal_initial_answer = b'\r'
-
- terminal_inital_prompt_newline = False
-
- def on_open_shell(self):
- try:
- self._exec_cli_command(b'no pag')
- except AnsibleConnectionFailure:
- raise AnsibleConnectionFailure('unable to set terminal parameters')
diff --git a/lib/ansible/plugins/terminal/ce.py b/lib/ansible/plugins/terminal/ce.py
deleted file mode 100644
index 67936e8fef..0000000000
--- a/lib/ansible/plugins/terminal/ce.py
+++ /dev/null
@@ -1,60 +0,0 @@
-#
-# (c) 2016 Red Hat Inc.
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import re
-
-from ansible.plugins.terminal import TerminalBase
-from ansible.errors import AnsibleConnectionFailure
-
-
-class TerminalModule(TerminalBase):
-
- terminal_stdout_re = [
- re.compile(br'[\r\n]?<.+>(?:\s*)$'),
- re.compile(br'[\r\n]?\[.+\](?:\s*)$'),
- ]
- #: terminal initial prompt
- #: The password needs to be changed. Change now? [Y/N]:
- terminal_initial_prompt = br'Change\s*now\s*\?\s*\[Y\/N\]\s*:'
-
- #: terminal initial answer
- #: do not change password when it is asked to change with initial connection.
- terminal_initial_answer = b'N'
- terminal_stderr_re = [
- re.compile(br"% ?Error: "),
- re.compile(br"^% \w+", re.M),
- re.compile(br"% ?Bad secret"),
- re.compile(br"invalid input", re.I),
- re.compile(br"(?:incomplete|ambiguous) command", re.I),
- re.compile(br"connection timed out", re.I),
- re.compile(br"[^\r\n]+ not found", re.I),
- re.compile(br"'[^']' +returned error code: ?\d+"),
- re.compile(br"syntax error"),
- re.compile(br"unknown command"),
- re.compile(br"Error\[\d+\]: ", re.I),
- re.compile(br"Error:", re.I)
- ]
-
- def on_open_shell(self):
- try:
- self._exec_cli_command('screen-length 0 temporary')
- except AnsibleConnectionFailure:
- raise AnsibleConnectionFailure('unable to set terminal parameters')
diff --git a/lib/ansible/plugins/terminal/cnos.py b/lib/ansible/plugins/terminal/cnos.py
deleted file mode 100644
index 6162b84cff..0000000000
--- a/lib/ansible/plugins/terminal/cnos.py
+++ /dev/null
@@ -1,83 +0,0 @@
-# (C) 2017 Red Hat Inc.
-# Copyright (C) 2017 Lenovo.
-#
-# GNU General Public License v3.0+
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-#
-# Contains terminal Plugin methods for CNOS Config Module
-# Lenovo Networking
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import json
-import re
-
-from ansible.errors import AnsibleConnectionFailure
-from ansible.module_utils._text import to_text, to_bytes
-from ansible.plugins.terminal import TerminalBase
-
-
-class TerminalModule(TerminalBase):
-
- terminal_stdout_re = [
- re.compile(br"[\r\n]?[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:>|#) ?$"),
- re.compile(br"\[\w+\@[\w\-\.]+(?: [^\]])\] ?[>#\$] ?$"),
- re.compile(br">[\r\n]?")
- ]
-
- terminal_stderr_re = [
- re.compile(br"% ?Error"),
- re.compile(br"% ?Bad secret"),
- re.compile(br"invalid input", re.I),
- re.compile(br"(?:incomplete|ambiguous) command", re.I),
- re.compile(br"connection timed out", re.I),
- re.compile(br"[^\r\n]+ not found"),
- re.compile(br"'[^']' +returned error code: ?\d+"),
- ]
-
- def on_open_shell(self):
- try:
- for cmd in (b'\n', b'terminal length 0\n'):
- self._exec_cli_command(cmd)
- except AnsibleConnectionFailure:
- raise AnsibleConnectionFailure('unable to set terminal parameters')
-
- def on_become(self, passwd=None):
- if self._get_prompt().endswith(b'#'):
- return
-
- cmd = {u'command': u'enable'}
- if passwd:
- # Note: python-3.5 cannot combine u"" and r"" together. Thus make
- # an r string and use to_text to ensure it's text
- # on both py2 and py3.
- cmd[u'prompt'] = to_text(r"[\r\n]?password: $",
- errors='surrogate_or_strict')
- cmd[u'answer'] = passwd
-
- try:
- self._exec_cli_command(to_bytes(json.dumps(cmd),
- errors='surrogate_or_strict'))
- except AnsibleConnectionFailure:
- msg = 'unable to elevate privilege to enable mode'
- raise AnsibleConnectionFailure(msg)
-
- def on_unbecome(self):
- prompt = self._get_prompt()
- if prompt is None:
- # if prompt is None most likely the terminal is hung up at a prompt
- return
-
- if b'(config' in prompt:
- self._exec_cli_command(b'end')
- self._exec_cli_command(b'disable')
-
- elif prompt.endswith(b'#'):
- self._exec_cli_command(b'disable')
diff --git a/lib/ansible/plugins/terminal/edgeos.py b/lib/ansible/plugins/terminal/edgeos.py
deleted file mode 100644
index 50f5901663..0000000000
--- a/lib/ansible/plugins/terminal/edgeos.py
+++ /dev/null
@@ -1,35 +0,0 @@
-# Copyright: (c) 2018, Ansible Project
-# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import os
-import re
-
-from ansible.plugins.terminal import TerminalBase
-from ansible.errors import AnsibleConnectionFailure
-
-
-class TerminalModule(TerminalBase):
-
- terminal_stdout_re = [
- re.compile(br"[\r\n]?[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:>|#) ?$"),
- re.compile(br"\@[\w\-\.]+:\S+?[>#\$] ?$")
- ]
-
- terminal_stderr_re = [
- re.compile(br"\n\s*command not found"),
- re.compile(br"\nInvalid command"),
- re.compile(br"\nCommit failed"),
- re.compile(br"\n\s*Set failed"),
- ]
-
- terminal_length = os.getenv('ANSIBLE_EDGEOS_TERMINAL_LENGTH', 10000)
-
- def on_open_shell(self):
- try:
- self._exec_cli_command('export VYATTA_PAGER=cat')
- self._exec_cli_command('stty rows %s' % self.terminal_length)
- except AnsibleConnectionFailure:
- raise AnsibleConnectionFailure('unable to set terminal parameters')
diff --git a/lib/ansible/plugins/terminal/edgeswitch.py b/lib/ansible/plugins/terminal/edgeswitch.py
deleted file mode 100644
index 27ac674d85..0000000000
--- a/lib/ansible/plugins/terminal/edgeswitch.py
+++ /dev/null
@@ -1,87 +0,0 @@
-#
-# (c) 2018 Red Hat Inc.
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import json
-import re
-
-from ansible.errors import AnsibleConnectionFailure
-from ansible.module_utils._text import to_text, to_bytes
-from ansible.plugins.terminal import TerminalBase
-
-
-class TerminalModule(TerminalBase):
-
- terminal_stdout_re = [
- re.compile(br"\(([^\(\)]+)\) [>#]$"),
- re.compile(br"\(([^\(\)]+)\) \(([^\(\)]+)\)#$")
- ]
-
- terminal_stderr_re = [
- re.compile(br"% ?Error"),
- re.compile(br"% ?Bad secret"),
- re.compile(br"invalid input", re.I),
- re.compile(br"(?:incomplete|ambiguous) command", re.I),
- re.compile(br"connection timed out", re.I),
- re.compile(br"[^\r\n]+ not found"),
- re.compile(br"'[^']' +returned error code: ?\d+"),
- re.compile(br"An invalid")
- ]
-
- def on_open_shell(self):
- return
-
- def on_become(self, passwd=None):
- prompt = self._get_prompt()
- if prompt and prompt.endswith(b'#'):
- return
-
- cmd = {u'command': u'enable'}
- if passwd:
- cmd[u'prompt'] = to_text(r"[\r\n]?[Pp]assword: ?$", errors='surrogate_or_strict')
- cmd[u'answer'] = passwd
- try:
- self._exec_cli_command(to_bytes(json.dumps(cmd), errors='surrogate_or_strict'))
- prompt = self._get_prompt()
- if prompt is None or not prompt.endswith(b'#'):
- raise AnsibleConnectionFailure('failed to elevate privilege to enable mode still at prompt [%s]' % prompt)
-
- cmd = {u'command': u'terminal length 0'}
- self._exec_cli_command(to_bytes(json.dumps(cmd), errors='surrogate_or_strict'))
- prompt = self._get_prompt()
- if prompt is None or not prompt.endswith(b'#'):
- raise AnsibleConnectionFailure('failed to setup terminal in enable mode')
-
- except AnsibleConnectionFailure as e:
- prompt = self._get_prompt()
- raise AnsibleConnectionFailure('unable to elevate privilege to enable mode, at prompt [%s] with error: %s' % (prompt, e.message))
-
- def on_unbecome(self):
- prompt = self._get_prompt()
- if prompt is None:
- # if prompt is None most likely the terminal is hung up at a prompt
- return
-
- if b'(Config' in prompt:
- self._exec_cli_command(b'end')
- self._exec_cli_command(b'exit')
-
- elif prompt.endswith(b'#'):
- self._exec_cli_command(b'exit')
diff --git a/lib/ansible/plugins/terminal/enos.py b/lib/ansible/plugins/terminal/enos.py
deleted file mode 100644
index e1b82d2562..0000000000
--- a/lib/ansible/plugins/terminal/enos.py
+++ /dev/null
@@ -1,83 +0,0 @@
-# (C) 2017 Red Hat Inc.
-# Copyright (C) 2017 Lenovo.
-#
-# GNU General Public License v3.0+
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-#
-# Contains terminal Plugin methods for ENOS Config Module
-# Lenovo Networking
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import json
-import re
-
-from ansible.errors import AnsibleConnectionFailure
-from ansible.module_utils._text import to_text, to_bytes
-from ansible.plugins.terminal import TerminalBase
-
-
-class TerminalModule(TerminalBase):
-
- terminal_stdout_re = [
- re.compile(br"[\r\n]?[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:>|#) ?$"),
- re.compile(br"\[\w+\@[\w\-\.]+(?: [^\]])\] ?[>#\$] ?$"),
- re.compile(br">[\r\n]?")
- ]
-
- terminal_stderr_re = [
- re.compile(br"% ?Error"),
- re.compile(br"% ?Bad secret"),
- re.compile(br"invalid input", re.I),
- re.compile(br"(?:incomplete|ambiguous) command", re.I),
- re.compile(br"connection timed out", re.I),
- re.compile(br"[^\r\n]+ not found"),
- re.compile(br"'[^']' +returned error code: ?\d+"),
- ]
-
- def on_open_shell(self):
- try:
- for cmd in (b'\n', b'terminal-length 0\n'):
- self._exec_cli_command(cmd)
- except AnsibleConnectionFailure:
- raise AnsibleConnectionFailure('unable to set terminal parameters')
-
- def on_become(self, passwd=None):
- if self._get_prompt().endswith(b'#'):
- return
-
- cmd = {u'command': u'enable'}
- if passwd:
- # Note: python-3.5 cannot combine u"" and r"" together. Thus make
- # an r string and use to_text to ensure it's text
- # on both py2 and py3.
- cmd[u'prompt'] = to_text(r"[\r\n]?password: $",
- errors='surrogate_or_strict')
- cmd[u'answer'] = passwd
-
- try:
- self._exec_cli_command(to_bytes(json.dumps(cmd),
- errors='surrogate_or_strict'))
- except AnsibleConnectionFailure:
- msg = 'unable to elevate privilege to enable mode'
- raise AnsibleConnectionFailure(msg)
-
- def on_unbecome(self):
- prompt = self._get_prompt()
- if prompt is None:
- # if prompt is None most likely the terminal is hung up at a prompt
- return
-
- if b'(config' in prompt:
- self._exec_cli_command(b'end')
- self._exec_cli_command(b'disable')
-
- elif prompt.endswith(b'#'):
- self._exec_cli_command(b'disable')
diff --git a/lib/ansible/plugins/terminal/eric_eccli.py b/lib/ansible/plugins/terminal/eric_eccli.py
deleted file mode 100644
index d162203265..0000000000
--- a/lib/ansible/plugins/terminal/eric_eccli.py
+++ /dev/null
@@ -1,59 +0,0 @@
-#
-# Copyright (c) 2019 Ericsson AB.
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-
-
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import json
-import re
-
-from ansible import constants as C
-from ansible.errors import AnsibleConnectionFailure
-from ansible.module_utils._text import to_text, to_bytes
-from ansible.plugins.terminal import TerminalBase
-from ansible.utils.display import Display
-from ansible.module_utils.six import PY3
-
-display = Display()
-
-
-class TerminalModule(TerminalBase):
-
- terminal_stdout_re = [
- re.compile(br"[\r\n]?\[.*\][a-zA-Z0-9_.-]*[>\#] ?$"),
- re.compile(br"[\r\n]?[a-zA-Z0-9_.-]*(?:\([^\)]+\))(?:[>#]) ?$"),
- re.compile(br"bash\-\d\.\d(?:[$#]) ?"),
- re.compile(br"[a-zA-Z0-9_.-]*\@[a-zA-Z0-9_.-]*\[\]\:\/flash\>")
- ]
-
- terminal_stderr_re = [
- re.compile(br"[\r\n]+syntax error: .*"),
- re.compile(br"Aborted: .*"),
- re.compile(br"[\r\n]+Error: .*"),
- re.compile(br"[\r\n]+% Error:.*"),
- re.compile(br"[\r\n]+% Invalid input.*"),
- re.compile(br"[\r\n]+% Incomplete command:.*")
- ]
-
- def on_open_shell(self):
-
- try:
- for cmd in (b'screen-length 0', b'screen-width 512'):
- self._exec_cli_command(cmd)
- except AnsibleConnectionFailure:
- raise AnsibleConnectionFailure('unable to set terminal parameters')
diff --git a/lib/ansible/plugins/terminal/exos.py b/lib/ansible/plugins/terminal/exos.py
deleted file mode 100644
index 6836cdb8f4..0000000000
--- a/lib/ansible/plugins/terminal/exos.py
+++ /dev/null
@@ -1,59 +0,0 @@
-#
-# (c) 2016 Red Hat Inc.
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import re
-
-from ansible.errors import AnsibleConnectionFailure
-from ansible.plugins.terminal import TerminalBase
-
-
-class TerminalModule(TerminalBase):
-
- terminal_stdout_re = [
- re.compile(br"[\r\n](?:! )?(?:\* )?(?:\(.*\) )?(?:Slot-\d+ )?(?:VPEX )?\S+\.\d+ (?:[>#]) ?$")
- ]
-
- terminal_stderr_re = [
- re.compile(br"% ?Error"),
- re.compile(br"% ?Bad secret"),
- re.compile(br"[\r\n%] Bad passwords"),
- re.compile(br"invalid input", re.I),
- re.compile(br"(?:incomplete|ambiguous) command", re.I),
- re.compile(br"connection timed out", re.I),
- re.compile(br"[^\r\n]+ not found"),
- re.compile(br"'[^']' +returned error code: ?\d+"),
- re.compile(br"Bad mask", re.I),
- re.compile(br"% ?(\S+) ?overlaps with ?(\S+)", re.I),
- re.compile(br"[%\S] ?Error: ?[\s]+", re.I),
- re.compile(br"[%\S] ?Informational: ?[\s]+", re.I),
- re.compile(br"%% Invalid .* at '\^' marker.", re.I),
- ]
-
- def on_open_shell(self):
- try:
- self._exec_cli_command(b'disable clipaging')
- except AnsibleConnectionFailure:
- raise AnsibleConnectionFailure('unable to set terminal parameters')
-
- try:
- self._exec_cli_command(b'configure cli columns 256')
- except AnsibleConnectionFailure:
- self._connection.queue_message('warning', 'Unable to configure cli columns, command responses may be truncated')
diff --git a/lib/ansible/plugins/terminal/icx.py b/lib/ansible/plugins/terminal/icx.py
deleted file mode 100644
index e7d55549d8..0000000000
--- a/lib/ansible/plugins/terminal/icx.py
+++ /dev/null
@@ -1,81 +0,0 @@
-# Copyright: (c) 2019, Ansible Project
-# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import re
-
-from ansible.plugins.terminal import TerminalBase
-from ansible.errors import AnsibleConnectionFailure
-from ansible.module_utils._text import to_text, to_bytes
-import json
-
-
-class TerminalModule(TerminalBase):
-
- terminal_stdout_re = [
- re.compile(br"[\r\n]?[\w\+\-\.:\/\[\]]+(?:\([^\)]+\)){0,3}(?:[>#]) ?$")
- ]
-
- terminal_stderr_re = [
- re.compile(br"% ?Error"),
- re.compile(br"% ?Bad secret"),
- re.compile(br"[\r\n%] Bad passwords"),
- re.compile(br"invalid input", re.I),
- re.compile(br"(?:incomplete|ambiguous) command", re.I),
- re.compile(br"connection timed out", re.I),
- re.compile(br"[^\r\n]+ not found"),
- re.compile(br"'[^']' +returned error code: ?\d+"),
- re.compile(br"Bad mask", re.I),
- re.compile(br"% ?(\S+) ?overlaps with ?(\S+)", re.I),
- re.compile(br"[%\S] ?Error: ?[\s]+", re.I),
- re.compile(br"[%\S] ?Informational: ?[\s]+", re.I),
- re.compile(br"Command authorization failed"),
- re.compile(br"Error - *"),
- re.compile(br"Error - Incorrect username or password."),
- re.compile(br"Invalid input"),
- re.compile(br"Already a http operation is in progress"),
- re.compile(br"Flash access in progress. Please try later"),
- re.compile(br"Error: .*"),
- re.compile(br"^Error: .*", re.I),
- re.compile(br"^Ambiguous input"),
- re.compile(br"Errno")
- ]
-
- def on_open_shell(self):
- pass
-
- def __del__(self):
- try:
- self.close()
- except AnsibleConnectionFailure:
- raise AnsibleConnectionFailure('unable to set terminal parameters')
-
- def on_become(self, passwd=None):
- if self._get_prompt().endswith(b'#'):
- return
-
- cmd = {u'command': u'enable'}
- cmd[u'prompt'] = to_text(r"[\r\n](?:Local_)?[Pp]assword: ?$", errors='surrogate_or_strict')
- cmd[u'answer'] = passwd
- cmd[u'prompt_retry_check'] = True
- try:
- self._exec_cli_command(to_bytes(json.dumps(cmd), errors='surrogate_or_strict'))
- prompt = self._get_prompt()
- if prompt is None or not prompt.endswith(b'#'):
- raise AnsibleConnectionFailure('failed to elevate privilege to enable mode still at prompt [%s]' % prompt)
- except AnsibleConnectionFailure as e:
- prompt = self._get_prompt()
- raise AnsibleConnectionFailure('unable to elevate privilege to enable mode, at prompt [%s] with error: %s' % (prompt, e.message))
-
- def on_unbecome(self):
- prompt = self._get_prompt()
- if prompt is None:
- return
-
- if b'(config' in prompt:
- self._exec_cli_command(b'exit')
-
- elif prompt.endswith(b'#'):
- self._exec_cli_command(b'exit')
diff --git a/lib/ansible/plugins/terminal/ironware.py b/lib/ansible/plugins/terminal/ironware.py
deleted file mode 100644
index 3651cbd114..0000000000
--- a/lib/ansible/plugins/terminal/ironware.py
+++ /dev/null
@@ -1,78 +0,0 @@
-#
-# (c) 2016 Red Hat Inc.
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import re
-import json
-
-from ansible.errors import AnsibleConnectionFailure
-from ansible.module_utils._text import to_text, to_bytes
-from ansible.plugins.terminal import TerminalBase
-
-
-class TerminalModule(TerminalBase):
-
- terminal_stdout_re = [
- re.compile(br"[\r\n]?(?:\w+@)?[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:>|#) ?$")
- ]
-
- terminal_stderr_re = [
- re.compile(br"[\r\n]Error - "),
- re.compile(br"[\r\n](?:incomplete|ambiguous|unrecognised|invalid) (?:command|input)", re.I)
- ]
-
- def on_open_shell(self):
- self.disable_pager()
-
- def disable_pager(self):
- cmd = {u'command': u'terminal length 0'}
- try:
- self._exec_cli_command(u'terminal length 0')
- except AnsibleConnectionFailure:
- raise AnsibleConnectionFailure('unable to disable terminal pager')
-
- def on_become(self, passwd=None):
- if self._get_prompt().strip().endswith(b'#'):
- return
-
- cmd = {u'command': u'enable'}
- if passwd:
- # Note: python-3.5 cannot combine u"" and r"" together. Thus make
- # an r string and use to_text to ensure it's text on both py2 and py3.
- cmd[u'prompt'] = to_text(r"[\r\n]?password: ?$", errors='surrogate_or_strict')
- cmd[u'answer'] = passwd
-
- try:
- self._exec_cli_command(to_bytes(json.dumps(cmd), errors='surrogate_or_strict'))
- except AnsibleConnectionFailure:
- raise AnsibleConnectionFailure('unable to elevate privilege to enable mode')
-
- def on_unbecome(self):
- prompt = self._get_prompt()
- if prompt is None:
- # if prompt is None most likely the terminal is hung up at a prompt
- return
-
- if b'(config' in prompt:
- self._exec_cli_command(b'end')
- self._exec_cli_command(b'exit')
-
- elif prompt.endswith(b'#'):
- self._exec_cli_command(b'exit')
diff --git a/lib/ansible/plugins/terminal/netvisor.py b/lib/ansible/plugins/terminal/netvisor.py
deleted file mode 100644
index 27dffb5947..0000000000
--- a/lib/ansible/plugins/terminal/netvisor.py
+++ /dev/null
@@ -1,39 +0,0 @@
-#
-# (c) 2016 Red Hat Inc.
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import json
-import re
-
-from ansible.errors import AnsibleConnectionFailure
-from ansible.module_utils._text import to_text, to_bytes
-from ansible.plugins.terminal import TerminalBase
-
-
-class TerminalModule(TerminalBase):
-
- terminal_stdout_re = [
- re.compile(br">.*[\r\n]?(.*)")
-
- ]
-
- terminal_stderr_re = [
- re.compile(br"% ?Error: (?!\bdoes not exist\b)(?!\balready exists\b)")
- ]
diff --git a/lib/ansible/plugins/terminal/nos.py b/lib/ansible/plugins/terminal/nos.py
deleted file mode 100644
index 245189468f..0000000000
--- a/lib/ansible/plugins/terminal/nos.py
+++ /dev/null
@@ -1,54 +0,0 @@
-#
-# (c) 2018 Extreme Networks Inc.
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import re
-
-from ansible.errors import AnsibleConnectionFailure
-from ansible.plugins.terminal import TerminalBase
-
-
-class TerminalModule(TerminalBase):
-
- terminal_stdout_re = [
- re.compile(br"([\r\n]|(\x1b\[\?7h))[\w\+\-\.:\/\[\]]+(?:\([^\)]+\)){0,3}(?:[>#]) ?$")
- ]
-
- terminal_stderr_re = [
- re.compile(br"% ?Error"),
- # re.compile(br"^% \w+", re.M),
- re.compile(br"% ?Bad secret"),
- re.compile(br"[\r\n%] Bad passwords"),
- re.compile(br"invalid input", re.I),
- re.compile(br"(?:incomplete|ambiguous) command", re.I),
- re.compile(br"connection timed out", re.I),
- re.compile(br"[^\r\n]+ not found"),
- re.compile(br"'[^']' +returned error code: ?\d+"),
- re.compile(br"Bad mask", re.I),
- re.compile(br"% ?(\S+) ?overlaps with ?(\S+)", re.I),
- re.compile(br"[%\S] ?Informational: ?[\s]+", re.I),
- re.compile(br"syntax error: unknown argument.", re.I)
- ]
-
- def on_open_shell(self):
- try:
- self._exec_cli_command(u'terminal length 0')
- except AnsibleConnectionFailure:
- raise AnsibleConnectionFailure('unable to set terminal parameters')
diff --git a/lib/ansible/plugins/terminal/onyx.py b/lib/ansible/plugins/terminal/onyx.py
deleted file mode 100644
index 52d630b9fd..0000000000
--- a/lib/ansible/plugins/terminal/onyx.py
+++ /dev/null
@@ -1,80 +0,0 @@
-#
-# (c) 2016 Red Hat Inc.
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import json
-import re
-
-from ansible.errors import AnsibleConnectionFailure
-from ansible.module_utils._text import to_text, to_bytes
-from ansible.plugins.terminal import TerminalBase
-
-
-class TerminalModule(TerminalBase):
-
- terminal_stdout_re = [
- re.compile(br"(?P<prompt>(.*)( > | # )\Z)"),
- ]
-
- terminal_stderr_re = [
- re.compile(br"\A%|\r\n%|\n%"),
- ]
-
- init_commands = [b'no cli session paging enable', ]
-
- def on_open_shell(self):
- try:
- for cmd in self.init_commands:
- self._exec_cli_command(cmd)
- except AnsibleConnectionFailure:
- raise AnsibleConnectionFailure('unable to set terminal parameters')
-
- def on_become(self, passwd=None):
- if self._get_prompt().endswith(b'#'):
- return
-
- cmd = {u'command': u'enable'}
- if passwd:
- # Note: python-3.5 cannot combine u"" and r"" together. Thus make
- # an r string and use to_text to ensure it's text on both py2 and
- # py3.
- cmd[u'prompt'] = to_text(r"[\r\n]?password: $",
- errors='surrogate_or_strict')
- cmd[u'answer'] = passwd
-
- try:
- self._exec_cli_command(to_bytes(json.dumps(cmd),
- errors='surrogate_or_strict'))
- except AnsibleConnectionFailure:
- raise AnsibleConnectionFailure(
- 'unable to elevate privilege to enable mode')
-
- def on_unbecome(self):
- prompt = self._get_prompt()
- if prompt is None:
- # if prompt is None most likely the terminal is hung up at a prompt
- return
-
- if b'(config' in prompt:
- self._exec_cli_command(b'exit')
- self._exec_cli_command(b'disable')
-
- elif prompt.endswith(b'#'):
- self._exec_cli_command(b'disable')
diff --git a/lib/ansible/plugins/terminal/routeros.py b/lib/ansible/plugins/terminal/routeros.py
deleted file mode 100644
index 78996f28aa..0000000000
--- a/lib/ansible/plugins/terminal/routeros.py
+++ /dev/null
@@ -1,69 +0,0 @@
-#
-# (c) 2016 Red Hat Inc.
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import json
-import re
-
-from ansible.errors import AnsibleConnectionFailure
-from ansible.module_utils._text import to_text, to_bytes
-from ansible.plugins.terminal import TerminalBase
-from ansible.utils.display import Display
-
-display = Display()
-
-
-class TerminalModule(TerminalBase):
-
- ansi_re = [
- # check ECMA-48 Section 5.4 (Control Sequences)
- re.compile(br'(\x1b\[\?1h\x1b=)'),
- re.compile(br'((?:\x9b|\x1b\x5b)[\x30-\x3f]*[\x20-\x2f]*[\x40-\x7e])'),
- re.compile(br'\x08.')
- ]
-
- terminal_initial_prompt = [
- br'\x1bZ',
- ]
-
- terminal_initial_answer = b'\x1b/Z'
-
- terminal_stdout_re = [
- re.compile(br"\x1b<"),
- re.compile(br"\[[\w\.]+\@[\w\s\-\.]+\] ?> ?$"),
- re.compile(br"Please press \"Enter\" to continue!"),
- re.compile(br"Do you want to see the software license\? \[Y\/n\]: ?"),
- ]
-
- terminal_stderr_re = [
- re.compile(br"\nbad command name"),
- re.compile(br"\nno such item"),
- re.compile(br"\ninvalid value for"),
- ]
-
- def on_open_shell(self):
- prompt = self._get_prompt()
- try:
- if prompt.strip().endswith(b':'):
- self._exec_cli_command(b' ')
- if prompt.strip().endswith(b'!'):
- self._exec_cli_command(b'\n')
- except AnsibleConnectionFailure:
- raise AnsibleConnectionFailure('unable to bypass license prompt')
diff --git a/lib/ansible/plugins/terminal/slxos.py b/lib/ansible/plugins/terminal/slxos.py
deleted file mode 100644
index 245189468f..0000000000
--- a/lib/ansible/plugins/terminal/slxos.py
+++ /dev/null
@@ -1,54 +0,0 @@
-#
-# (c) 2018 Extreme Networks Inc.
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import re
-
-from ansible.errors import AnsibleConnectionFailure
-from ansible.plugins.terminal import TerminalBase
-
-
-class TerminalModule(TerminalBase):
-
- terminal_stdout_re = [
- re.compile(br"([\r\n]|(\x1b\[\?7h))[\w\+\-\.:\/\[\]]+(?:\([^\)]+\)){0,3}(?:[>#]) ?$")
- ]
-
- terminal_stderr_re = [
- re.compile(br"% ?Error"),
- # re.compile(br"^% \w+", re.M),
- re.compile(br"% ?Bad secret"),
- re.compile(br"[\r\n%] Bad passwords"),
- re.compile(br"invalid input", re.I),
- re.compile(br"(?:incomplete|ambiguous) command", re.I),
- re.compile(br"connection timed out", re.I),
- re.compile(br"[^\r\n]+ not found"),
- re.compile(br"'[^']' +returned error code: ?\d+"),
- re.compile(br"Bad mask", re.I),
- re.compile(br"% ?(\S+) ?overlaps with ?(\S+)", re.I),
- re.compile(br"[%\S] ?Informational: ?[\s]+", re.I),
- re.compile(br"syntax error: unknown argument.", re.I)
- ]
-
- def on_open_shell(self):
- try:
- self._exec_cli_command(u'terminal length 0')
- except AnsibleConnectionFailure:
- raise AnsibleConnectionFailure('unable to set terminal parameters')
diff --git a/lib/ansible/plugins/terminal/sros.py b/lib/ansible/plugins/terminal/sros.py
deleted file mode 100644
index 77085a383e..0000000000
--- a/lib/ansible/plugins/terminal/sros.py
+++ /dev/null
@@ -1,43 +0,0 @@
-#
-# (c) 2016 Red Hat Inc.
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import re
-
-from ansible.plugins.terminal import TerminalBase
-from ansible.errors import AnsibleConnectionFailure
-
-
-class TerminalModule(TerminalBase):
-
- terminal_stdout_re = [
- re.compile(br"[\r\n]?[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:>|#|\$|>#) ?$"),
- re.compile(br"\[\w+\@[\w\-\.]+(?: [^\]])\] ?[>#\$] ?$")
- ]
-
- terminal_stderr_re = [
- re.compile(br"Error:"),
- ]
-
- def on_open_shell(self):
- try:
- self._exec_cli_command(b'environment no more')
- except AnsibleConnectionFailure:
- raise AnsibleConnectionFailure('unable to set terminal parameters')
diff --git a/lib/ansible/plugins/terminal/voss.py b/lib/ansible/plugins/terminal/voss.py
deleted file mode 100644
index f540be9b4e..0000000000
--- a/lib/ansible/plugins/terminal/voss.py
+++ /dev/null
@@ -1,89 +0,0 @@
-#
-# (c) 2018 Extreme Networks Inc.
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import json
-import re
-
-from ansible.errors import AnsibleConnectionFailure
-from ansible.module_utils._text import to_text, to_bytes
-from ansible.plugins.terminal import TerminalBase
-
-
-class TerminalModule(TerminalBase):
-
- terminal_stdout_re = [
- re.compile(br"[\r\n]+[^\s#>]+(?:[>#])$", re.M)
- ]
-
- terminal_stderr_re = [
- re.compile(br"% ?Error"),
- re.compile(br"% ?Bad secret"),
- re.compile(br"[\r\n%] Bad passwords"),
- re.compile(br"invalid input", re.I),
- re.compile(br"(?:incomplete|ambiguous) command", re.I),
- re.compile(br"connection timed out", re.I),
- re.compile(br"[^\r\n]+ not found"),
- re.compile(br"'[^']' +returned error code: ?\d+"),
- re.compile(br"Discontiguous Subnet Mask"),
- re.compile(br"Conflicting IP address"),
- re.compile(br"[\r\n]Error: ?[\S]+"),
- re.compile(br"[%\S] ?Informational: ?[\s]+", re.I),
- re.compile(br"Command authorization failed")
- ]
-
- def on_open_shell(self):
- try:
- self._exec_cli_command(u'terminal more disable')
- except AnsibleConnectionFailure:
- raise AnsibleConnectionFailure('unable to set terminal parameters')
-
- def on_become(self, passwd=None):
- if self._get_prompt().endswith(b'#'):
- return
-
- cmd = {u'command': u'enable'}
- if passwd:
- # Note: python-3.5 cannot combine u"" and r"" together. Thus make
- # an r string and use to_text to ensure it's text on both py2 and py3.
- cmd[u'prompt'] = to_text(r"[\r\n](?:Local_)?[Pp]assword: ?$", errors='surrogate_or_strict')
- cmd[u'answer'] = passwd
- cmd[u'prompt_retry_check'] = True
- try:
- self._exec_cli_command(to_bytes(json.dumps(cmd), errors='surrogate_or_strict'))
- prompt = self._get_prompt()
- if prompt is None or not prompt.endswith(b'#'):
- raise AnsibleConnectionFailure('failed to elevate privilege to enable mode still at prompt [%s]' % prompt)
- except AnsibleConnectionFailure as e:
- prompt = self._get_prompt()
- raise AnsibleConnectionFailure('unable to elevate privilege to enable mode, at prompt [%s] with error: %s' % (prompt, e.message))
-
- def on_unbecome(self):
- prompt = self._get_prompt()
- if prompt is None:
- # if prompt is None most likely the terminal is hung up at a prompt
- return
-
- if prompt.endswith(b')#'):
- self._exec_cli_command(b'end')
- self._exec_cli_command(b'disable')
-
- elif prompt.endswith(b'#'):
- self._exec_cli_command(b'disable')