publicly available NETCONF tools and clients make it
much easier to interact with a NETCONF server. One
popular NETCONF client is the Python 3 ncclient
library. Next, let’s use ncclient to explore the Cisco NX-
OS NETCONF interface.
Cisco NX-OS is the network operating system that
powers Cisco Nexus switches in data centers around the
world. Built on top of Linux, Cisco NX-OS, also known as
Open NX-OS, exposes the full power of Linux, with rich
programmable interfaces and a diverse set of automation
tools. The following examples use Cisco NX-OS version
9.2.3, ncclient version 0.6.7, and Python 3.7.4. You
enable NETCONF on Cisco NX-OS version 9.2.3 by
issuing the feature netconf command in configuration
mode. Much as with Cisco IOS XE, the NETCONF server
is running by default on TCP port 830 and uses the SSH
protocol as transport.
The manager module within the ncclient library
handles all NETCONF RPC connections between the
client and the server. By using the connect method
available with the manager module, it is very easy to
establish a connection to a NETCONF server. The
connect method takes as input parameters the
hostname or the IP address of the NETCONF server, the
port on which the server is running, the username and
password that are used to connect, and the
hostkey_verify parameter, which specifies whether the
script should look for hostkey verification information in
the ~/.ssh/known_hosts location on the server on which
the script is run. Example 12-12 shows a simple Python 3
script that retrieves the capabilities of the NETCONF
server and displays them to the console.
Example 12-12 Python Script to Retrieve and Print
NETCONF Capabilities
Click here to view code image