- 29 Mar 2024
-
DarkLight
-
PDF
Netmiko
- Updated on 29 Mar 2024
-
DarkLight
-
PDF
Netmiko is a multi-vendor library to simplify Paramiko SSH connections primarily to network devices. It is maintained by Kirk Byers and built on top of the Paramiko library. Network engineers and developers can use Netmiko to interact with a wide range of devices over SSH. Most audits, commands, or configurations can be pushed or retrieved with nothing but connection and authentication details. However, should a more advanced connectivity configuration be required (custom timeouts, retries, etc), Netmiko also supports additional parameters based upon its underlying Paramiko library.
For more information on Netmiko, please visit the Netmiko PyPi or Netmiko Docs pages.
Automation Gateway (AG) contains a Netmiko Execution Engine that supports pulling or pushing of arbitrary commands or configurations via the send_command
and send_config
endpoints.
Netmiko version 3.0 is the minimum version supported by Automation Gateway.
External Inventory
Netmiko does not have any explicit notion of inventory systems or files. Instead, it accepts a set of connection options which it uses to connect at runtime (host, port, authentication details, etc).
Execution
Netmiko functions are executed by issuing a POST
request to the appropriate endpoint, e.g. /api/v2.0/netmiko/send_{command|config}
. Executing a function can be done using the Automation Gateway UI or by a separate application via Automation Gateway API. Functions are executed on the node on which the AG server is running.
Endpoint Arguments
For external inventory, Netmiko endpoints in Automation Gateway require three (3) distinct arguments to interact with remote devices: a host, connection options, and router commands/configs.
Host
The host
is either an IP address or a hostname which can be resolved via DNS on the server that Automation Gateway is running on.
Example
host="192.168.0.1"
host="CSR-MIAMI-01"
host="CSR-MIAMI-01.domain.com"
Connection Options
The connection_options
is a dictionary which can map directly to Netmiko's ConnectHandler arguments, both in required parameters and parameter types such as port=int()
. Because host
is a top level argument, it is excluded in this dictionary and will be overwritten if included.
Example
connection_options = {
"device_type": "cisco_ios",
"host": "192.168.0.1",
"port": 22,
"username": "admin",
"password": "VerySecurePassword",
# ...
}
Common Device Types
The device_type
is supplied via the device_type
parameter in connection_options
.
See the links below for details regarding Netmiko support of vendor platforms and device types:
Example
Alcatel|Nokia SROS: "nokia_sros",
Arista EOS: "arista_eos",
Cisco IOS: "cisco_ios",
Cisco IOSXR: "cisco_xr",
Cisco NXOS: "cisco_nxos",
Juniper Junos: "juniper_junos"
Native Inventory
Execute native inventory by providing a host and command_string.
Execution
Netmiko functions are executed by issuing a POST
request to the appropriate endpoint, e.g. /api/v2.0/netmiko/send_{command|config_set}/execute
. Executing a function can be done using the Automation Gateway UI or by a separate application via Automation Gateway API. Functions are executed on the node on which the AG server is running.
Endpoint Arguments
For native inventory, Netmiko endpoints in Automation Gateway require at least two (2) distinct arguments to interact with native devices: a host and router commands/configs.
Host
The host
is the native Netmiko device name.
Example
host="cisco_device"
Command String
The command_string
is executed on the remote device.
Example
“command_string”: “show version”
“command_string”: “show interfaces”
Config Commands
Multiple configuration commands are sent to the device.
Example
“config_commands”: [
“hostname ROUTER1”,
“interface Ethernet 1/1”,
“description ROUTER1 Uplink”
]
The minimum requirments used to connect to native Netmiko devices are host
and command_string
and config_commands
. For other variables, please refer to the Netmiko documentation.
Example
{
"cmd_verify": true,
"command_string": "show version",
"delay_factor": 0,
"expect_string": "string",
"host": "cisco_device",
"max_loops": 0,
"normalize": true,
"strip_command": true,
"strip_prompt": true,
"textfsm_template": "string",
"ttp_template": "string",
"use_genie": true,
"use_textfsm": true,
"use_ttp": true
}
Router Commands and Config
Any environment-specific commands or configurations can be supplied transactionally (one command/config line per API call) or in a batch (performance may vary; see the Script Execution Engine guide for a better alternative for large command and configuration sets or prebuilt scripts).
Example
commands = [
"show version",
"show interfaces"
]
config = [
"enable",
"terminal length 0",
"interface Ethernet1/1",
" no switchport",
" ip address 192.168.1.1/24",
" mtu 9216",
" end",
"copy running-configuration startup-configuration"
]