-
Notifications
You must be signed in to change notification settings - Fork 23
/
netmiko_send_command.py
33 lines (29 loc) · 1.14 KB
/
netmiko_send_command.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from typing import Any
from nornir.core.task import Result, Task
from nornir_netmiko.connections import CONNECTION_NAME
def netmiko_send_command(
task: Task,
command_string: str,
use_timing: bool = False,
enable: bool = False,
**kwargs: Any
) -> Result:
"""
Execute Netmiko send_command method (or send_command_timing)
Arguments:
command_string: Command to execute on the remote network device.
use_timing: Set to True to switch to send_command_timing method.
enable: Set to True to force Netmiko .enable() call.
kwargs: Additional arguments to pass to send_command method.
Returns:
Result object with the following attributes set:
* result: Result of the show command (generally a string, but depends on use of TextFSM).
"""
net_connect = task.host.get_connection(CONNECTION_NAME, task.nornir.config)
if enable:
net_connect.enable()
if use_timing:
result = net_connect.send_command_timing(command_string, **kwargs)
else:
result = net_connect.send_command(command_string, **kwargs)
return Result(host=task.host, result=result)