Network Automation with Python Libraries Netmiko, Napalm, and Nornir
The network automation market size is projected to grow from $3 billion in 2020 to about $9 billion over the next five years, so that’s about 25% compounded annual growth over that period. North America has the highest market share in the network automation market due to the early adoption of technology and the presence of solution providers.
The major drivers for the network automation market include increasing network traffic and cloud infrastructure leading to a significant transition in data centers, increasing adoption of connected devices, increasing adoption of automation technologies such as AI and machine learning, rising adoption of virtual and software-defined infrastructure, and the error-prone manual changes that often result in network downtime. Now, when we talk about network automation, the most often talked about topics are Coding and Python. You need to learn python, you need to learn Python, everyone needs to learn Python.
Are you going to become a Coder or a Developer?
Python Native Libraries
Let’s start with the native Python libraries that you must learn to code for network automation. Those are JSON, YAML, pyYAML, XMLTODICT, and PYANG. Let me unpack. JSON and Python go together like peanut butter and jelly. You can convert between JSON and Python dictionaries using JSON library loadS and dumpS methods where objects convert to dictionaries and arrays convert to lists. Python can handle YAML using the native YAML library, again YAML objects become Python dictionaries and Lists become Lists. Now, the XMLTODICT library allows you to treat XML like Python dictionaries so it is easier to work with XML data typically resulting from an API call made to a networking platform. You can also convert from dictionary back to XML as well by using the unparse method. PYANG library allows you to work with native YANG models and function as a YANG validator. Like, it can be used to transform YANG modules into other formats. So, beyond native Python libraries, you have API libraries. So, unlike libraries, you don’t need to know the methods within the libraries to put them to use, all you need to do is to call the appropriate API to get the job done.
Python API Libraries
Python comes bundled with various native API libraries such as the REST APIs. You can access REST APIs by using the REQUESTS Python library. NCCLIENT is another API library that works as the NETCONF client. NETMIKO is a third-party API library. REQUESTS library is essentially a full HTTP client, so it simplifies HTTP authentication, populating request headers and handling response headers. You can use this library to interface with RESTCONF and native REST APIs. NETMIKO is the API library that you’re going to use a lot if you work as a network automation engineer and there is no other way to automate your target platforms other than using the device’s CLI. It supports multiple vendor platforms such as Cisco, Juniper, and Arista. All data that are sent or received using the NETMIKO library remains in cleartext.
Napalm and Nornir
Now, let’s move to the final piece of the Python automation toolchain and that is configuration management using third-party Python libraries. Yes, I am talking about NAPALM and NORNIR. You can think of NAPALM as a multi-vendor library that abstracts out the vendor-specific API details. It uses the existing backend libraries and interfaces such as NX-API, NETCONF, and even CLI. It can be used to perform various device configuration actions such as replace, merge, compare, commit and even rollback. It can also be integrated into other tools such as Ansible and NORNIR. Now, one thing that has been missing from the Python-based network automation solution, is a configuration management framework. This is where you enter NORNIR. NORNIR is the flask of network automation. It is Python native and can leverage other network automation libraries such as NAPALM or NETMIKO via the plugin framework. What NORNIR brings to the table is that it takes care of dealing with the inventory and manages the job of dispatching the tasks you want to run against your nodes and devices concurrently. The framework provides a very simple way to write plugins. NORNIR belongs in the same category as Ansible and Salt inventory because it supports inventory management and concurrency.
Let me summarize. If you are starting, just know that you don’t have to a developer, not just to get started but like ever. Python comes several native libraries such as JSON, YAML, and REQUESTS, and then there are three well-known third-party libraries and are NAPALM, NETMIKO, and NORNIR. These libraries allow you to lift your game from tinkering with automation to configuration management like you can do inventory management and concurrently provision hundreds of devices in a multi-threaded fashion.
How useful was this post?
Author:Muhammad Afaq Khan, CCIE #9070
5 (1) The network automation market size is projected to grow from $3 billion in 2020 to about $9 billion over the next five years, so that’s about 25% compounded annual growth over that period. North America has the highest market share in the network automation market due to the early adoption of technology and […]
0 (0) Network automation is the biggest trend in networking today and picking up even more steam as networking infrastructure becomes virtualized, software-defined, and cloud-based. If there was ever another driver needed for network automation to kick in high gear, employees working remotely due to coronavirus is it. As per Gartner, by 2023, 60% of […]
5 (1) In the last several articles, I made a case that as a network engineer, when you look back at 2020 say in three years, you will realize that it was the year that kicked the network automation into high gear. It is super critical to note that network automation isn’t about using network […]
5 (1) In this article, I am going to cover every bit of detail that you need to get started, to prepare and pass the Implementing DevOps Solutions and Practices Using Cisco Platforms or the Cisco DEVOPS 300-910 exam. You can take the DEVOPS exam and the DEVCOR 350-901 exam to earn your DevNet Professional […]
5 (1) In this article, I am going to cover every bit of detail that you need to get started, to prepare and pass the Automating and Programming Cisco Collaboration Solutions or the CLAUTO 300-835 exam. You can take the CLAUTO exam and the DEVCOR 350-901 exam to earn your DevNet Professional certification. Likewise, Automating […]
How useful was this post?