netmiko_send_command_ps

Send command string to device using promptless (ps) approach. Can be used for any command, including commands that change device prompt. Multiple commands can be sent separated by ‘ ‘ newline.

../_images/promptless_mode_v0.1.png

Promptless mode allows to detect end of output from device without relying on timers or correct prompt matching (hence the name - promptless). This mode still uses pattern to decide if device finished emitting data, but that pattern is not dependent on device’s prompt regex matching.

Each reading cycle, data from device read as fast as possible until device either finishes or pose to prepare more data. Latter case detected and handled using read timeout timer and checking if new data received. To detect when device finishes producing output, algorithm sends two space character to device and checks in next read cycle if last line contains two additional spaces, concluding that end of output detected if so and continue cycling otherwise.

Overall its similar to how Humans interact with device prompt to verify that its still operational - try hitting space or type something in terminal to see if its appears on the screen.

Dependencies:

netmiko_send_command_ps sample usage

Code to invoke netmiko_send_command_ps task:

from nornir import InitNornir
from nornir_salt import netmiko_send_command_ps

nr = InitNornir(config_file="config.yaml")

commands = '''
show ip int brief
conf t
interface loopback 100
ip address 1.1.1.100 255.255.255.255
end
show ip int brief
wr
'''

output = nr.run(
    task=netmiko_send_command_ps,
    commands="show run",
    netmiko_kwargs={}
)

output_multiline = nr.run(
    task=netmiko_send_command_ps,
    commands=commands,
    netmiko_kwargs={}
)

netmiko_send_command_ps returns

Returns Nornir results object with individual tasks names set equal to commands sent to device.

netmiko_send_command_ps reference

nornir_salt.plugins.tasks.netmiko_send_command_ps.netmiko_send_command_ps(task: nornir.core.task.Task, command_string: str, enable: bool = False, **kwargs: Any) nornir.core.task.Result

Patch netmiko connection object with send_command_ps method and execute it.

Parameters
  • command_string – (str) Command to execute on the remote network device.

  • enable – (bool) Set to True to force Netmiko .enable() call.

  • kwargs – (dict) Additional arguments to pass to send_command_ps method.

Return result object

with result of the show command

nornir_salt.plugins.tasks.netmiko_send_command_ps.send_command_ps(self, command_string, read_timeout=30, timeout=120, inter_loop_sleep=0.1, initial_sleep=0.1, strip_prompt=True, strip_command=True, normalize=True, cutoff=0.6, nowait=False)

Execute command_string_ps on the SSH channel using promptless (ps) approach. Can be used for any commands, including commands that change prompt. Multiple commands can be sent separated by ‘n’ newline.

Parameters
  • command_string – (str) The command(s) to be executed on the remote device.

  • read_timeout – (int) Timeout in seconds to wait for data from devices, default 30s, if set to -1 will wait indefinitely

  • timeout – (int) Absolute timeout in seconds of overall wait, default 120s, if set to -1 will wait indefinitely

  • inter_loop_sleep – (int) Interval in seconds to sleep between reading loops, default 0.1s

  • initial_sleep – (int) time to sleep after sending command, default 0.1s

  • strip_prompt – (bool) Remove the trailing router prompt from the output (default: True).

  • strip_command – (bool) Remove the echo of the command from the output (default: True).

  • normalize – (bool) Ensure the proper enter is sent at end of command (default: True).

  • nowait – (bool) Default is False, if True sends command and returns immediately without waiting for prompt right after initial_sleep timer elapsed.