added response_timestamps to ios_xr_command module (#50095)

This commit is contained in:
vaneuk 2019-02-04 16:19:07 +03:00 committed by Trishna Guha
parent daf1cfbde0
commit 2a0c356da9
4 changed files with 17 additions and 6 deletions

View file

@ -24,6 +24,7 @@ import json
from ansible.errors import AnsibleConnectionFailure
from ansible.module_utils._text import to_text
from ansible.module_utils.basic import get_timestamp
from ansible.module_utils.common._collections_compat import Mapping
from ansible.module_utils.connection import ConnectionError
from ansible.module_utils.network.common.config import NetworkConfig, dumps
@ -172,10 +173,11 @@ class Cliconf(CliconfBase):
self.send_command(**cmd_obj)
def run_commands(self, commands=None, check_rc=True):
def run_commands(self, commands=None, check_rc=True, return_timestamps=False):
if commands is None:
raise ValueError("'commands' value is required")
responses = list()
timestamps = list()
for cmd in to_list(commands):
if not isinstance(cmd, Mapping):
cmd = {'command': cmd}
@ -185,6 +187,7 @@ class Cliconf(CliconfBase):
raise ValueError("'output' value %s is not supported for run_commands" % output)
try:
timestamp = get_timestamp()
out = self.send_command(**cmd)
except AnsibleConnectionFailure as e:
if check_rc:
@ -203,7 +206,11 @@ class Cliconf(CliconfBase):
pass
responses.append(out)
return responses
timestamps.append(timestamp)
if return_timestamps:
return responses, timestamps
else:
return responses
def discard_changes(self):
self.send_command('abort')