Now so far we have seen how we can use get requests to ultimately retrieve
information about
our devices. What we now want to do though is to actually make configuration
changes okay.
So if we want to be making configuration changes the types of methods we want
to look at are things
like a post request for creating something brand new or potentially we can just
create a put request
to update something. Now here is the difficulty in managing configurations with
Yang.
Remember when we happen to send a get request we got this information coming WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Remember when we happen to send a get request we got this information coming
back to us in this
Yang model type way. Well any similar sense when it comes to making
configurations we actually
have to send the data that we want to update the device with also in this Yang
based structure.
So this might present some difficulty because as you know you might be looking
at this in
gun roll. How do I begin building this configuration not like your regular
Cisco CLI but instead
as this weird and wonderful Yang type data. So there are different ways in WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
as this weird and wonderful Yang type data. So there are different ways in
which you can do this
task but quite embarrassingly I have to admit that even today it seems like the
best utility that we
have to do this is to actually use the old school CLI and what can you imagine
what is this all about.
Now now what I will say is we're not just using the CLI we're using the CLI in
conjunction with
some restcon for requests. So what on earth am I even blabbing about okay so
let's go with a fairly
simple example. Let's imagine we're going to configure a look back on our WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
simple example. Let's imagine we're going to configure a look back on our
device. Now a look back
is a form of interface after all. So what we could do is we could go and
consult the Yang model.
You know just as we did we went through Pi Yang and we could see all the
different keys.
So we could use Pi Yang and we can see the structures see which keys belong to
which try to fix
the indentation so on so forth but quite honestly this is a bit of a headache.
If we want to just
configure a look back with restcon let's first configure a look back on the
device to make sure one
actually exists. So what I'm going to first do is I will just log into the
machine itself and all WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
machine itself and all
I will do is say configure terminal and let's just say interface look back and
let's just go with
look back one two three okay and let's just add in things we would like to
configure so let's add
any description for example this is a test look back let's also add an IPv4
address also IP address
I'm just do one into one six eights I don't know one two three dot one and we
'll give it a slash
24 mask okay so pretty much let's imagine this is what we want to configure via
restcon but we just
don't know how to structure the data but the cool thing is we have this now WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
don't know how to structure the data but the cool thing is we have this now
configured on the device
with all the details that we need such as the description and an IPv4 address
so what I propose
we do is we now send a get request over restcon which will actually pull back
this information
and we can just see the structure that restcon returns this data and then
effectively we will use
this as a template which we can modify for creating lookbacks in the future
okay so let's go and
try this then okay so what I will do right now is I will copy over script
number two and I'll create WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
number two and I'll create
one called script4.py so if we just go and open this one up as we recall this
particular script
is going to return interface information modeled via the ietf style so let me
just delete this
portion right here and just get a JSON response back so let's save this clear
the screen and we'll run
script number four okay though because let's scroll on up now here is the thing
what I want to do
is I want to just target one particular interface but right now all I'm getting
back is the model data
for all of the interfaces this is no good for my template if I just want to WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
for all of the interfaces this is no good for my template if I just want to
make a modification to
one of them so what I will do is I will filter the actual data now notice here
we have this interface
key and inside of it is not actually a key this happens to be a list object now
the way we actually
target an element within the list via url and we're going to combine this
particular key and then
associate it with the actual interface that we want to return so to say for
example in my case here
we go down to this one here look back one two three what I can do here is this WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
we go down to this one here look back one two three what I can do here is this
I can grab that key
interface which is like I say what we see right here and now because we have a
list object I'm
going to use the equal sign and then just specify the name of the interface
that I want to actually
return so for example if I wanted to get gigabit ethernet one I would just copy
this paste you in save
this run the script again and now we just get the information for ethernet one
similarly if I
wanted to get the information for the look back which has got all of the
information that we are
interested in all I will do is change the interface to equal look back one two WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
interested in all I will do is change the interface to equal look back one two
three so if I save
this now clearly screen and run it this here is all of the information that we
wanted to configure
such as the description the IP address but the handy thing is we've got the
exact structure we need
in order to send off these types of requests so if I just happen to copy this
here and let me just
copy script four and I'll create one called script five dot py so what I'm
going to do is make some
modifications to this particular script under the headers let me just go and
create a little payloads WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
create a little payloads
and I'll say it's equal to and all I'm going to do is paste in the
configuration that we just saw
there okay so essentially we've just got this little dictionary with all of the
data so what I can do
here is let's maybe say I wanted to update the description as well as the
actual IP address let's
just change this to be updated so we know it's actually changed and maybe let's
make this
address to be 192168123.123 okay and maybe in fact let's give it a slash 32
mask so I've modified
this now what we're going to do here is if you recall when it comes to arrest WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
this now what we're going to do here is if you recall when it comes to arrest
apis we're going to have
particular headers we are sending a payload to the actual device so I want to
tell the device which
type of data I'm going to be sending also the header is going to be content
type is application
yang data JSON so what I'm actually specifying here in the URL is that I'm
targeting you very
particular resource I want to be targeting look back 123 but I want to be
sending this particular
payload along with my actual request now the problem is right now is my request WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
payload along with my actual request now the problem is right now is my request
currently happened
to be a get request but as it stands I actually want to update look back 123
with this information
so instead what I will do is I will change this to a put request to update and
right now here I will
just print out the response and what I need to do is to add one more thing to
the actual request
I'm making I'm going to also have to pass in the payload I'll be sending over
some JSON data
and that's going to be equal to the payload dictionary that I've just defined
above okay see this
right here we're now passing it in so if I save this and I run the script now WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
right here we're now passing it in so if I save this and I run the script now
we get a 204 this is
actually indicating that we have a success so if I now log into the device and
I do a show run
if I scroll all the way down to the look back look at this right here we can
see it has been
updated it now has the new IP address and it also has the new subnet mask and
again if I actually
just go back exit if I run script number four which actually retrieves the
information for that
particular look back indeed we can see here as part of a risk on request this
information has
clearly been updated so we'll see how to get data we'll see how to make WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
clearly been updated so we'll see how to get data we'll see how to make
configuration changes let's
imagine we wanted to delete this particular look back well what we'll do is
just copy script number 5
over create script number six let's open you in this case here we actually don
't need any headers
and we'll delete the payload so I can remove these two options from my actual
request and all I'm
going to do is I'm going to target this very particular interface look back 123
as pair the actual URL
remember the URL correlates to the resource and all I'm going to do this time WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
remember the URL correlates to the resource and all I'm going to do this time
is I'm going to send a
get request I'm going to use the HTTP delete method so if I happen to save this
I clear the screen
if I now run script number six I answer we have a 204 this indicates a success
so now if I log into
the machine one more time and I do a show run if I scroll on down notice look
back 123 is nowhere to
be found it actually has been deleted so I know Yang can certainly be pretty
confusing especially if
you're not familiar with it we have to understand how to configure payloads in
this particular structure
but if we just configure the information that we want via the CLI and then WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
but if we just configure the information that we want via the CLI and then
craft the necessary get
request with the correct URL then we do have a good template to ultimately send
off future payloads
and then make modifications