Skip to content

Commit

Permalink
napalm_ping.py (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
tejasmokashi1992 committed Jan 30, 2020
1 parent 3e65272 commit 397f541
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nornir/plugins/tasks/networking/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .netmiko_send_config import netmiko_send_config
from .netmiko_save_config import netmiko_save_config
from .tcp_ping import tcp_ping
from .napalm_ping import napalm_ping

__all__ = (
"napalm_cli",
Expand All @@ -28,4 +29,5 @@
"netmiko_send_config",
"netmiko_save_config",
"tcp_ping",
"napalm_ping",
)
55 changes: 55 additions & 0 deletions nornir/plugins/tasks/networking/napalm_ping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from typing import Optional
from nornir.core.task import Result, Task


def napalm_ping(
task: Task,
dest: str,
source: Optional[str] = None,
ttl: Optional[int] = 255,
timeout: Optional[int] = 2,
size: Optional[int] = 100,
count: Optional[int] = 5,
vrf: Optional[str] = None,
) -> Result:
"""
Executes ping on the device and returns a dictionary with the result.
Arguments:
dest(str) – Host or IP Address of the destination.
source(str, optional) – Source address of echo request.
ttl(int, optional) – Max number of hops.
timeout(int, optional) – Max seconds to wait after sending final packet.
size(int, optional) – Size of request in bytes.
count(int, optional) – Number of ping request to send.
vrf(str, optional) - Name of vrf.
Examples:
Simple example::
> nr.run(task=napalm_ping,
> dest='10.1.1.1')
Passing some other optional arguments::
> nr.run(task=napalm_ping,
> dest='10.1.1.1', source='10.1.1.2', size=1400, count=10)
Returns:
Result object with the following attributes set:
* result (``dict``): list of dictionary with the result of the ping response.
Output dictionary has one of following keys "success or error"
"""
device = task.host.get_connection("napalm", task.nornir.config)
result = device.ping(
destination=dest,
source=source,
ttl=ttl,
timeout=timeout,
size=size,
count=count,
vrf=vrf,
)
return Result(host=task.host, result=result)

0 comments on commit 397f541

Please sign in to comment.