Diniz Martins

Dec 28, 20201 min

Napalm | Network Automation

Napalm is a vendor neutral, cross-platform open source project that provides a unified API to network devices, is written in Python and already works with the most popular automation frameworks.

You don't have to use an existing automation framework to automate with Napalm. Since it's an open source library you could just integrate it with your own Python application.

NAPALM supports several methods to connect to the devices, to manipulate configurations or to retrieve data:

  • Arista EOS;

  • Cisco IOS;

  • Cisco IOS-XR;

  • Cisco NX-OS;

  • Juniper JunOS.

You can select the driver you need by doing the following:

>>> from napalm import get_network_driver
 
>>> get_network_driver('eos')
 
<class napalm.eos.eos.EOSDriver at 0x10ebad6d0>
 
>>> get_network_driver('iosxr')
 
<class napalm.iosxr.iosxr.IOSXRDriver at 0x10ec90050>
 
>>> get_network_driver('junos')
 
<class napalm.junos.junos.JunOSDriver at 0x10f8f61f0>
 
>>> get_network_driver('nxos')
 
<class napalm.nxos.nxos.NXOSDriver at 0x10f9304c8>
 
>>> get_network_driver('ios')
 
<class napalm.ios.ios.IOSDriver at 0x10f9b0738>

Installation:

pip install napalm

Open the python on your machine:

root@DRM:/home/STENGE# python3
 
Python 3.8.5 (default, Jul 28 2020, 12:59:40)
 
[GCC 9.3.0] on linux
 
Type "help", "copyright", "credits" or "license" for more information.
 
>>>

Start by importing the NAPALM module into Python:

from napalm import get_network_driver

You can select the driver you need by doing the following:

driver = get_network_driver("ios")

Create the python code using the IOS-XE always on sandbox information:

device = driver ('ip-address', 'your-loggin', 'your-password')

Next, we open a connection the device and pass the 'get_interfaces' command:

device.open()
 
device.get_interfaces()

The output will come all messed up - we can make the output more readable, by importing 'json' and printing this in 'json format':

import json
 
print(json.dumps(device.get_interfaces(), sort_keys=True, indent=4))

Finally, we close the connection. It is advised to issue use the 'close' to disconnect our session from the device:

device.close()

    1670
    5