mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
8137c7207d
This updates the network_cli connection plugin to attempt to automatically determine the remote device os. The device network os discovery can be overridden by setting the ansible_network_os value.
62 lines
2 KiB
Python
62 lines
2 KiB
Python
#
|
|
# (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_prompts_re = [
|
|
re.compile(r'[\r\n]?[a-zA-Z]{1}[a-zA-Z0-9-]*[>|#|%](?:\s*)$'),
|
|
re.compile(r'[\r\n]?[a-zA-Z]{1}[a-zA-Z0-9-]*\(.+\)#(?:\s*)$')
|
|
]
|
|
|
|
terminal_errors_re = [
|
|
re.compile(r"% ?Error"),
|
|
re.compile(r"^% \w+", re.M),
|
|
re.compile(r"% ?Bad secret"),
|
|
re.compile(r"invalid input", re.I),
|
|
re.compile(r"(?:incomplete|ambiguous) command", re.I),
|
|
re.compile(r"connection timed out", re.I),
|
|
re.compile(r"[^\r\n]+ not found", re.I),
|
|
re.compile(r"'[^']' +returned error code: ?\d+"),
|
|
re.compile(r"syntax error"),
|
|
re.compile(r"unknown command"),
|
|
re.compile(r"user not present")
|
|
]
|
|
|
|
def on_open_shell(self):
|
|
try:
|
|
self._exec_cli_command('terminal length 0')
|
|
except AnsibleConnectionFailure:
|
|
raise AnsibleConnectionFailure('unable to set terminal parameters')
|
|
|
|
@staticmethod
|
|
def guess_network_os(conn):
|
|
stdin, stdout, stderr = conn.exec_command('show version')
|
|
if 'NX-OS' in stdout.read():
|
|
return 'nxos'
|
|
|
|
|
|
|