Module nxos logging fixes (#52883)

* nxos_logging fixes
This commit is contained in:
Mike Wiebe
2019-03-06 13:55:03 -05:00
committed by Nathaniel Case
parent 0b579a0837
commit b090b57eac
3 changed files with 78 additions and 27 deletions

View File

@@ -301,14 +301,16 @@ class LocalNxapi:
if isinstance(commands, (list, set, tuple)):
commands = ' ;'.join(commands)
msg = {
'version': version,
'type': command_type,
'chunk': chunk,
'sid': sid,
'input': commands,
'output_format': 'json'
}
# Order should not matter but some versions of NX-OS software fail
# to process the payload properly if 'input' gets serialized before
# 'type' and the payload of 'input' contains the word 'type'.
msg = collections.OrderedDict()
msg['version'] = version
msg['type'] = command_type
msg['chunk'] = chunk
msg['sid'] = sid
msg['input'] = commands
msg['output_format'] = 'json'
return dict(ins_api=msg)
@@ -448,7 +450,6 @@ class LocalNxapi:
commands = 'config replace {0}'.format(replace)
commands = to_list(commands)
msg, msg_timestamps = self.send_request(commands, output='config', check_status=True,
return_error=return_error, opts=opts)
if return_error:
@@ -664,13 +665,18 @@ class HttpApi:
raise ValueError("commit comment is not supported")
def read_module_context(self, module_key):
if self._module_context.get(module_key):
return self._module_context[module_key]
try:
module_context = self._connection.read_module_context(module_key)
except ConnectionError as exc:
self._module.fail_json(msg=to_text(exc, errors='surrogate_then_replace'))
return None
return module_context
def save_module_context(self, module_key, module_context):
self._module_context[module_key] = module_context
try:
self._connection.save_module_context(module_key, module_context)
except ConnectionError as exc:
self._module.fail_json(msg=to_text(exc, errors='surrogate_then_replace'))
return None