Read blog
De-risk your SD-WAN rollout with network digital twin technology.
read more

API - Part 2 - Settings & Snapshots

The IP Fabric webinar covering Application Programming Interface (API) and its capabilities continuing with modifying settings and manipulating snapshots in part 2.

Transcript

So let's get back to our our functions, and let's see what we have, prepared for for this webinar. So it will be go again to the file where we have all the functions created. So we have the token request, refresh token, get data, which we have just used. And here is the basic list of the functions. So to give you an idea about what we're gonna do right now, let's go to the IP fabric first.

In the IP fabric, there's a lot of settings you can apply to your snapshots. So it starts as IP addresses or a subnets that you can exclude or include from discovery. It also starts with the information that you wanna provide as seed entry point for your discovery. And there's all other other settings that you can do. You can change the snapshot settings, SSI, and telnet settings.

We have the API information in the 3.5 0 version. Config management, you can do certificate changes, SNMP, etcetera. There's a lot of ways how you can change your settings just through the API. So it's completely flexible system that you can operate through the API. That's very important.

So now let's get back to our functions. And the first we're gonna do, we will be changing the seed. The seed is extremely important for any discovery. If you don't provide any seed information, the discovery starts automatically from its default gateway, if it's the first discovery. If it's not the first discovery, it will try to use previously discovered devices as a seed point automatically.

Okay? Playing with the seed and IP filter options is extremely useful when you wanna target minor snapshot to a different locations or for different specific subnets and you wanna change it on the go. So let's let's go ahead and let's play with the functions. So first is gonna be the simple get seed information. Right now, we have the seed empty.

So we can see and put a sometimes you see it like 10 10 10 10, whatever. We save that. So the get seed information is a very simple function. We only calling, the get request towards the settings and seed in the API. Here we are just checking if the response is okay.

If the response is okay, we print the text response, which will be the list of the IP addresses that are currently in the seed. So let's try that. We go to the console, and we call it the get seed the get seed function. The what we need to input is a server and the headers. And the response is, there's 1 IP address sitting in the seat right now, which we can confirm it agree.

Now we might be wanting to update the scene information, which can be extremely useful when we want to, for example, create a minor snapshot with just group of devices, in the in the IP fabric. And, what I would recommend to do, if you wanna just focus strictly on some group devices, put those devices into the seat, make sure you discover those, and put those devices into the IP, include list as well. So you will narrow down the scope automatically to only those IP addresses that are in the seat. So let's update this information. And first, let's have a quick, let's have a quick look on the functions themselves.

So the first is the update seed. For the update seed, we will use the post request, which will only update the seed information. So if there's any other remaining CRM addresses, it will only add more to that. Then there's another way how you can update a seed, and it's you can rewrite it completely with the put request. The put request will completely rewrite the data with the new information.

So let's play with that. In our, in our settings, we can modify the seed information with the following seed, phase 2. I will create it's a simple list of IP addresses, which I which I will use as a payload for the update seed request. So update seeds. And for the server, it's gonna be the same, the headers, and the page seats 2.

And we get a response that the seed was updated with those 3 IP addresses. Now let's go to seed again to see if it's changed. And we see that it actually did. So we have one IP address at the at the end and 3 more IP addresses. Now let's try to do the same with the rewrite sheet.

So we're gonna do rewrite server headers, and we will use the same payload. So we see that the seed information was modified. Let's see what we get. I'm gonna again call to get seed function, and you you can see that it changed because with the rewrite seed, we removed the last IP completely. Now let's have a look at how we can get all other additional settings from IP Fabric.

For getting the settings information, we have, again, created a simple get request towards API b one settings. It will get us all the information about how the epifabric is set up with all the data. So let's call it and see on our own. I'm gonna go call to get settings. And again, we need to define a server and the headers, and this is the information we have.

If we do, let's say, g equals get settings, server and the headers, we can play with the response so we can see what are that or how the data looks like when they're encoded into the JSON. And when they are in the JSON, we can ask for keys. So we can see the keys. We have credentials, privileges, and we have the networks as well. So if we just just want to know what networks are included or excluded from discovery when we start a snapshot, we can ask this way.

We can, of course, verify the same in IP fabric GUI, which usually don't do when you're playing with API, but we can check. So the system is telling us that we have this IP address excluded, and we include everything. So we go to the settings, advanced, and here it is, the exact same information. So what I want to do right now is to update the seed with only 2 devices, update the include list only with the same two devices, and I want to start a minor snapshot through the API. So the devices selected are these 2 devices with these 2 IP addresses.

