• Diniz Martins

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()
23 views0 comments

Recent Posts

See All

FMC | Security Intelligence Blacklisting

As a first line of defense against malicious Internet content, the Firepower System includes the Security Intelligence feature, which allows you to immediately blacklist (block) connections based on t

AnyConnect | XML

The mostly used VPN software from Cisco is probably Cisco AnyConnect Secure Mobility Client and it is a pretty sharp tool. The simple view of client is really impressive and productive. Whenever I wan

Cisco Nexus NX-OS tips and tricks

The Cisco Nexus series switches are modular and fixed port network switches designed for the data center. Cisco Systems introduced the Nexus Series of switches on January 28, 2008. The first chassis i