diff options
author | Ansible Core Team <info@ansible.com> | 2020-03-09 09:40:36 +0000 |
---|---|---|
committer | Ansible Core Team <info@ansible.com> | 2020-03-09 09:40:36 +0000 |
commit | 91e8679f56be4d8fd78bb3e1b2d5da53f874f753 (patch) | |
tree | 2abfce59200cd4e7d5992dc2d2ca78eab5ea8238 /lib/ansible/plugins | |
parent | 92ff28ec75abca5c6420dffd71a7b2f91aecdcbf (diff) | |
download | ansible-91e8679f56be4d8fd78bb3e1b2d5da53f874f753.tar.gz |
Migrated to dellemc_networking.os9
Diffstat (limited to 'lib/ansible/plugins')
-rw-r--r-- | lib/ansible/plugins/action/dellos9.py | 81 | ||||
-rw-r--r-- | lib/ansible/plugins/cliconf/dellos9.py | 123 | ||||
-rw-r--r-- | lib/ansible/plugins/doc_fragments/dellos9.py | 58 | ||||
-rw-r--r-- | lib/ansible/plugins/terminal/dellos9.py | 83 |
4 files changed, 0 insertions, 345 deletions
diff --git a/lib/ansible/plugins/action/dellos9.py b/lib/ansible/plugins/action/dellos9.py deleted file mode 100644 index 6500e165c6..0000000000 --- a/lib/ansible/plugins/action/dellos9.py +++ /dev/null @@ -1,81 +0,0 @@ -# -# (c) 2016 Red Hat Inc. -# -# Copyright (c) 2017 Dell 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 sys -import copy - -from ansible import constants as C -from ansible.plugins.action.network import ActionModule as ActionNetworkModule -from ansible.module_utils.network.common.utils import load_provider -from ansible.module_utils.network.dellos9.dellos9 import dellos9_provider_spec -from ansible.utils.display import Display - -display = Display() - - -class ActionModule(ActionNetworkModule): - - def run(self, tmp=None, task_vars=None): - del tmp # tmp no longer has any effect - - module_name = self._task.action.split('.')[-1] - self._config_module = True if module_name == 'dellos9_config' else False - socket_path = None - persistent_connection = self._play_context.connection.split('.')[-1] - - if persistent_connection == 'network_cli': - provider = self._task.args.get('provider', {}) - if any(provider.values()): - display.warning('provider is unnecessary when using network_cli and will be ignored') - del self._task.args['provider'] - elif self._play_context.connection == 'local': - provider = load_provider(dellos9_provider_spec, self._task.args) - pc = copy.deepcopy(self._play_context) - pc.connection = 'network_cli' - pc.network_os = 'dellos9' - pc.remote_addr = provider['host'] or self._play_context.remote_addr - pc.port = int(provider['port'] or self._play_context.port or 22) - pc.remote_user = provider['username'] or self._play_context.connection_user - pc.password = provider['password'] or self._play_context.password - pc.private_key_file = provider['ssh_keyfile'] or self._play_context.private_key_file - command_timeout = int(provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT) - pc.become = provider['authorize'] or False - if pc.become: - pc.become_method = 'enable' - pc.become_pass = provider['auth_pass'] - - display.vvv('using connection plugin %s' % pc.connection, pc.remote_addr) - connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin, task_uuid=self._task._uuid) - connection.set_options(direct={'persistent_command_timeout': command_timeout}) - - socket_path = connection.run() - display.vvvv('socket_path: %s' % socket_path, pc.remote_addr) - if not socket_path: - return {'failed': True, - 'msg': 'unable to open shell. Please see: ' + - 'https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell'} - - task_vars['ansible_socket'] = socket_path - - result = super(ActionModule, self).run(task_vars=task_vars) - return result diff --git a/lib/ansible/plugins/cliconf/dellos9.py b/lib/ansible/plugins/cliconf/dellos9.py deleted file mode 100644 index 1d758d0784..0000000000 --- a/lib/ansible/plugins/cliconf/dellos9.py +++ /dev/null @@ -1,123 +0,0 @@ -# -# (c) 2017 Red Hat Inc. -# -# (c) 2017 Dell EMC. -# -# 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 - -DOCUMENTATION = """ ---- -cliconf: dellos9 -short_description: Use dellos9 cliconf to run command on Dell OS9 platform -description: - - This dellos9 plugin provides low level abstraction apis for - sending and receiving CLI commands from Dell OS9 network devices. -version_added: 2.5 -""" - -import re -import json - -from itertools import chain - -from ansible.errors import AnsibleConnectionFailure -from ansible.module_utils._text import to_bytes, to_text -from ansible.module_utils.common._collections_compat import Mapping -from ansible.module_utils.network.common.utils import to_list -from ansible.plugins.cliconf import CliconfBase, enable_mode - - -class Cliconf(CliconfBase): - - def get_device_info(self): - device_info = {} - - device_info['network_os'] = 'dellos9' - reply = self.get('show version') - data = to_text(reply, errors='surrogate_or_strict').strip() - - match = re.search(r'Software Version (\S+)', data) - if match: - device_info['network_os_version'] = match.group(1) - - match = re.search(r'System Type (\S+)', data, re.M) - if match: - device_info['network_os_model'] = match.group(1) - - reply = self.get('show running-config | grep hostname') - data = to_text(reply, errors='surrogate_or_strict').strip() - match = re.search(r'^hostname (.+)', data, re.M) - if match: - device_info['network_os_hostname'] = match.group(1) - - return device_info - - @enable_mode - def get_config(self, source='running', format='text', flags=None): - if source not in ('running', 'startup'): - return self.invalid_params("fetching configuration from %s is not supported" % source) -# if source == 'running': -# cmd = 'show running-config all' - else: - cmd = 'show startup-config' - return self.send_command(cmd) - - @enable_mode - def edit_config(self, command): - for cmd in chain(['configure terminal'], to_list(command), ['end']): - self.send_command(cmd) - - def get(self, command, prompt=None, answer=None, sendonly=False, newline=True, check_all=False): - return self.send_command(command=command, prompt=prompt, answer=answer, sendonly=sendonly, newline=newline, check_all=check_all) - - def get_capabilities(self): - result = super(Cliconf, self).get_capabilities() - return json.dumps(result) - - def run_commands(self, commands=None, check_rc=True): - if commands is None: - raise ValueError("'commands' value is required") - - responses = list() - for cmd in to_list(commands): - if not isinstance(cmd, Mapping): - cmd = {'command': cmd} - - output = cmd.pop('output', None) - if output: - raise ValueError("'output' value %s is not supported for run_commands" % output) - - try: - out = self.send_command(**cmd) - except AnsibleConnectionFailure as e: - if check_rc: - raise - out = getattr(e, 'err', to_text(e)) - - responses.append(out) - - return responses - - def set_cli_prompt_context(self): - """ - Make sure we are in the operational cli mode - :return: None - """ - if self._connection.connected: - self._update_cli_prompt_context(config_context=')#') diff --git a/lib/ansible/plugins/doc_fragments/dellos9.py b/lib/ansible/plugins/doc_fragments/dellos9.py deleted file mode 100644 index e65e53cdc3..0000000000 --- a/lib/ansible/plugins/doc_fragments/dellos9.py +++ /dev/null @@ -1,58 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright: (c) 2015, Peter Sprygada <psprygada@ansible.com> -# Copyright: (c) 2016, Dell Inc. -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - - -class ModuleDocFragment(object): - - # Standard files documentation fragment - DOCUMENTATION = r''' -options: - provider: - description: - - A dict object containing connection details. - type: dict - suboptions: - host: - description: - - Specifies the DNS host name or address for connecting to the remote - device over the specified transport. The value of host is used as - the destination address for the transport. - type: str - required: true - port: - description: - - Specifies the port to use when building the connection to the remote - device. - type: int - default: 22 - username: - description: - - User to authenticate the SSH session to the remote device. If the - value is not specified in the task, the value of environment variable - C(ANSIBLE_NET_USERNAME) will be used instead. - type: str - password: - description: - - Password to authenticate the SSH session to the remote device. If the - value is not specified in the task, the value of environment variable - C(ANSIBLE_NET_PASSWORD) will be used instead. - type: str - ssh_keyfile: - description: - - Path to an ssh key used to authenticate the SSH session to the remote - device. If the value is not specified in the task, the value of - environment variable C(ANSIBLE_NET_SSH_KEYFILE) will be used instead. - type: path - timeout: - description: - - Specifies idle timeout (in seconds) for the connection. Useful if the - console freezes before continuing. For example when saving - configurations. - type: int - default: 10 -notes: - - For more information on using Ansible to manage Dell EMC Network devices see U(https://www.ansible.com/ansible-dell-networking). -''' diff --git a/lib/ansible/plugins/terminal/dellos9.py b/lib/ansible/plugins/terminal/dellos9.py deleted file mode 100644 index ceb20f85b2..0000000000 --- a/lib/ansible/plugins/terminal/dellos9.py +++ /dev/null @@ -1,83 +0,0 @@ -# -# (c) 2016 Red Hat Inc. -# -# Copyright (c) 2017 Dell 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.module_utils._text import to_text, to_bytes -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: (?:(?!\bdoes not exist\b)(?!\balready exists\b)(?!\bHost not found\b)(?!\bnot active\b).)*\n"), - 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"'[^']' +returned error code: ?\d+"), - ] - - terminal_initial_prompt = br"\[y/n\]:" - - terminal_initial_answer = b"y" - - def on_open_shell(self): - try: - self._exec_cli_command(b'terminal length 0') - 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: - 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 prompt.strip().endswith(b')#'): - self._exec_cli_command(b'end') - self._exec_cli_command(b'disable') - - elif prompt.endswith(b'#'): - self._exec_cli_command(b'disable') |