Overview of NAPALM and Its Purpose#

NAPALM aims to streamline network automation workflows by offering a unified interface for managing network devices. Its key objectives include:

  • Abstracting vendor-specific complexities: NAPALM abstracts the differences between vendor-specific configurations, allowing network engineers to write automation scripts that work across different platforms.

  • Simplifying network management: By providing a consistent set of methods for device configuration and management, NAPALM simplifies network automation tasks such as configuration changes, state monitoring, and data retrieval.

  • Promoting interoperability: NAPALM encourages interoperability between different vendor devices, making it easier to integrate heterogeneous network environments.

Supported Network Operating Systems#

NAPALM is used to interact with various hardware networking vendors. It works as an API on top of other APIs, adding another level of abstraction. Here are some of the supported operating systems:

  • Arista EOS

  • Cisco IOS

  • Cisco IOS-XR

  • Cisco NX-OS

  • Juniper JunOS

Installation and Configuration Steps#

To get started with NAPALM, you need to install the library and configure your development environment. You can install NAPALM using pip, the Python package manager:

pip install napalm

Once installed, you can import the NAPALM module in your Python scripts and start using its features.

NAPALM CLI#

NAPALM installation includes a CLI tool for direct usage. You can access the help menu with:

napalm --help

Here’s an example of using NAPALM CLI to ping a device:

napalm --user admin --password cisco --vendor ios 192.168.10.10 call ping --method-kwargs "destination='192.168.10.10'"

IOS Prerequisites#

For IOS devices, Napalm uses the Netmiko library for interaction. Here are some prerequisites:

  • Enable the archive functionality for auto-rollback.

  • Enable SCP for file transfers.

See more details on the Napalm Docs

Working with Different Vendor Platforms using NAPALM#

NAPALM supports a wide range of networking vendors, including Cisco, Juniper, Arista, and many others. It provides a consistent interface for interacting with devices from these vendors, allowing you to write automation scripts that work across multiple platforms.

Here’s an example of how to connect to a Cisco router using NAPALM:

import napalm

# Create a NAPALM driver for Cisco IOS
driver = napalm.get_network_driver("ios")

# Connect to the device
device = driver(hostname="172.16.10.12", username="admin", password="cisco")
device.open()

# Perform operations on the device

# Close the connection
device.close()

Retrieving Device Information and Configuration Data#

NAPALM provides methods for retrieving various types of information from network devices, including device details, interfaces, routing tables, and configuration data. Here’s how you can retrieve the device information from a device:

import napalm
import json

# Create a NAPALM driver for Cisco IOS
driver = napalm.get_network_driver("ios")

# Connect to the device
device = driver(hostname="172.16.10.12", username="admin", password="cisco")
device.open()

# Retrieve the running configuration
device_facts = device.get_facts()

# Print the running configuration
print(json.dumps(device_facts, indent=4))

# Close the connection
device.close()
{
    "uptime": 3360.0,
    "vendor": "Cisco",
    "os_version": "3700 Software (C3725-ADVENTERPRISEK9-M), Version 12.4(15)T14, RELEASE SOFTWARE (fc2)",
    "serial_number": "FTX0945W0MY",
    "model": "3725",
    "hostname": "R1",
    "fqdn": "R1.tech.com",
    "interface_list": [
        "FastEthernet0/0",
        "FastEthernet0/1",
        "Loopback0",
        "Loopback2",
        "Loopback3",
        "Loopback4"
    ]
}

Applying Configuration Changes and Managing Network State#

In network management, applying configuration changes and ensuring the stability of network states are essential tasks. NAPALM simplifies these operations by providing a unified interface for managing configurations across various network devices. Let’s explore how NAPALM can be utilized to configure network interfaces and maintain network states effectively.

Example 1: Configuring Interface Description#

This example demonstrates how to configure the description for an interface on a Cisco router using NAPALM:

import napalm

# Create a NAPALM driver for Cisco IOS
driver = napalm.get_network_driver("ios")

# Connect to the device
device = driver(hostname="172.16.10.11", username="admin", password="cisco")
device.open()

# Load the configuration changes
config = "interface GigabitEthernet0/3\ndescription Test Interface"
device.load_merge_candidate(config=config)

# Apply the configuration changes
device.commit_config()

# Close the connection
device.close()

In this example, we establish a connection to the Cisco router and load a configuration change to set the description for interface GigabitEthernet0/3. Subsequently, the changes are committed to ensure they take effect.

Example 2: Managing Network Configurations#

The following example demonstrates how to manage network configurations by loading a candidate configuration from a file, comparing it with the running configuration, and applying the changes if necessary:

import napalm

# Create a NAPALM driver for Cisco IOS
driver = napalm.get_network_driver("ios")

# Connect to the device
device = driver("172.16.10.11", "admin", "cisco")
device.open()

# Load the candidate configuration from a file
device.load_merge_candidate(filename="acl.cfg")

# Compare the candidate configuration with the running configuration
difference = device.compare_config()

# Check for differences and apply the changes if necessary
if len(difference) > 0:
    print("Configuration changes detected:")
    print(difference)
    device.commit_config()
else:
    print("No changes required.")
    device.discard_config()

# Close the connection
device.close()

In this example, we load a candidate configuration from a file named acl.cfg and compare it with the running configuration. If there are differences, the changes are applied, and if not, the candidate configuration is discarded.

These examples demonstrate the versatility of NAPALM in configuring network devices and managing network states efficiently.

Integrating NAPALM with Other Automation Tools and Frameworks#

NAPALM integrates seamlessly with other automation tools and frameworks, allowing you to build comprehensive automation workflows. You can use NAPALM alongside tools like Ansible, SaltStack, and Puppet to automate network provisioning, configuration management, and monitoring tasks.

Configuration support Method#

NAPALM offers various methods for configuration support, such as replace, merge, commit confirm, compare config, atomic changes, and rollback. You can find more details in the official docs.