mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 22:02:50 +00:00
Remove cliconf from httpapi connection (#46813)
* Bare minimum rip out cliconf * nxapi changeover * Update documentation, move options * Memoize device_info * Gratuitous rename to underscore use of local api implementation Fixup eos module_utils like nxos * Streamline version and image scans * Expose get_capabilities through module_utils * Add load_config to module_utils * Support rpcs using both args and kwargs * Add get_config for nxos * Add get_diff * module context, pulled from nxapi We could probably do this correctly later * Fix eos issues * Limit connection._sub_plugin to only one plugin
This commit is contained in:
@@ -297,7 +297,7 @@ class NetworkConnectionBase(ConnectionBase):
|
||||
self._local = connection_loader.get('local', play_context, '/dev/null')
|
||||
self._local.set_options()
|
||||
|
||||
self._sub_plugins = []
|
||||
self._sub_plugin = {}
|
||||
self._cached_variables = (None, None, None)
|
||||
|
||||
# reconstruct the socket_path and set instance values accordingly
|
||||
@@ -309,8 +309,9 @@ class NetworkConnectionBase(ConnectionBase):
|
||||
return self.__dict__[name]
|
||||
except KeyError:
|
||||
if not name.startswith('_'):
|
||||
for plugin in self._sub_plugins:
|
||||
method = getattr(plugin['obj'], name, None)
|
||||
plugin = self._sub_plugin.get('obj')
|
||||
if plugin:
|
||||
method = getattr(plugin, name, None)
|
||||
if method is not None:
|
||||
return method
|
||||
raise AttributeError("'%s' object has no attribute '%s'" % (self.__class__.__name__, name))
|
||||
@@ -342,12 +343,11 @@ class NetworkConnectionBase(ConnectionBase):
|
||||
def set_options(self, task_keys=None, var_options=None, direct=None):
|
||||
super(NetworkConnectionBase, self).set_options(task_keys=task_keys, var_options=var_options, direct=direct)
|
||||
|
||||
for plugin in self._sub_plugins:
|
||||
if plugin['type'] != 'external':
|
||||
try:
|
||||
plugin['obj'].set_options(task_keys=task_keys, var_options=var_options, direct=direct)
|
||||
except AttributeError:
|
||||
pass
|
||||
if self._sub_plugin.get('obj') and self._sub_plugin.get('type') != 'external':
|
||||
try:
|
||||
self._sub_plugin['obj'].set_options(task_keys=task_keys, var_options=var_options, direct=direct)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
def _update_connection_state(self):
|
||||
'''
|
||||
|
||||
@@ -37,8 +37,8 @@ options:
|
||||
network_os:
|
||||
description:
|
||||
- Configures the device platform network operating system. This value is
|
||||
used to load the correct httpapi and cliconf plugins to communicate
|
||||
with the remote device
|
||||
used to load the correct httpapi plugin to communicate with the remote
|
||||
device
|
||||
vars:
|
||||
- name: ansible_network_os
|
||||
remote_user:
|
||||
@@ -154,7 +154,7 @@ from ansible.module_utils.six.moves import cPickle
|
||||
from ansible.module_utils.six.moves.urllib.error import HTTPError, URLError
|
||||
from ansible.module_utils.urls import open_url
|
||||
from ansible.playbook.play_context import PlayContext
|
||||
from ansible.plugins.loader import cliconf_loader, httpapi_loader
|
||||
from ansible.plugins.loader import httpapi_loader
|
||||
from ansible.plugins.connection import NetworkConnectionBase
|
||||
from ansible.utils.display import Display
|
||||
|
||||
@@ -177,17 +177,11 @@ class Connection(NetworkConnectionBase):
|
||||
|
||||
self.httpapi = httpapi_loader.get(self._network_os, self)
|
||||
if self.httpapi:
|
||||
self._sub_plugins.append({'type': 'httpapi', 'name': self._network_os, 'obj': self.httpapi})
|
||||
self._sub_plugin = {'type': 'httpapi', 'name': self._network_os, 'obj': self.httpapi}
|
||||
display.vvvv('loaded API plugin for network_os %s' % self._network_os)
|
||||
else:
|
||||
raise AnsibleConnectionFailure('unable to load API plugin for network_os %s' % self._network_os)
|
||||
|
||||
self.cliconf = cliconf_loader.get(self._network_os, self)
|
||||
if self.cliconf:
|
||||
self._sub_plugins.append({'type': 'cliconf', 'name': self._network_os, 'obj': self.cliconf})
|
||||
display.vvvv('loaded cliconf plugin for network_os %s' % self._network_os)
|
||||
else:
|
||||
display.vvvv('unable to load cliconf for network_os %s' % self._network_os)
|
||||
else:
|
||||
raise AnsibleConnectionFailure(
|
||||
'Unable to automatically determine host network os. Please '
|
||||
|
||||
@@ -183,7 +183,7 @@ class Connection(NetworkConnectionBase):
|
||||
|
||||
self.napalm.open()
|
||||
|
||||
self._sub_plugins.append({'type': 'external', 'name': 'napalm', 'obj': self.napalm})
|
||||
self._sub_plugin = {'type': 'external', 'name': 'napalm', 'obj': self.napalm}
|
||||
display.vvvv('created napalm device for network_os %s' % self._network_os, host=host)
|
||||
self._connected = True
|
||||
|
||||
|
||||
@@ -217,11 +217,11 @@ class Connection(NetworkConnectionBase):
|
||||
|
||||
netconf = netconf_loader.get(self._network_os, self)
|
||||
if netconf:
|
||||
self._sub_plugins.append({'type': 'netconf', 'name': self._network_os, 'obj': netconf})
|
||||
self._sub_plugin = {'type': 'netconf', 'name': self._network_os, 'obj': netconf}
|
||||
display.display('loaded netconf plugin for network_os %s' % self._network_os, log_only=True)
|
||||
else:
|
||||
netconf = netconf_loader.get("default", self)
|
||||
self._sub_plugins.append({'type': 'netconf', 'name': 'default', 'obj': netconf})
|
||||
self._sub_plugin = {'type': 'netconf', 'name': 'default', 'obj': netconf}
|
||||
display.display('unable to load netconf plugin for network_os %s, falling back to default plugin' % self._network_os)
|
||||
display.display('network_os is set to %s' % self._network_os, log_only=True)
|
||||
|
||||
|
||||
@@ -231,7 +231,7 @@ class Connection(NetworkConnectionBase):
|
||||
self.cliconf = cliconf_loader.get(self._network_os, self)
|
||||
if self.cliconf:
|
||||
display.vvvv('loaded cliconf plugin for network_os %s' % self._network_os)
|
||||
self._sub_plugins.append({'type': 'cliconf', 'name': self._network_os, 'obj': self.cliconf})
|
||||
self._sub_plugin = {'type': 'cliconf', 'name': self._network_os, 'obj': self.cliconf}
|
||||
else:
|
||||
display.vvvv('unable to load cliconf for network_os %s' % self._network_os)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user