So I'm gonna take those IPs and place them to the seat as well. You need to use a mask. So the payload for changing the seed IP addresses will be this one. And we want to rewrite it completely because we wanna get rid all the of all the information we have in the seat right now. So we're gonna call the seat.

And we're gonna rewrite it. And we wanna rewrite it with the actual payseed 1. Okay. When we get seed, we get the exact information. And now what I wanna do is to change the settings of the epifabric.

And now let's have a quick look at the function again. There's one important thing I wanna show you. So when we get into settings, we are using a get request which is just a request for information from the API. Here's the different quite a different function. It just get the settings and it will show you or write a response.

If the response is okay, it will show you just the networks, which we can use later on. It's just a slight modification of the get settings. Then look at the update settings. I mean, spot the difference. There is a different type of request.

This is not get or post or or put. This is a patch request. With a patch request, what we do, we only modify what we have on the API. The good thing about this is that we don't need to send to the API settings all the information that are in the settings. We just need to send what do we wanna modify.

Because if we have a quick look at the JSON payload for the patch request, it can look like in a way. So there's boundaries, safe config, bg limit, network settings, resolving name, scanner, trace route, etcetera. With the batch request, we don't need to define all this information, in the JSON payload. We just need to use maybe the subset of information we may need to modify. In this case, we will modify the networks.

So we will go back to our settings. And what I will do, I will use just this payload to patch the settings we have in the IP fabric. So to get the list of the IP addresses that are included and excluded in the settings, I will use the function get settings net to see. And this is this is what I see. The exclude is this list and the include we include everything.

Now I'm gonna define the settings for changing the the payload for changing the settings, And I'm gonna change the settings. And we see it was, modified successfully. And let's see for let's see. We see. We don't exclude anything right now, and we include only these 2 IP addresses for the next discovery.

So now let's get, let's get to the to starting the snapshot via API. And first, the function I created for observing the snapshots, over the API is to get snapshot. With the get snapshot, we simply get the number of snapshots that are right now in the in the IB fabric, and, we can see all the details on our own. So let's have a look. I'm gonna call to get snapshots with the server and headers.

A simple response, there are right now 9 available snapshots. So right now I wanna see what else I have in response. And this is a lot of information, so maybe just have a look at the keys in the JSON. Sorry. Oh, I forgot.

The response we have is not a dictionary. It's a list. So let's have a look at the first available snapshot. Okay. And here is the information.

Here we have the ID. This is the name, exactly the one that we have in our GUI. The running false, that's important. When we once we start a snapshot, we're gonna call the function again to see if there are any running snapshots. And especially when you are creating a snapshot that's gonna take longer than a couple of minutes, you wanna make sure once you initiate a snapshot that there's no other snapshot running at the moment because it can delay your snapshot initiation.

So let's start a snapshot. The snapshot, initiation or starting the snapshot is very easy, like everything else with IP fabric. You send a simple post request with no payload, just a header and the API endpoint, and it will automatically start a snapshot with the global settings that you have applied. So let's start a snapshot. Start a snapshot, server, headers.

Let's see what we get. I'm gonna, assign it. I'm gonna, create a barbell and assign the response so I can see what we have in the response when we start a snapshot. Let's call it a t, and let's start. So we have started the snapshot successfully.

What we get is just the message from the function. We can go to the GUI. Let's see on our own. Right. So we have started snapshot.

We have 2 IP addresses remaining, and nothing else is gonna be discovered because we have just placed 2 IP addresses into the seat and into the include list as well. So right now I'm gonna call get snapshot again, and we see that the number increased. That's very important. And I'm gonna call the or I'm gonna ask, what is the last snapshot again? So last snapshot right right now, it's running, and we should be seeing oh, stage discovering.

Okay. Running false or running true, that's very important because we know that the snapshot hasn't finished yet. We have the time of the stored, and we have the snapshot ID. So we can check again. State loaded.

Look false. Running false. It seems that our snapshot was created. We have 2 devices, and, yeah, that's it. Let's verify in the GUI.

Alright. It's true. Our snapshot was created within 36 seconds, and we have exactly 2 devices that we wanted to have in the snapshot.

Webinar notes

Episode Title:

API - Part 2 - Settings & Snapshots

Topics:

  • API
  • Network Automation
  • Network Assurance

Our hosts

Milan Zapletal

Milan Zapletal

Solution Architect