mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-09 09:54:02 -07:00
bug fixes and updates for eos connections (#21534)
* refactors supports_sessions to a property * exposes supports_sessions as a toplevel function * adds open_shell() to network_cli * implements open_shell() in eos action plugin
This commit is contained in:
parent
a01288859d
commit
9d4a3599b8
3 changed files with 48 additions and 17 deletions
|
@ -94,6 +94,15 @@ class Cli:
|
|||
def __init__(self, module):
|
||||
self._module = module
|
||||
self._device_configs = {}
|
||||
self._session_support = None
|
||||
|
||||
@property
|
||||
def supports_sessions(self):
|
||||
if self._session_support is not None:
|
||||
return self._session_support
|
||||
rc, out, err = self.exec_command('show configuration sessions')
|
||||
self._session_support = rc == 0
|
||||
return self._session_support
|
||||
|
||||
def exec_command(self, command):
|
||||
if isinstance(command, dict):
|
||||
|
@ -195,7 +204,7 @@ class Cli:
|
|||
except ValueError:
|
||||
pass
|
||||
|
||||
if not all((bool(use_session), self.supports_sessions())):
|
||||
if not all((bool(use_session), self.supports_sessions)):
|
||||
return configure(self, commands)
|
||||
|
||||
conn = get_connection(self)
|
||||
|
@ -255,6 +264,14 @@ class Eapi:
|
|||
else:
|
||||
self._enable = 'enable'
|
||||
|
||||
@property
|
||||
def supports_sessions(self):
|
||||
if self._session_support:
|
||||
return self._session_support
|
||||
response = self.send_request(['show configuration sessions'])
|
||||
self._session_support = 'error' not in response
|
||||
return self._session_support
|
||||
|
||||
def _request_builder(self, commands, output, reqid=None):
|
||||
params = dict(version=1, cmds=commands, format=output)
|
||||
return dict(jsonrpc='2.0', id=reqid, method='runCmds', params=params)
|
||||
|
@ -344,13 +361,6 @@ class Eapi:
|
|||
self._device_configs[cmd] = cfg
|
||||
return cfg
|
||||
|
||||
def supports_sessions(self):
|
||||
if self._session_support:
|
||||
return self._session_support
|
||||
response = self.send_request(['show configuration sessions'])
|
||||
self._session_support = 'error' not in response
|
||||
return self._session_support
|
||||
|
||||
def configure(self, commands):
|
||||
"""Sends the ordered set of commands to the device
|
||||
"""
|
||||
|
@ -371,7 +381,7 @@ class Eapi:
|
|||
fallback to using configure() to load the commands. If that happens,
|
||||
there will be no returned diff or session values
|
||||
"""
|
||||
if not supports_sessions():
|
||||
if not self.supports_sessions:
|
||||
return configure(self, commands)
|
||||
|
||||
session = 'ansible_%s' % int(time.time())
|
||||
|
@ -406,6 +416,8 @@ class Eapi:
|
|||
is_json = lambda x: str(x).endswith('| json')
|
||||
is_text = lambda x: not str(x).endswith('| json')
|
||||
|
||||
supports_sessions = lambda x: get_connection(module).supports_sessions
|
||||
|
||||
def get_config(module, flags=[]):
|
||||
conn = get_connection(module)
|
||||
return conn.get_config(flags)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue