Cisco CCNP Enterprise 300-435 ENAUTO – Network Device Programmability
January 30, 2023

12. 38 ncclient to Configure IOX-XE Devcies

In three, two we have to learn understand about NZ Client that uses NETCONF. And I’m going to show you examples related to how we can go and configure the Is XE devices before doing the lab. Let’s learn more about NC client. And let me show you the URL where you’ll get most of the information related to NC Client. Now here you can see the link and this is Clint read the docs IO. NZ client is a Python library for netconflint. It aims to offer an intuitive API that sensibly maps the XML encoded nature of Netcon for Python construct and making the network management descript easier. So what this NZ client will do that it will go and support the operation and capability defined in this RFC Request pipelining asynchronous RPC keeping XML out. We’ll see that how we can take XML as an input that we are going to see in the lab. And then this is extensible correct.

Now there are some other useful links as well. And one of the important link here is that developer Cisco. com. If you go to that particular link, you’ll find a little bit history about NCL NC Client. You can see that integration of Python library to NETCONF clients. Correct. Now this NZ client was developed by CCR Bushan and it is maintained by these guys. If you want to reach out if you have any specific questions, you can check their Twitter handle as well. Docs are at this location and then Pipe location here we can go and check these links. So if you go to Pipe Pi and here you can see that how you can go and do the installation because I am using Pip Three. So I can go and use pip three install NC client. And let me show you if I have my automation tool here and if it is running, so what I will do that. In the next section I will show you the labs related to NZ client to do the configuration to iOS XE devices.

13. 39 Lab ncclient IOS-XE

Let us do the lab related to NZ client. And obviously with respect to iOS XE, I want to show you my topology diagram as well before doing the lab. So here you can see the topology diagram is very straightforward. I have one iOS XE device connected with this switch in this common land network where I have my automation tool. Now, what I want to do before doing anything, I just wanted to do the Pip three install NC client, correct? Now, since I have already done the installation here, you can see that already my NC client is installed. Then I have few codes that I put inside my CSR folder and in this code I have few program just for demo purpose. So for example, I want to run this program with respect to my device list that is there in device info. So I can go and show you that device info in my inventory. Device inventory I have two iOS XC, although I’m going to use only one because in our network we have only one device connected. So here you can see that I have iOS device where I am using port number 830 that is used for net conf SSH.

This is the IP and the username and the password. Now, from device perspective, what are the things you should do inside the CSI device that we have? So let me quickly show you that you should run the net conf that I have enabled the net conf SSH and net confiant I have enabled the SSH as well. And then I have done the configuration for line VTi where transport input is all and then finally the user name so someone can connect to this device. Even you can go and do the testing as well. Before running the actual program, just check the SSH connectivity that are not in your CSL device. Once everything is there, I should check the ability with the iOS device and if it is working fine, then we can go and run our program. So here you can see I have 12345 program set. Number one is to check the capability, what type of NETCONF supported models we have in the devices. So what I can do first of all, let me show you the code. Code is very easy and straightforward. So what we are doing, we are logging to the device as per the device list, we know that the file is iOS Xi. So we are logging to the device and then we are checking the capability. Okay, the important thing here is that we should check the functions from where we are calling the we are importing the input in this particular program. So we have the device info already in the same folder we are importing the iOS XE. Then we have NZ client from where we are importing the manager. Now this manager connect will connect to the device as M and this M here will give the capability correct.

Let me show you this in the Nano file as well. So this is actually colorful and here we can understand more. So with Manager connect as M and then you can see that we can go and write the capability because here you can see that for capability in M server capabilities we are printing the capability. It’s a very easy and straightforward program we have. If I go and run this you can see that what output will get. Obviously we will get all the capabilities that we have related to NETCONF inside the devices, inside that CSI device. Correct? Good, likewise we can go and check the other program will go and give you the interface detail. Again, let me show you the program as well, just for the reference. So here you can see that you are going to take the input from the filter IET. Of interface XML. Read that then we’ll go and connect to the device where the device is imported from iOS XE obviously the device info and from there we are extracting iOS XE one. Then we have the manager and then we have the XML to dictionary because we are using the XML. So we need some dictionary, we need actually some library who can convert XML to dictionary format. Correct? Great.

So we’ll do the connection and then we have the net conf reply. So here you can see that the program is quite structured and again we are using the net conf protocol to get the results as well. Correct. So let me go down and then it will go and print the output for the interface related output in this format. So interface detail, what’s the name, the type, the physical address, the unicorn in and out packets. Great. So let’s run this program and then we have two underscore in details as the program name. So here you can see that the interface is gig one, the Mac addresses this and you can see the packet input and packet output. Even the counters are increasing. That means we are taking the live counters from the interface. So now if I go to the interface to this particular router go to the router and you can see whenever we are logged in we can see that the user connection is there. What I want, I want to check the input and the output. So here you can see that you should have the packets input and output et cetera include input and the same thing we can go and verify from the output here. So 4018 is the input packet and here also you find some big counters 40, 87.

