NETCONF 102: Using Python to generate NETCONF API calls.

In this Learning Lab, you will learn the basics of how to leverage a NETCONF API in Python.

Objective

Completion Time: 45 minutes

  • Understand how to leverage a NETCONF API from Python
  • Explore different NETCONF implementations
  • Explore ways to parse and use XML returned for a NETCONF API

Prerequisites

You will want to make sure you have gone through the Coding 101 lab if you are unfamiliar with retrieving results from a RESTful service. Although this lab will not use a REST API, there are similar concepts that will be useful from this previous lab.

You will also want to make sure you have gone through the NETCONF 101 lab if you are unfamiliar with the NETCONF protocol.

In this lab, we are going to use Putty or an equivalent Terminal emulator and a simple Python script to connect to a device's NETCONF subsystem.

Also, this lab includes steps in the How to Setup Your Computer section to setup your development environment if needed.

Background

  • If you are unfamiliar with Python, make sure you complete the Coding 10X and Coding 20X learning lab exercises

  • This lab shall shall use Virtual Nexus Switches as a programmable device running in DevNet's VIRL Always On VIRL/NX-API Sandbox and CSR1000V running in the Device Programmability Always On Sandbox.

Access to a Device that Supports a NETCONF API

  • If you are working from your own machine, use the DevNet Sandbox Always-On VIRL/NX-OS Lab and the Device programmability Always-On VIRL/NX-OS Lab
    • The first environment has a small NX-OS network to which we can send NETCONF API calls
    • The second environment has a CSR1000V that we can also send NETCONF API calls to compare and contrast different NETCONF implementations

Python

  • To run the code samples, you need to have Python2 installed on your machine.

Virtual Environments

  • This lab uses a venv to run ncclient is 0.5 and avoid issues with existing Python environments.
  • Reference the section How to Set up Your Computer above to learn how to complete this step.

Development Libraries

  • If you are running on a Ubuntu based systems, we'll need the development version of Python, libxml2, and libxslt as well as a few others.
  • Reference the section How to Set up Your Computer above to learn how to complete this step.

NCClient Library

  • These codes samples use the NCClient to simplify making NETCONF API calls.
  • Note that currently, the most recent version of ncclient is 0.4.7. The latest development release in GitHub (0.5.0 at the time this lab was written) has support for Python3 as well as some useful classes that future learning labs shall leverage. The steps below show how to install this version.
  • Reference the section How to Set up Your Computer above to learn how to install the NETCONF Library on your own machine.

Clone Git Repo

  • Clone the NETCONF example code
    • This GitHub repository provides sample code that you can run for this learning lab
  • If you are working from your own computer, clone the git repository.
  • Reference the section How to Set up Your Computer above to see the steps required.

Step 1. Setting the stage for device programmability

We are going to use the NX-OSv device running 7.2(0)D1(1) in VIRL and a CSR1000V running 3.17 to interface with example NETCONF APIs in this lab. Before we begin, see the diagram below to set the stage for our device programmability exercises.

Per the diagram above, we shall use some example code to simulate an orchestrator that makes NETCONF API calls against a network device. See the next step to get deeper into NETCONF using Python!