NAPALM Introduction
Network Programmability and AutomationPythonTutorials

NAPALM Network Automation Python: Introduction e Installation

Introduction

In this first article we are going to introduce a library for network automation called NAPALM. We are going to learn what NAPALM is, how it works and a little of its history. I want you to learn the installation process of this library and finally that we see the official documentation, which will serve as a guide and consultancy.

This is the first of multiple articles and videos, in which I want to teach you how you can implement Network Programmability and Automation with Python and the NAPALM library.

NOTE: Next video is in Spanish. English version coming very soon.

What is NAPALM?

NAPALM (Network Automation and Programmability Abstraction Layer with Multivendor support) is a Python library created and developed in 2015 by David Borroso and Elisa Jasinska. The goal was to unify device access, data collection, and configuration manipulation from multiple device vendors.

Through a unified API NAPALM allows to obtain data or manipulate configuration using the same functions, regardless of the operating system or vendor.

The official team that maintains NAPALM, also known as the “Core Developers“, have made developments for multiple vendors and operating systems. They currently support:

  • Arista EOS
  • Cisco IOS
  • Cisco IOS-XR
  • Cisco NX-OS
  • Juniper JunOS

In addition to the core drivers, napalm also supports community powered drivers. This community maintains its driver repositories on Github. Here you can find drivers for other manufacturers such as Huawei, Cumulus, HP, ArubaOS, among others.

NAPALM is a Free Software project. It is published and maintained on Github. Licensed under Apache 2.0

How does NAPALM work?

Let’s look at it this way, if you wanted to access different network devices with different operating systems through Python, we would probably have to use libraries developed for each operating system. It would be a tedious task to apply Network Programmability in these circumstances. To facilitate programming, NAPALM adds an abstraction layer. This layer allows us to use the same function to perform the same action on different operating systems.

How does it do the trick?

What NAPALM does is to hide this abstraction layer by unifying how we access a network device, regardless of who created it.

This is possible thanks to the introduction of the Network Driver concept. Every time we want to interact with a device, we only have to specify what operating system we are going to talk to and NAPALM will select the correct Network Driver. That is, select a library with all the functions related to that operating system. For example, as we can see on the video above, through the function get_network_drivers () and passing it the name of the Operating System, NAPALM prepares the correct library to talk to the device.

If we see it from another point of view, it is basically like having an API on top of other APIs.

NAPALM installation

To install NAPALM we need to meet the following requirements:

  • We will need a machine with the Linux Operating System. In my case I use the Ubuntu console for Windows 10.
  • We need to have Python3 installed.
  • PIP – Python Library Package Manager.
  • Python Virtual Environment (Optional)

Once these requirements are completed, we will proceed to install NAPALM with the command:

pip install napalm

Functionality Test

Let’s use the following code to test that the library is well installed and working correctly:

import napalm
def main():
    driver_ios = napalm.get_network_driver("ios")
    ios_router = driver_ios(
    hostname = "192.168.56.11",
    username = "codingnetworks",
    password = "codingnetworks"
    )
    print("Connecting to IOS Router...")
    ios_router.open()
    print("Checking IOS Router Connection Status:")
    print(ios_router.is_alive())
    ios_router.close()
    print("Test Completed")
if __name__ == "__main__":
    main()

Basically what we did in this code was, first, we imported the NAPALM library, to be able to use all the functions that are in it. We create the Main function, within which we will write our code. The next thing was to call the get_network_driver method passing the “ios” parameter, so that it specifically returns the class that contains the IOS operating system network driver. With this class we proceeded to create an object instance that will control the router by passing the IP, username and password of the router to which we want to connect as parameters.

With the object that we called “ios_router”, we invoke the open () method to initiate the connection to the router. To validate that the connection was successful, we called the is_alive () method which, as you will see in the next output, threw the answer True, indicating that there is a connection to the router.

Output when running the code:

NAPALM documentation

One of the main sources of documentation for NAPALM is the official documentation page of the project:

https://napalm.readthedocs.io

On this page you will find more details and tutorials on the installation process, programming examples. We can find the complete list of the functions developed until today to communicate and obtain information from the devices.

NAPALM can be integrated with automation platforms like Ansible or Salt. The documentation page provides information on this.

Also if you really like the project and would like to become a contributing programmer, at the end of the index you will find the documentation on how to contribute to the project with new functionalities or to solve found Bugs.

Conclusion

We have reached the end of our Introduction to NAPALM article. In the next one, this will get more interesting because we are going to work fully with routers with Cisco IOS and IOS-XR. The details and depth of practice will be seen in the Coding Networks YouTube channel videos. So subscribe, turn on notifications so you don’t miss out, and continue learning Network Programmability and Automation.

By Michael Alvarez