Cisco NX-OS Network Automation using Python User Manual

June 5, 2024
Cisco

Cisco NX-OS Network Automation using Python

Cisco NX-OS Network
Automation using Python-0product

Network Automation

  • Process of using software to automate network provisioning, testing, deployment and network management
  • To help maximize network efficiency and functionality
  • Networks are complex and bulky in nature
  • Manual operations – more delays
  • Automation makes the networks more agile and responsive to changes
  • Benefits:
  • Improved operational efficiency
  • Reduced errors

Network Automation Architecture

Cisco NX-OS Network Automation using
Python-1

Network Programmability

Cisco NX-OS Network Automation using
Python-2

  • It’s a set of tools to deploy, manage and troubleshoot a network device
  • Network engineer perspective – interacting with a device or group of devices
  • Software developer perspective – abstracting the network. Seeing the whole network as a single device and manipulating it with software

Benefits of Network Programmability

  • Reduced OPEX
  • Customization
  • Reduced human error
  • Operational flexibility
  • Increased opportunity for innovation

Application Programming Interface (API)

  • APIs are mechanisms used to communicate with applications and other software.
  • An API may perform different functions based on where they are located in the flow
  • Used to communicate with various components of the network through software
  • APIs are usually RESTful APIs

Representational State Transfer (REST) APIs

  • An API that uses REST is often referred to a RESTful API
  • RESTful APIs use Hypertext Transfer Protocol (HTTP) methods to gather and manipulate data.
HTTP Function Action
GET Read
POST Create
PATCH Update / Modify
PUT Update / Replace
DELETE Delete

HTTP Status Codes

HTTP STATUS

CODE

| RESULT| COMMON REASON
---|---|---
200| Ok| Using GET or POST to exchange data with

an API

201| Created| Creating resources by using a REST API call
400| Bad Request| Request failed due to client-side issue
401| Unauthorized| Client not authenticated to access site or

API call

403| Forbidden| Access not granted based on supplied

credentials

404| Not Found| Page at HTTP URL location does not exist

or is hidden

Netmiko Overview

  • Netmiko – Python library used extensively to interact with network devices
  • Multi-vendor library
  • Cisco IOS/IOS-XE, NX-OS, firewalls, etc.
  • Extended support of Paramiko library’s SSH functionality
  • Going into configuration modes
  • Sending commands
  • Retrieving outputs
  • Taking care of yes/no prompts

NAPALM Overview

  • NAPALM – Network automation and programmability abstraction layer with multi-vendor support
  • Provides functions that allows:
  • Configuration operations (commit or rollback)
  • Retrieve state data from network devices
  • Contains methods to establish connection to network devices
  • Can work in conjunction with automation tools – Ansible
  • Has support for various network OS:
  • IOS, IOS-XR, NX-OS, JunOS, EOS, etc.
NAPALM Operations
  • Replace – Allows users to replace the existing running configuration with an entirely new configuration.
  • Merge – Allows users to merge configuration changes from a file to the running configuration on the device.
  • Compare – Compare the newly proposed configuration with the existing one. Only applies to replace operation and not for merge operation.
  • Discard – Resets the merge configuration file to an empty file. Thus, not allowing the new configuration to be applied on the device.
  • Commit – Commits the proposed configuration to the network device. In other words, used to deploy a staged configuration.
  • Rollback – Rollback (revert back) the running configuration to the saved configured prior to the last commit.

Templating with Jinja2

  • Jinja is a modern templating language for Python – Modelled after Django templates
  • Allows user to easily interact with Python program
  • Use data to quickly generate dynamic content
  • Benefits:
  • Template inheritance
  • Optimal just-in-time compilation
  • Easy debuggability
  • Configurable syntax
  • Commonly used with web frameworks such as Flask
  • Configuration management tools – Ansible, Nornir, etc.

Delimiters

Cisco NX-OS Network Automation using
Python-Nornir Overview

  • Python based automation framework
  • Manage network and host inventory and provide common framework to write plugins for the network devices and hosts
  • Requires minimum Python version 3.6.2
  • Multi-threaded – Defaults to 20 worker threads
  • Initialized using config file – references couple other files
  • Host inventory file
  • Group file
  • All these files are written in YAML format

Nornir Advantages

  • Python or Golang (Gornir)
  • Reuse existing libraries – napalm, netmiko
  • Quick host filtering based on any attribute or combination of attributes
  • Very fast due to use of threads
  • Can be used to build highly flexible and extensible automation tools using Flask, Django, etc.
  • Automatically performs caching and closes open connections

Extra Resources and References

Cisco Press News

Network Programmability and Automation Fundamentals [Learn more] CCNP and CCIE Security Core SCOR 350-701 Official Cert Guide
https://www.ciscopress.com/store/ccnp-and-ccie-security-core-scor-350-701 -official-cert-9780135971970

Cisco DevNet Professional DEVCOR 350-901 Study Guide
https://www.ciscopress.com/store/cisco-devnet-professional-devcor-350-901 -study-guide-9780137500048

Other useful resources:
Interview with Vinit Jain, Cisco’s Top Events Contributor
https://community.cisco.com/t5/networking-documents/interview-with-vinit- jain-cisco-s-top-events-contributor/ta-p/3156059
Vinit’s publications
http://www.ciscopress.com/authors/bio/255ee209-1418-4938-9a42-d3bece2b46c6

Read User Manual Online (PDF format)

Loading......

Download This Manual (PDF format)

Download this manual  >>

Cisco User Manuals

Related Manuals