fixes issue in eos shared module for earlier versions of EOS (#17980)
Earlier versions of EOS that do not support config sessions would create an exception. This fix will now check if the device supports sessions and if it doesn't, it will fall back to not using sessions
This commit is contained in:
parent
33f5c25f41
commit
3badb212fb
1 changed files with 18 additions and 1 deletions
|
@ -50,7 +50,7 @@ class EosConfigMixin(object):
|
|||
cmds = ['configure terminal']
|
||||
cmds.extend(to_list(commands))
|
||||
cmds.append('end')
|
||||
responses = self.execute(commands)
|
||||
responses = self.execute(cmds)
|
||||
return responses[1:-1]
|
||||
|
||||
def get_config(self, include_defaults=False, **kwargs):
|
||||
|
@ -60,6 +60,12 @@ class EosConfigMixin(object):
|
|||
return self.execute([cmd])[0]
|
||||
|
||||
def load_config(self, config, commit=False, replace=False):
|
||||
if self.supports_sessions():
|
||||
return self.load_config_session(config, commit, replace)
|
||||
else:
|
||||
return self.configure(config)
|
||||
|
||||
def load_config_session(self, config, commit=False, replace=False):
|
||||
""" Loads the configuration into the remote device
|
||||
"""
|
||||
session = 'ansible_%s' % int(time.time())
|
||||
|
@ -116,6 +122,17 @@ class EosConfigMixin(object):
|
|||
commands = ['configure session %s' % session, 'abort']
|
||||
self.execute(commands)
|
||||
|
||||
def supports_sessions(self):
|
||||
try:
|
||||
if isinstance(self, Eapi):
|
||||
self.execute('show configuration sessions', output='text')
|
||||
else:
|
||||
self.execute('show configuration sessions')
|
||||
return True
|
||||
except NetworkError:
|
||||
return False
|
||||
|
||||
|
||||
|
||||
class Eapi(EosConfigMixin):
|
||||
|
||||
|
|
Loading…
Reference in a new issue