Now it’s packet is increasing so that’s why we have increased number. Great. So you can see that how easily we can go and add multiple things in our program. Now here it is showing only one but a list can be big. Simply we need to go there and add more and more interfaces and then we’ll get more and more results. Then I have the third program as well that will give you the interface stat again. If I go and show you the program, it’s very straightforward where we are collecting the stats related to gig one, the unicorn packet, and then again we have the interface detail and we are collecting the output in this particular format so I can go and run this program as well. And this program will again give you the interface stats of one of the interface.

Again, we are not restricted for one interface. We can add more interfaces and then we’ll get the result for more and more interfaces. Let’s quickly go and run the last program that is config interface. This is actually interesting where you want to send the configuration and you want to do the configuration. So before doing this, before running this program I just wanted to show you the configuration what I want that one of the interface that is get to I want to send some configuration so configure by NETCONF say today and the IP is I can change the IPC 172 1110 and then the subnet mask is okay, then they configure the payload and it will go and do the configuration with that particular device. Obviously this device that is imported from the device info iOS XC one and the interface is gig two. Now before doing this configuration we can go and verify that what is the configuration over interface gig two and here we can see that gig to having IP ten to 55 to 55 to 55 one because this is not physically connected to showing down that’s okay, let’s go and do the configuration via the Python program. So what I can do here I can go to Python three and then four underscore config interface PY.

Now here you can see that it is connecting to the device. You can see connected by netcon by VTi and transaction is there. And now if you go and see the IP interface brief still we can see the transaction is not successful seems because I can see this let me see that if I have saved that program yes it is saved and still I can see that the configuration is not completed. So do we have any error? Let’s see so we are sending the payload, the IP address the Net mask to that particular interface that interface is nothing but gitu. All right so it should do the configuration as per our result and I can’t see this show IP interface prefestibility showing the old configuration. Here you can see that the description is configured by NETCONF today the IP is this let’s see that inside the program. If I go inside the program you can see that the Net conflict is from conflict IETF interface XML and let me show that what is that? So if you go here and if you check this config ietfxml.

So here we have this format which is telling that use this particular format for the execution but the value here can see that is coming from this particular place. Now, if any problem in this particular configuration it will not work. I will do one thing. Let me quickly change this to say for example 123-1212 and let me run this program one more time. I can see that the gate to my device is not able to change this configuration and can check the configuration is still this is not there. All right, to make this program work, I have done a small change here. So if I go here and show the interface you can see that it’s twelve, 1212, one and then I can go to this interface default interface kick two and then I can go to the program where I have my program, I will do certain change. So instead of 1212 I can give some other IP just for our verification and rest of the things are okay. So I can give say 16, 1616 dot, anything save and then we can go and execute this program.

Once you execute this program and if you go and check the output so we can check the output and here you can see it got configured. So remember when value was there, an interface was down then it was not able to put those values means override those values. But if we don’t have any configuration it went there and it has done the execution. All right, so we have seen good amount of examples related to iOS XE, NCC client or NC client and net conf integration with Python. So we have checked the capabilities, the interface detail, the other interface detail and then finally we have configured the device as well. Now, I have taken the example only for one interface or few of the steps that we have done but same is true that you can take n number of interfaces and you can push N number of configuration script as well. So if we are able to do with few of interfaces, few of the configuration you can do and you can have to add more and more configuration to run exclude these programs.

14. 40 3.3 Configure Device via RESTCONF API Python

Now we reach to three where we have to configure device using RESTCONF API utilizing Python Method request library. Now, what I have done that I have created two videos related to St van API with Python and you’ll find that it’s quite interesting and important as well that you can use the same trick that I have used. You can use the same type of code that I have used, I have taken help from GitHub and then you can do the automation, you can create the script for your organization as well that I have created. Now, not only these programs, these Python programs you can create and do the automation, but these programs will help you to do the troubleshooting as well in the future. So watch coming two videos and those videos are actually very informative. Again with relates to do the automation or do the scripting with respect to RESTCONF API, with respect to Ciscosive answers.

Leave a Reply

How It Works

img
Step 1. Choose Exam
on ExamLabs
Download IT Exams Questions & Answers
img
Step 2. Open Exam with
Avanset Exam Simulator
Press here to download VCE Exam Simulator that simulates real exam environment
img
Step 3. Study
& Pass
IT Exams Anywhere, Anytime!