mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 14:20:22 -07:00
adds new feature to network_cli (#19848)
In some cases it is desirable to have a send only function that doesn't wait for the response from the CLI (such as reloading a device). This adds a new key to the command json string sendonly that will achieve this behavior.
This commit is contained in:
parent
08e2a5d4fb
commit
4937dd67e4
1 changed files with 3 additions and 3 deletions
|
@ -149,6 +149,8 @@ class Connection(_Connection):
|
||||||
command = obj['command']
|
command = obj['command']
|
||||||
self._history.append(command)
|
self._history.append(command)
|
||||||
self._shell.sendall('%s\r' % command)
|
self._shell.sendall('%s\r' % command)
|
||||||
|
if obj.get('sendonly'):
|
||||||
|
return
|
||||||
return self.receive(obj)
|
return self.receive(obj)
|
||||||
except (socket.timeout, AttributeError):
|
except (socket.timeout, AttributeError):
|
||||||
raise AnsibleConnectionFailure("timeout trying to send command: %s" % command.strip())
|
raise AnsibleConnectionFailure("timeout trying to send command: %s" % command.strip())
|
||||||
|
@ -206,15 +208,13 @@ class Connection(_Connection):
|
||||||
* command - the command string to execute
|
* command - the command string to execute
|
||||||
* prompt - the expected prompt generated by executing command
|
* prompt - the expected prompt generated by executing command
|
||||||
* response - the string to respond to the prompt with
|
* response - the string to respond to the prompt with
|
||||||
|
* sendonly - bool to disable waiting for response
|
||||||
|
|
||||||
:arg cmd: the string that represents the command to be executed
|
:arg cmd: the string that represents the command to be executed
|
||||||
which can be a single command or a json encoded string
|
which can be a single command or a json encoded string
|
||||||
:returns: a tuple of (return code, stdout, stderr). The return
|
:returns: a tuple of (return code, stdout, stderr). The return
|
||||||
code is an integer and stdout and stderr are strings
|
code is an integer and stdout and stderr are strings
|
||||||
"""
|
"""
|
||||||
# TODO: add support for timeout to the cmd to handle non return
|
|
||||||
# commands such as a system restart
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
obj = json.loads(cmd)
|
obj = json.loads(cmd)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue