Networking¶
-
nornir.plugins.tasks.networking.
napalm_cli
(task: nornir.core.task.Task, commands: List[str]) → nornir.core.task.Result¶ Run commands on remote devices using napalm
Parameters: commands – commands to execute Returns: - result (
dict
): result of the commands execution
Return type: Result object with the following attributes set - result (
-
nornir.plugins.tasks.networking.
napalm_configure
(task: nornir.core.task.Task, dry_run: Optional[bool] = None, filename: Optional[str] = None, configuration: Optional[str] = None, replace: bool = False) → nornir.core.task.Result¶ Loads configuration into a network devices using napalm
Parameters: - dry_run – Whether to apply changes or not
- filename – filename containing the configuration to load into the device
- configuration – configuration to load into the device
- replace – whether to replace or merge the configuration
Returns: - changed (
bool
): whether the task is changing the system or not - diff (
string
): change in the system
Return type: Result object with the following attributes set
-
nornir.plugins.tasks.networking.
napalm_get
(task: nornir.core.task.Task, getters: List[str], getters_options: Optional[Dict[str, Dict[str, Any]]] = None, **kwargs) → nornir.core.task.Result¶ Gather information from network devices using napalm
Parameters: - getters – getters to use
- getters_options (dict of dicts) – When passing multiple getters you pass a dictionary where the outer key is the getter name and the included dictionary represents the options to pass to the getter
- **kwargs – will be passed as they are to the getters
Examples
Simple example:
> nr.run(task=napalm_get, > getters=["interfaces", "facts"])
Passing options using
**kwargs
:> nr.run(task=napalm_get, > getters=["config"], > retrieve="all")
Passing options using
getters_options
:> nr.run(task=napalm_get, > getters=["config", "interfaces"], > getters_options={"config": {"retrieve": "all"}})
Returns: - result (
dict
): dictionary with the result of the getter
Return type: Result object with the following attributes set
-
nornir.plugins.tasks.networking.
napalm_validate
(task: nornir.core.task.Task, src: Optional[str] = None, validation_source: Optional[Dict[str, Dict[str, Any]]] = None) → nornir.core.task.Result¶ Gather information with napalm and validate it:
Parameters: - src – file to use as validation source
- validation_source (list) – data to validate device’s state
Returns: - result (
dict
): dictionary with the result of the validation - complies (
bool
): Whether the device complies or not
Return type: Result object with the following attributes set
-
nornir.plugins.tasks.networking.
netconf_capabilities
(task: nornir.core.task.Task) → nornir.core.task.Result¶ Gather Netconf capabilities from device
Examples
Simple example:
> nr.run(task=netconf_capabilities)
Returns: - result (
list
): list with the capabilities of the host
Return type: Result object with the following attributes set - result (
-
nornir.plugins.tasks.networking.
netconf_edit_config
(task: nornir.core.task.Task, config: str, target: str = 'running') → nornir.core.task.Result¶ Edit configuration of device using Netconf
Parameters: - config – Configuration snippet to apply
- target – Target configuration store
Examples
Simple example:
> nr.run(task=netconf_edit_config, config=desired_config)
-
nornir.plugins.tasks.networking.
netconf_get
(task: nornir.core.task.Task, path: str = '', filter_type: str = 'xpath') → nornir.core.task.Result¶ Get information over Netconf from device
Parameters: - path – Subtree or xpath to filter
- filter_type – Type of filtering to use, ‘xpath’ or ‘subtree’
Examples
Simple example:
> nr.run(task=netconf_get)
Passing options using
xpath
:> query = "/devices/device" > nr.run(task=netconf_get, > path=query) Passing options using ``subtree``:: > query = "<interfaces></interfaces>" > nr.run(task=netconf_get, > filter_type="subtree", > path=query)
Returns: - result (
str
): The collected data as an XML string
Return type: Result object with the following attributes set
-
nornir.plugins.tasks.networking.
netconf_get_config
(task: nornir.core.task.Task, source: str = 'running', path: str = '', filter_type: str = 'xpath') → nornir.core.task.Result¶ Get configuration over Netconf from device
Parameters: - source – Configuration store to collect from
- path – Subtree or xpath to filter
- filter_type – Type of filtering to use, ‘xpath’ or ‘subtree’
Examples
Simple example:
> nr.run(task=netconf_get_config)
Collect startup config:
> nr.run(task=netconf_get_config, source="startup")
Passing options using
xpath
:> xpath = /devices/device" > nr.run(task=netconf_get_config, > path=xpath)
Passing options using
subtree
:> xpath = /devices/device" > nr.run(task=netconf_get_config, > filter_type="subtree", > path=subtree)
Returns: - result (
str
): The collected data as an XML string
Return type: Result object with the following attributes set
-
nornir.plugins.tasks.networking.
netmiko_commit
(task: nornir.core.task.Task, **kwargs) → nornir.core.task.Result¶ Execute Netmiko commit method
Parameters: kwargs – Additional arguments to pass to method. Returns: - obj: nornir.core.task.Result:
- result (
str
): String showing the CLI output from the commit operation
- result (
-
nornir.plugins.tasks.networking.
netmiko_file_transfer
(task: nornir.core.task.Task, source_file: str, dest_file: str, **kwargs) → nornir.core.task.Result¶ Execute Netmiko file_transfer method
Parameters: - source_file – Source file.
- dest_file – Destination file.
- kwargs – Additional arguments to pass to file_transfer
Returns: - result (
bool
): file exists and MD5 is valid - changed (
bool
): the destination file was changed
Return type: Result object with the following attributes set
-
nornir.plugins.tasks.networking.
netmiko_send_command
(task: nornir.core.task.Task, command_string: str, use_timing: bool = False, enable: bool = False, **kwargs) → nornir.core.task.Result¶ Execute Netmiko send_command method (or send_command_timing)
Parameters: - 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: Result of the show command (generally a string, but depends on use of TextFSM).
Return type: Result object with the following attributes set
-
nornir.plugins.tasks.networking.
netmiko_send_config
(task: nornir.core.task.Task, config_commands: Optional[List[str]] = None, config_file: Optional[str] = None, **kwargs) → nornir.core.task.Result¶ Execute Netmiko send_config_set method (or send_config_from_file)
Parameters: - config_commands – Commands to configure on the remote network device.
- config_file – File to read configuration commands from.
- kwargs – Additional arguments to pass to method.
Returns: - result (
str
): string showing the CLI from the configuration changes.
Return type: Result object with the following attributes set
-
nornir.plugins.tasks.networking.
netmiko_save_config
(task: nornir.core.task.Task, cmd: str = '', confirm: bool = False, confirm_response: str = '') → nornir.core.task.Result¶ Execute Netmiko save_config method
Parameters: - cmd (str, optional) – Command used to save the configuration.
- confirm (bool, optional) – Does device prompt for confirmation before executing save operation
- confirm_response (str, optional) – Response send to device when it prompts for confirmation
Returns: - obj: nornir.core.task.Result:
- result (
str
): String showing the CLI output from the save operation
- result (
-
nornir.plugins.tasks.networking.
tcp_ping
(task: nornir.core.task.Task, ports: List[int], timeout: int = 2, host: Optional[str] = None) → nornir.core.task.Result¶ Tests connection to a tcp port and tries to establish a three way handshake. To be used for network discovery or testing.
Parameters: - ports (list of int) – tcp ports to ping
- timeout (int, optional) – defaults to 2
- host (string, optional) – defaults to
hostname
Returns: - result (
dict
): Contains port numbers as keys with True/False as values
Return type: Result object with the following attributes set
-
nornir.plugins.tasks.networking.
napalm_ping
(task: nornir.core.task.Task, dest: str, source: Optional[str] = '', ttl: Optional[int] = 255, timeout: Optional[int] = 2, size: Optional[int] = 100, count: Optional[int] = 5, vrf: Optional[str] = None) → nornir.core.task.Result¶ Executes ping on the device and returns a dictionary with the result.
Parameters: - dest (str) –
- source (str, optional) –
- ttl (int, optional) –
- timeout (int, optional) –
- size (int, optional) –
- count (int, optional) –
- vrf (str, optional) –
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 (
dict
): list of dictionary with the result of the ping response. Output dictionary has one of following keys “success or error”
Return type: Result object with the following attributes set