15. 41 Lab Task Integrating Python API –1
In this important section, I’m going to show you the lab. So let me show you that how you can perform the lab dusk integrating Python with API. All right, so I logged in or I shared my screen where I have the lab setup. Now here you can see that we have the network automation and this can easily be with help of genes three that already I have covered in my earlier videos, right? So let’s go and do the lab. What you can do here to perform the say for example, SDWAN related rest API. If you want to check the API doc, first of all here you can go and check the API docs and then you will get quite huge number of API documents that we have inside the SDWAN. Like that you will find the API doc for ACI, API dock for other products as well. Other Sdn products as well.
Now, while it is opening up, what I can do here is that I can go to the link. So here you can see that we have the Zhub where getting a started SDWAN APIs are there in Zhub. If you go and open this URL, you will find that you have complete codes as well. Now in this quote, what you want that you can go and check this stwand PY. If I go and open this here, you can see on your screen, although the font size is very small, but you can go and have a look. So we have complete script here and in this script we have certain requirements as well. So if you go ahead and check that how to use this script, you will find it. You will find it. That how you are going to use the script. And then you can utilize it.
16. 42 Lab Task Integrating Python API –2
Now I will show you how you can go and build your lab so python integration with the API. So for that I have the lab topology like this and then I have my network automation here. Now, before starting this, let me go and show you the configuration that we have that I want to use. And for that you can go and check the link here you can do the Google search getting started with Cisco’s API. And what I can do here that I can go and copy and paste this directly. So let me start this from here. I’m copying and pasting now please read it carefully. There are some requirements that we need to have. We need some sort of pip installed packages or some other requirements. So there’s one file called requirement TXT. You should go there and verify that. I’ll go here and create my program. Say ABC PY, I’ll paste that control o enter and control X. And if I want I can go and check this program.
So ABC PY here you can see that you need to import these functions and there are so many things. So let me again go back again. I have to show you at ABC by this is the program that you can go and refer once. All right, so now what we can do here is that we can check the options that we have and before checking the option, what it is telling that you go and set the environment variable. So you have to set it. Now I can go and give my v manage IP. So I have my v manage connected, then I can go and give the port number as it is. So you can go and give the port number. My username is the same and the password is different. Password is admin. Now once I have my username and password set, now again I can go and check the help. So you can go and verify the help. This time it will tell you that what options you have. Now if I’m looking for the network device list, I can go here and check the device list. Now the program will run and it will tell that what devices I have at the moment it is throwing an error, it is telling the site ID is not a key. So I will go here and check my program why this site ID is not working inside this sub function that is device list and the API used with the URL is the devices. Now I can go down here and items check the header. Now when we are talking about this API, before showing how to correct it, I’ll go and use the same API function.
So what it is telling that you can go here, let me make some space here. You can go here and you can use the API call devices. So this is the API I’m using and I can go and use the 8443 as well. All right, I’m getting some error that it is not giving the value that I’m looking for and you can see so this is the correct API, that is the data services, data service and device. Now once you get this output here you can see that you have the header information and then you have the data. Now this data that we have here so here you can see that we have the header and I should not use like this so let me go out and come back. How you’re going to pass this information is important because once we do for one of the function then we can easily do for other functions as well. So I have the header information like this and I am getting one error related to site ID.
So at this moment I’ll go and remove the site ID. Somehow the program is not able to read the site ID so I’ll go and remove the site ID first and the output here you can see that what will happen the header and then the for loop will run. So we have the output in the JSON format, whatever things means, whatever keywords that we are taking from here. So these are the keywords and you can go and put these keywords there in the program in the same format they will go and print it and since we are using the table tablet that’s the function table function so it will go and print in the nice table format. Okay, so how many functions I have here? 123456 how many entries I want to print so six entries here and 123456 entries here as well. This program is good, I can come out and now I can run this. So you will see now that we are getting the output in nice table format.
Now if you compare it, if I want to compare it this output, this output is also good informative but first of all it’s a bulk output and second thing is that it is not in the table format or it is not in good format like this. This output you can go and you can open your notepad and you can save here like this. Again, if you want to filter something we can go and filter but yeah, we’re getting nice output here now again we can go back to the help and what other things we have that we can go and explore. So now you can go and attach, you can do the detach of devices, you can attach the devices, you can have the template list, that’s the one thing. The second thing here is that suppose if you want to improve the program so we have copied the program and I want to add one of my API, correct? So for that how you can do it again you have to edit and you have to do manual work first.
So you have to create a program. Let me show you. That how you can do it. So, device list and the function I have starting from here. So I will go and copy this in my notepad or maybe in my sub line so let me open that so I open my editor and let me go down to here you can see that I can go and put now we should follow the indentation otherwise it will go and throw an error. So this time, instead of device list, if you want to get some, say, control info, control plane information. And for that, I have an API running here. You can see that I want control connection. Information for this particular device. Correct. Now, in the API, instead of device, what you can print. So you can go and give that information where I have my supply here, you can see. So the base URL is up. To here. And if you go and check the API that we are calling. So I can go and give this like this. So to use like this and seems that it is coming twice. All right, so this is a function. The output actually, I’m looking for now. We have to go and change this table entry. Now, just for the sake of simplicity, I’ll print only two. But likewise, you can go and print whatever you want. Right. So let me go and delete say host name and the device type. So what we’ll do that we want to get the data let’s take it a V device name is one and system IP.
So I’ll go and print only these two things now in header, you can give any name, but let me use the same here and then you have the System IP. So you want to print the next thing that will be the System. IP I’ll write to you. But the thing is that here in header we can give anything. But in the item you should give exactly whatever the keyword I have here, so I can go there and I can print it so now our program is ready. I can go here and copy program is control info. Let’s go here and I want to add it. Go and make some space add here it should have the correct indentation otherwise it will never work. So everything is the same line. And that’s why I am using the Sublime. So it will take this as it is now. Finally, if I scroll down, I need to add the function here.
So I can go here and add say CLI, add the command. And what is that? That is control info. Okay, so now we are good. I can save this. I can come out. And first of all we’ll check the help function. Now if any problem is there in help, it will go and tell. Oh, this line you have this problem here you can see the control is not defined. That’s the error it is throwing. Then we can go and check. So why this problem? Here you can see that click command and then the device list we started like this seems that I haven’t pasted that output here I can’t see okay, never mind. So we’ll go back to the place and I can go and copy this. I can paste here and let’s see CTRL info.
So that’s a problem actually we have should use underscore because it was not taking this as a whole. So let me quickly check that I should not do the duplication of the configuration. So I have one control info here and set sims so here it’s okay that you can go the underscore or the dash in between it will take. Let’s check. So now again we have put the code and now we are checking I can go back here and then we can put control info and now that particular block will run. So now it is retrieving the information and here you can see that we have successfully converted the API into the Python table format. So it’s telling you the device name your and the system name your. All right, so this is the way that we can go and perform the laptop.
17. 43 3.4 using Ansible configure IOS-XE
In section three four we have to learn understand that how we can use the skills of Ansible to configure our iOS Xi devices. Now before doing the lab and understanding the concept, let’s go and do the revision or quick review of how this Ansible work. What are the important concepts inside the Ansible at this point of time? We know that we have Ansible, we have Puppet and Chef. Ansible is something you can think as an agent list means you don’t need agents to install to the remote server from where you want to take the configuration or from where you want to do the interaction. Ansible is open source agent list, simple wide adoption. It is used for configuration management, orchestration and deployment. Now the use for Ansible is really huge and not only that Ansible is supporting Cisco devices but it is supporting a number of different vendors and devices. How ansible interacting. Here you can see in the diagram that you have the user, you have the Ansible. You can think that Ansible library that is termed as ansible controller. So inside the controller you have the Ansible CFG file you can go and create inventory playbook modules, correct? These modules are something that there are so many inbuilt module and if you know the coding you can create your models as well.
Now via SSH, obviously the username and password we can push the configuration, get the configuration and we can exclude certain commands. Now all these labs again with respect to iOS XE, we are going to see in upcoming video using Ansible what are the terms we have? So the terms that we need to learn are the playbook inventory, the YAML obviously the data model is YAML, the ginger to ad hoc commands, templates et cetera. Now when we go and do the lab we’ll find that we are going to run the Ansible playbook and then obviously we have our file, the file we are going to save or create as YML extension and then as per our inventory we are going to execute the playbooks, correct?
So you will see in the lab and that all these things will be very much clarified in the lab. In upcoming lab you’ll understand more and more. So here you can see that you have the Anzie Bell CFG file. This also I will show you that how this CFG looked like when we’ll do the lab. It is there in the Etsynsible Ansible configuration where you have the configuration related default setting and if you want to do certain things you can do that change but you should know that what changes you want to do. Likewise we are going to create our own inventory as well. So inventory of devices where I may have routers switches and then certain variables related to routers and switches. So this also you will see in the lab section we have so many inbuilt modules and we can write our own modules as well, correct. So here you can see the number of modules and increasing with release. Two four has something 465, two seven has 671. So these modules are getting increased. Now, if you want to simply execute the command, we have this ad hoc commands as well that we can go and run. But what we are going to do is we are going to run the playbook. Then we have the concept of playbook.
This is actually important because the playbook that we are going to execute, they have the YAML extension and we’ll see we have so many examples to understand. So we’ll go and check the contents of the playbook and once you run it, you’ll find the playbook has certain areas and then you have the task defined inside the playbook. It will run and it will give you the output. We have Ginger two templates as well. Now this Ginger two template further enhance the modeling capability including native concrete lets Ginger two templates have access to the ansible variables and implement many filters and tests. That’s the key actually. So we have the variable inside the ansible and to simplify the variables and call we are using Zenja two template. Okay. And again you can see the example here you have in the right hand side. All right, so these are the basics related to ansible and this slide you can think as a summary slide. So when you have the ansible program, you can see that you have the ansible, you can define the host. Obviously you have the ansible CFC file and then you can create your task inside the playbook. So you want to check the iOS interface configuration and number of YAML file or configurations I have that I can go and do it. We’ll see in the upcoming session.
So, how I break this ansible three four section is that first of all there is one video, that upcoming video where you will learn that how you can install these inside Sent OS. So you’ll go to the ansible main website where you can go and check the process to install it over various operating system. For example, you will see over sent to us. And in next recording I’ll show you the actual three dot four lab where I will run these playbooks with respect to iOS 60 inside the GNS three. Since both of the videos are informative. First one is that you can go and check other aspects as well other operating system as well. So you can go and install it. You will learn some basics about how to install it. And next obviously we’ll go and do it in the iOS XE device. So go and watch two videos, two upcoming lab videos. The second one is very much relevant to section three. Regard four.