Connections¶
NAPALM¶
-
class
nornir.plugins.connections.napalm.
Napalm
¶ This plugin connects to the device using the NAPALM driver and sets the relevant connection.
- Inventory:
- extras: passed as it is to the napalm driver
-
close
() → None¶ Close the connection with the device
-
open
(hostname: Optional[str], username: Optional[str], password: Optional[str], port: Optional[int], platform: Optional[str], extras: Optional[Dict[str, Any]] = None, configuration: Optional[nornir.core.configuration.Config] = None) → None¶ Connect to the device and populate the attribute
connection
with the underlying connection
Netmiko¶
-
class
nornir.plugins.connections.netmiko.
Netmiko
¶ This plugin connects to the device using the Netmiko driver and sets the relevant connection.
- Inventory:
- extras: maps to argument passed to
ConnectHandler
.
-
close
() → None¶ Close the connection with the device
-
open
(hostname: Optional[str], username: Optional[str], password: Optional[str], port: Optional[int], platform: Optional[str], extras: Optional[Dict[str, Any]] = None, configuration: Optional[nornir.core.configuration.Config] = None) → None¶ Connect to the device and populate the attribute
connection
with the underlying connection
Paramiko¶
-
class
nornir.plugins.connections.paramiko.
Paramiko
¶ This plugin connects to the device with paramiko to the device and sets the relevant connection.
- Inventory:
- extras: maps to argument passed to
ConnectHandler
.
-
close
() → None¶ Close the connection with the device
-
open
(hostname: Optional[str], username: Optional[str], password: Optional[str], port: Optional[int], platform: Optional[str], extras: Optional[Dict[str, Any]] = None, configuration: Optional[nornir.core.configuration.Config] = None) → None¶ Connect to the device and populate the attribute
connection
with the underlying connection
Netconf¶
-
class
nornir.plugins.connections.netconf.
Netconf
¶ This plugin connects to the device via NETCONF using ncclient library.
- Inventory:
- extras: See here
Example on how to configure a device to use netconfig without using an ssh agent and without verifying the keys:
--- nc_device: hostname: 192.168.16.20 username: admin password: admin port: 2022 connection_options: netconf: extras: allow_agent: False hostkey_verify: False
Then it can be used like:
>>> from nornir import InitNornir >>> from nornir.core.task import Result, Task >>> >>> nr = InitNornir( >>> inventory={ >>> "options": { >>> "hosts": { >>> "rtr00": { >>> "hostname": "localhost", >>> "username": "admin", >>> "password": "admin", >>> "port": 65030, >>> "platform": "whatever", >>> "connection_options": { >>> "netconf": {"extras": {"hostkey_verify": False}} >>> }, >>> } >>> } >>> } >>> } >>>) >>> >>> >>> def netconf_code(task: Task) -> Result: >>> manager = task.host.get_connection("netconf", task.nornir.config) >>> >>> # get running config and system state >>> print(manager.get()) >>> >>> # get only hostname >>> print(manager.get(filter=("xpath", "/sys:system/sys:hostname"))) >>> >>> # get candidate config >>> print(manager.get_config("candidate")) >>> >>> # lock >>> print(manager.lock("candidate")) >>> >>> # edit configuration >>> res = manager.edit_config( >>> "candidate", >>> "<sys:system><sys:hostname>asd</sys:hostname></sys:system>", >>> default_operation="merge", >>> ) >>> print(res) >>> >>> print(manager.commit()) >>> >>> # unlock >>> print(manager.unlock("candidate")) >>> >>> return Result(result="ok", host=task.host) >>> >>> >>> nr.run(task=netconf_code)
-
close
() → None¶ Close the connection with the device
-
open
(hostname: Optional[str], username: Optional[str], password: Optional[str], port: Optional[int], platform: Optional[str], extras: Optional[Dict[str, Any]] = None, configuration: Optional[nornir.core.configuration.Config] = None) → None¶ Connect to the device and populate the attribute
connection
with the underlying connection