Netmiko integration

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, visit the Netmiko PyPI or Netmiko docs pages.

Itential Automation Gateway (IAG) 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 IAG.

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 IAG UI or by a separate application via the IAG API. Functions are executed on the node on which the AG server is running.

Endpoint arguments

For external inventory, Netmiko endpoints in IAG require three 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 IAG is running on.

Example:

1host="192.168.0.1"
2host="CSR-MIAMI-01"
3host="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:

1connection_options = {
2 "device_type": "cisco_ios",
3 "host": "192.168.0.1",
4 "port": 22,
5 "username": "admin",
6 "password": "VerySecurePassword",
7 # ...
8}

Common device types

The device_type is supplied via the device_type parameter in connection_options.

See the following links for details on Netmiko support of vendor platforms and device types:

Example:

1Alcatel|Nokia SROS: "nokia_sros",
2Arista EOS: "arista_eos",
3Cisco IOS: "cisco_ios",
4Cisco IOSXR: "cisco_xr",
5Cisco NXOS: "cisco_nxos",
6Juniper 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 IAG UI or by a separate application via the IAG API. Functions are executed on the node on which the AG server is running.

Endpoint arguments

For native inventory, Netmiko endpoints in IAG require at least two distinct arguments to interact with native devices: a host and router commands/configs.

Host

The host is the native Netmiko device name.

Example:

1host="cisco_device"

Command string

The command_string is executed on the remote device.

Example:

1"command_string": "show version"
2"command_string": "show interfaces"

Config commands

Multiple configuration commands are sent to the device.

Example:

1"config_commands": [
2"hostname ROUTER1",
3"interface Ethernet 1/1",
4"description ROUTER1 Uplink"
5]

The minimum requirements to connect to native Netmiko devices are host, command_string, and config_commands. For other variables, refer to the Netmiko documentation.

Example:

1{
2 "cmd_verify": true,
3 "command_string": "show version",
4 "delay_factor": 0,
5 "expect_string": "string",
6 "host": "cisco_device",
7 "max_loops": 0,
8 "normalize": true,
9 "strip_command": true,
10 "strip_prompt": true,
11 "textfsm_template": "string",
12 "ttp_template": "string",
13 "use_genie": true,
14 "use_textfsm": true,
15 "use_ttp": true
16}

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:

1commands = [
2 "show version",
3 "show interfaces"
4]
5
6config = [
7 "enable",
8 "terminal length 0",
9 "interface Ethernet1/1",
10 " no switchport",
11 " ip address 192.168.1.1/24",
12 " mtu 9216",
13 " end",
14 "copy running-configuration startup-configuration"
15]