Well, we know how to retrieve information from our devices using netconf. Let's
now begin
modifying configurations with our edit config rpc's. So with that said, all I
will do is copy the
previous script and create one called script5.py. Let's open this up. All right
, okay, so let's see
what we're going to do here. So let's maybe go and see that we want to
configure OSPF on our device.
Here's the first thing I'll do. What I recommend is very, very similar to what
we saw with
restconf is to first configure the configuration that you want via the CLI and WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
restconf is to first configure the configuration that you want via the CLI and
then when
you get requests to pull that information, once we've done that, we can use
that as a template
for what the configuration structure should actually look like. So what I will
do here is go
in to this device once again. Okay, so SSH admin and paste this in. Type in the
password.
All right, so let's do showrun section eIGRP. We can see we have this
configuration for now. Let
me just remove this. Okay, I don't want any other routing configuration apart
from what I'm going to WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
from what I'm going to
configure right now. So I'm going to also check if I have any OSPF, which I don
't, but I do actually
have some bgp. So what I will do here is just remove this. So say no router bgp
100. Not all I will
do here is I will just say router OSPF1. I will add the router ID of all the
ones and I'll just say
network wanting to 168 1.0 and give it a slash 24 mask. Put an area 0 and let's
also add another
network of hell. Let's just go with 2.0. Okay, so here is the thing what I will WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
network of hell. Let's just go with 2.0. Okay, so here is the thing what I will
do here is I will go back
to my little script here and all I will do is I'm just going to grab the native
key and I run
script 5. So like we say this is going to give me all the running configuration
. What I want to do
is I want to grab this router key, which is going to contain all the routing
information. So all I
will do here is just add forward slash router, save here, pull this green, add
it up and run again.
Okay, so if I just scroll on up and zoom out a little bit here is all the
information. Now what I
want to do is this you're going to notice that the first tag is RPC reply and WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
want to do is this you're going to notice that the first tag is RPC reply and
the bottom tag is also
RPC reply. Within this we have a data tag and a closing data tag. What I'm
going to do right now
is I'm going to copy from the data tag at the bottom all the way to the data
tag at the top.
Let's grab this, copy here and let me go in right here. Let me just create a
little variable called
OSPFconfig and again we'll have a multiline strings while I'll have my three
quotation marks and
I'll just paste in what we just saw there and let me just zoom out a little bit
so we can see this. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
so we can see this.
Now first thing is first what I want to do here is to make some modifications.
The first thing to do
is because we're going to make a configuration change I actually want to change
the data tags to be
config tags so that's the first thing I'll do here. Now the first config tag I
'm going to add the name
space information that you actually will recall here. Here's information I got
back here XMLNS
all this. Let's grab all of this right here and I'm going to add that within
the first config tag
like this. Now this here is actually a valid payload that I could send to my WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
like this. Now this here is actually a valid payload that I could send to my
target device and it
would understand what I'm trying to actually configure. Now right now the
configurations are already
on the box but what I can do is actually remove them. Now the first thing to
state here is that there
actually are different operations we can have with our edit config RPC. So the
first thing we can do
is select to merge our configurations quite simply what we'll do here is we'll
leave whatever
configurations are already on the box and we'll just merge in these new
configurations I able just
add these new configurations to what is already existing. So imagine let's just WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
add these new configurations to what is already existing. So imagine let's just
maybe say
already on the device we had a network statement of 192 168 3.0 with the slash
24 mask in area 0k.
Well if I happen to send this payload which adds 192 let me just zoom in a
little bit. If I were to
add this payload which adds this network as well as this network any merge
operation and like a
say it would leave the existing network already on the box of 192 168 3.0 but WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
say it would leave the existing network already on the box of 192 168 3.0 but
it would just add this
network as well as this network to the device. Now that is the first operation
we can do it
emerge but we can also do is a replace operation. Now essentially what a
replace operation will do
it will replace what is already on the box with whatever it is we have right
here so this is what
is known as a declarative configuration. So to use the same example if already
on the box we had
an OSPF configuration with the network statement of 192 168 3.0 slash 24 mask WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
an OSPF configuration with the network statement of 192 168 3.0 slash 24 mask
in area 0.
If I happen to send this particular payload in an operation replace will the
only OSPF configuration
that would be on the device after the operation would be these ones this would
replace whatever was
already there so that means an effect this one here would ultimately be deleted
from the box.
Let me show you what I mean okay. So the first thing I will do here is in my
router key I will say
operation equals and then in quotation marks I will say merge okay. Now
remember right now on
the device these two networks are already there if I go back in fact just log WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
the device these two networks are already there if I go back in fact just log
in do a show run
section OSPF like I say these are already existing on the device. If I happen
to change these
configurations let's add 3.0 and 4.0 and we choose to merge the configurations
we will leave
these existing statements on the device and just simply add two more as per
this payload the
three network and the four network. Now in order to do this what I'm going to
have to do is to also
specify a different RPC descent so instead of a get config I will send an edit WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
specify a different RPC descent so instead of a get config I will send an edit
config and again
if I want to target the candidate data story could but in my case here I will
just target the running.
In this case here we're not going to specify a particular filter what I want to
do is I want to tell
what config I want to be sending so the actual config here is labeled OSPF_con
fig so that is what
I will actually send here and in this case here let me just print out the
result regularly okay
and the last thing I need to do actually is I need to change the source the
keyword here is going to WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
keyword here is going to
be target when we make a configuration change so with that now done let's just
run the script notice
in the output we actually get this okay response as we can see right there so
if we log into the
device again and I do my show run section OSPF look at this right here the
already pre existing
configurations are left unaffected and all we've done is merge in two more
network statements
now here's the thing if I happen to maybe make a modification and I change this
to be an operation
replace save this what we're effectively telling the device is whatever OSPF WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
replace save this what we're effectively telling the device is whatever OSPF
configuration we have
we want to replace it just with these particular configurations so in essence
we should actually
delete the other two networks okay so let's try this out arrow up try again
once again we get the
okay response let's log in let's do show run section OSPF check this out right
here see that we have
fully replaced the OSPF configuration with simply what we've defined in this
particular payload
anything that is not defined has been deleted by inference so again let's maybe WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
anything that is not defined has been deleted by inference so again let's maybe
see I remove one of
these network statements right here okay just delete this and let's maybe
change this to be 192 168
let's go with 12.0 the only OSPF configuration we have is this particular
network and we want to
replace all the current OSPF with all of this config okay so let's save this
exit back out arrow
up try again we get an okay statement let's log back in and again just do show
run section OSPF
we have fully replaced the configuration that was on the box with this new WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
we have fully replaced the configuration that was on the box with this new
config okay see that
now there also is another operation we can do and that is just to explicitly
delete something
so what I could do is if I go back to my configuration let's just log in let's
just configure more OSPF
information let's just say network 10 000 slash 24 mask let's put it in area 51
if I want to just
particularly delete this piece of the configuration what I could do is I could
specify an operation
delete but I don't want to use this particular tag because that is going to WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
delete but I don't want to use this particular tag because that is going to
effectively delete
everything with thinnestags see this the only thing in my case here I want to
be deleting is this
network statements all I do is specify the tag that I want to be targeting so
this one here so let's
go in here and I'll remove operation of place right here in this time I'll go
to the network level
and I'll just say operation equals delete so if I save this and it exit out and
I read on a script
once again we get that okay response let's log back in if I do show run section WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
once again we get that okay response let's log back in if I do show run section
OSPF as we can see
here we have explicit deleted just that network statement.