WEBVTT

1
00:00.000 --> 00:04.740
Well, we know how to retrieve information from our devices using netconf. Let's

2
00:04.740 --> 00:05.360
now begin

3
00:05.360 --> 00:10.240
modifying configurations with our edit config rpc's. So with that said, all I

4
00:10.240 --> 00:11.200
will do is copy the

5
00:11.200 --> 00:15.850
previous script and create one called script5.py. Let's open this up. All right

6
00:15.850 --> 00:16.720
, okay, so let's see

7
00:16.720 --> 00:20.710
what we're going to do here. So let's maybe go and see that we want to

8
00:20.710 --> 00:23.120
configure OSPF on our device.

9
00:23.120 --> 00:26.480
Here's the first thing I'll do. What I recommend is very, very similar to what

10
00:26.480 --> 00:27.280
we saw with

11
00:27.280 --> 00:32.650
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

11
00:27.280 --> 00:32.650
restconf is to first configure the configuration that you want via the CLI and

12
00:32.650 --> 00:33.040
then when

13
00:33.040 --> 00:37.060
you get requests to pull that information, once we've done that, we can use

14
00:37.060 --> 00:38.400
that as a template

15
00:38.400 --> 00:42.340
for what the configuration structure should actually look like. So what I will

16
00:42.340 --> 00:43.520
do here is go

17
00:43.520 --> 00:49.360
in to this device once again. Okay, so SSH admin and paste this in. Type in the

18
00:49.360 --> 00:50.240
password.

19
00:50.240 --> 00:54.400
All right, so let's do showrun section eIGRP. We can see we have this

20
00:54.400 --> 00:55.520
configuration for now. Let

21
00:55.520 --> 00:59.160
me just remove this. Okay, I don't want any other routing configuration apart

22
00:59.160 --> 01:00.160
from what I'm going to
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

22
00:59.160 --> 01:00.160
from what I'm going to

23
01:00.160 --> 01:04.250
configure right now. So I'm going to also check if I have any OSPF, which I don

24
01:04.250 --> 01:05.360
't, but I do actually

25
01:05.360 --> 01:10.400
have some bgp. So what I will do here is just remove this. So say no router bgp

26
01:10.400 --> 01:11.760
100. Not all I will

27
01:11.760 --> 01:16.800
do here is I will just say router OSPF1. I will add the router ID of all the

28
01:16.800 --> 01:17.760
ones and I'll just say

29
01:17.760 --> 01:24.660
network wanting to 168 1.0 and give it a slash 24 mask. Put an area 0 and let's

30
01:24.660 --> 01:25.920
also add another

31
01:25.920 --> 01:30.530
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

31
01:25.920 --> 01:30.530
network of hell. Let's just go with 2.0. Okay, so here is the thing what I will

32
01:30.530 --> 01:32.000
do here is I will go back

33
01:32.000 --> 01:36.410
to my little script here and all I will do is I'm just going to grab the native

34
01:36.410 --> 01:37.840
key and I run

35
01:37.840 --> 01:41.900
script 5. So like we say this is going to give me all the running configuration

36
01:41.900 --> 01:42.640
. What I want to do

37
01:42.640 --> 01:45.820
is I want to grab this router key, which is going to contain all the routing

38
01:45.820 --> 01:46.800
information. So all I

39
01:46.800 --> 01:51.040
will do here is just add forward slash router, save here, pull this green, add

40
01:51.040 --> 01:52.160
it up and run again.

41
01:52.160 --> 01:56.150
Okay, so if I just scroll on up and zoom out a little bit here is all the

42
01:56.150 --> 01:57.360
information. Now what I

43
01:57.360 --> 02:01.790
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

43
01:57.360 --> 02:01.790
want to do is this you're going to notice that the first tag is RPC reply and

44
02:01.790 --> 02:03.280
the bottom tag is also

45
02:03.280 --> 02:09.260
RPC reply. Within this we have a data tag and a closing data tag. What I'm

46
02:09.260 --> 02:10.720
going to do right now

47
02:10.720 --> 02:15.070
is I'm going to copy from the data tag at the bottom all the way to the data

48
02:15.070 --> 02:15.920
tag at the top.

49
02:15.920 --> 02:20.720
Let's grab this, copy here and let me go in right here. Let me just create a

50
02:20.720 --> 02:21.680
little variable called

51
02:21.680 --> 02:25.570
OSPFconfig and again we'll have a multiline strings while I'll have my three

52
02:25.570 --> 02:26.640
quotation marks and

53
02:26.640 --> 02:29.760
I'll just paste in what we just saw there and let me just zoom out a little bit

54
02:29.760 --> 02:30.880
so we can see this.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

54
02:29.760 --> 02:30.880
so we can see this.

55
02:30.880 --> 02:34.800
Now first thing is first what I want to do here is to make some modifications.

56
02:34.800 --> 02:35.680
The first thing to do

57
02:35.680 --> 02:39.440
is because we're going to make a configuration change I actually want to change

58
02:39.440 --> 02:40.960
the data tags to be

59
02:40.960 --> 02:45.770
config tags so that's the first thing I'll do here. Now the first config tag I

60
02:45.770 --> 02:47.120
'm going to add the name

61
02:47.120 --> 02:50.600
space information that you actually will recall here. Here's information I got

62
02:50.600 --> 02:52.320
back here XMLNS

63
02:52.320 --> 02:56.880
all this. Let's grab all of this right here and I'm going to add that within

64
02:56.880 --> 02:58.240
the first config tag

65
02:58.240 --> 03:02.670
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

65
02:58.240 --> 03:02.670
like this. Now this here is actually a valid payload that I could send to my

66
03:02.670 --> 03:03.840
target device and it

67
03:03.840 --> 03:07.110
would understand what I'm trying to actually configure. Now right now the

68
03:07.110 --> 03:08.560
configurations are already

69
03:08.560 --> 03:11.940
on the box but what I can do is actually remove them. Now the first thing to

70
03:11.940 --> 03:12.880
state here is that there

71
03:12.880 --> 03:17.340
actually are different operations we can have with our edit config RPC. So the

72
03:17.340 --> 03:18.480
first thing we can do

73
03:18.480 --> 03:22.380
is select to merge our configurations quite simply what we'll do here is we'll

74
03:22.380 --> 03:23.360
leave whatever

75
03:23.360 --> 03:27.160
configurations are already on the box and we'll just merge in these new

76
03:27.160 --> 03:29.120
configurations I able just

77
03:29.120 --> 03:33.050
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

77
03:29.120 --> 03:33.050
add these new configurations to what is already existing. So imagine let's just

78
03:33.050 --> 03:33.680
maybe say

79
03:34.240 --> 03:40.670
already on the device we had a network statement of 192 168 3.0 with the slash

80
03:40.670 --> 03:43.120
24 mask in area 0k.

81
03:43.120 --> 03:47.330
Well if I happen to send this payload which adds 192 let me just zoom in a

82
03:47.330 --> 03:48.800
little bit. If I were to

83
03:48.800 --> 03:54.170
add this payload which adds this network as well as this network any merge

84
03:54.170 --> 03:55.440
operation and like a

85
03:55.440 --> 04:00.530
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

85
03:55.440 --> 04:00.530
say it would leave the existing network already on the box of 192 168 3.0 but

86
04:00.530 --> 04:01.760
it would just add this

87
04:01.760 --> 04:06.740
network as well as this network to the device. Now that is the first operation

88
04:06.740 --> 04:07.440
we can do it

89
04:07.440 --> 04:11.980
emerge but we can also do is a replace operation. Now essentially what a

90
04:11.980 --> 04:14.000
replace operation will do

91
04:14.000 --> 04:18.710
it will replace what is already on the box with whatever it is we have right

92
04:18.710 --> 04:19.600
here so this is what

93
04:19.600 --> 04:23.800
is known as a declarative configuration. So to use the same example if already

94
04:23.800 --> 04:24.720
on the box we had

95
04:24.720 --> 04:30.420
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

95
04:24.720 --> 04:30.420
an OSPF configuration with the network statement of 192 168 3.0 slash 24 mask

96
04:30.420 --> 04:31.120
in area 0.

97
04:31.120 --> 04:36.630
If I happen to send this particular payload in an operation replace will the

98
04:36.630 --> 04:38.000
only OSPF configuration

99
04:38.000 --> 04:41.040
that would be on the device after the operation would be these ones this would

100
04:41.040 --> 04:42.320
replace whatever was

101
04:42.320 --> 04:47.230
already there so that means an effect this one here would ultimately be deleted

102
04:47.230 --> 04:48.240
from the box.

103
04:48.240 --> 04:51.800
Let me show you what I mean okay. So the first thing I will do here is in my

104
04:51.800 --> 04:53.680
router key I will say

105
04:53.680 --> 04:58.590
operation equals and then in quotation marks I will say merge okay. Now

106
04:58.590 --> 04:59.600
remember right now on

107
04:59.600 --> 05:03.820
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

107
04:59.600 --> 05:03.820
the device these two networks are already there if I go back in fact just log

108
05:03.820 --> 05:04.960
in do a show run

109
05:04.960 --> 05:09.590
section OSPF like I say these are already existing on the device. If I happen

110
05:09.590 --> 05:10.640
to change these

111
05:10.640 --> 05:17.900
configurations let's add 3.0 and 4.0 and we choose to merge the configurations

112
05:17.900 --> 05:18.800
we will leave

113
05:18.800 --> 05:23.310
these existing statements on the device and just simply add two more as per

114
05:23.310 --> 05:24.240
this payload the

115
05:24.240 --> 05:27.880
three network and the four network. Now in order to do this what I'm going to

116
05:27.880 --> 05:28.960
have to do is to also

117
05:28.960 --> 05:34.720
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

117
05:28.960 --> 05:34.720
specify a different RPC descent so instead of a get config I will send an edit

118
05:34.720 --> 05:35.760
config and again

119
05:35.760 --> 05:39.240
if I want to target the candidate data story could but in my case here I will

120
05:39.240 --> 05:40.720
just target the running.

121
05:40.720 --> 05:44.640
In this case here we're not going to specify a particular filter what I want to

122
05:44.640 --> 05:45.760
do is I want to tell

123
05:45.760 --> 05:50.440
what config I want to be sending so the actual config here is labeled OSPF_con

124
05:50.440 --> 05:51.520
fig so that is what

125
05:51.520 --> 05:55.020
I will actually send here and in this case here let me just print out the

126
05:55.020 --> 05:56.720
result regularly okay

127
05:56.720 --> 05:59.670
and the last thing I need to do actually is I need to change the source the

128
05:59.670 --> 06:00.640
keyword here is going to
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

128
05:59.670 --> 06:00.640
keyword here is going to

129
06:00.640 --> 06:04.650
be target when we make a configuration change so with that now done let's just

130
06:04.650 --> 06:06.000
run the script notice

131
06:06.000 --> 06:09.740
in the output we actually get this okay response as we can see right there so

132
06:09.740 --> 06:10.560
if we log into the

133
06:10.560 --> 06:16.030
device again and I do my show run section OSPF look at this right here the

134
06:16.030 --> 06:17.520
already pre existing

135
06:17.520 --> 06:21.880
configurations are left unaffected and all we've done is merge in two more

136
06:21.880 --> 06:23.200
network statements

137
06:23.200 --> 06:26.880
now here's the thing if I happen to maybe make a modification and I change this

138
06:26.880 --> 06:27.920
to be an operation

139
06:27.920 --> 06:33.360
replace save this what we're effectively telling the device is whatever OSPF
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

139
06:27.920 --> 06:33.360
replace save this what we're effectively telling the device is whatever OSPF

140
06:33.360 --> 06:34.800
configuration we have

141
06:34.800 --> 06:38.960
we want to replace it just with these particular configurations so in essence

142
06:38.960 --> 06:39.840
we should actually

143
06:39.840 --> 06:44.700
delete the other two networks okay so let's try this out arrow up try again

144
06:44.700 --> 06:45.600
once again we get the

145
06:45.600 --> 06:50.900
okay response let's log in let's do show run section OSPF check this out right

146
06:50.900 --> 06:52.640
here see that we have

147
06:52.640 --> 06:56.620
fully replaced the OSPF configuration with simply what we've defined in this

148
06:56.620 --> 06:57.840
particular payload

149
06:57.840 --> 07:02.310
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

149
06:57.840 --> 07:02.310
anything that is not defined has been deleted by inference so again let's maybe

150
07:02.310 --> 07:03.440
see I remove one of

151
07:03.440 --> 07:06.960
these network statements right here okay just delete this and let's maybe

152
07:06.960 --> 07:09.280
change this to be 192 168

153
07:09.280 --> 07:14.720
let's go with 12.0 the only OSPF configuration we have is this particular

154
07:14.720 --> 07:16.000
network and we want to

155
07:16.000 --> 07:21.140
replace all the current OSPF with all of this config okay so let's save this

156
07:21.140 --> 07:22.480
exit back out arrow

157
07:22.480 --> 07:27.440
up try again we get an okay statement let's log back in and again just do show

158
07:27.440 --> 07:29.200
run section OSPF

159
07:29.200 --> 07:33.310
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

159
07:29.200 --> 07:33.310
we have fully replaced the configuration that was on the box with this new

160
07:33.310 --> 07:34.480
config okay see that

161
07:34.480 --> 07:38.210
now there also is another operation we can do and that is just to explicitly

162
07:38.210 --> 07:39.040
delete something

163
07:39.040 --> 07:43.760
so what I could do is if I go back to my configuration let's just log in let's

164
07:43.760 --> 07:45.440
just configure more OSPF

165
07:45.440 --> 07:51.920
information let's just say network 10 000 slash 24 mask let's put it in area 51

166
07:51.920 --> 07:52.720
if I want to just

167
07:52.720 --> 07:56.720
particularly delete this piece of the configuration what I could do is I could

168
07:56.720 --> 07:57.840
specify an operation

169
07:57.840 --> 08:01.160
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

169
07:57.840 --> 08:01.160
delete but I don't want to use this particular tag because that is going to

170
08:01.160 --> 08:02.240
effectively delete

171
08:02.240 --> 08:06.170
everything with thinnestags see this the only thing in my case here I want to

172
08:06.170 --> 08:07.680
be deleting is this

173
08:07.680 --> 08:11.700
network statements all I do is specify the tag that I want to be targeting so

174
08:11.700 --> 08:13.040
this one here so let's

175
08:13.040 --> 08:17.500
go in here and I'll remove operation of place right here in this time I'll go

176
08:17.500 --> 08:18.800
to the network level

177
08:18.800 --> 08:24.840
and I'll just say operation equals delete so if I save this and it exit out and

178
08:24.840 --> 08:26.000
I read on a script

179
08:26.000 --> 08:30.960
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

179
08:26.000 --> 08:30.960
once again we get that okay response let's log back in if I do show run section

180
08:30.960 --> 08:32.320
OSPF as we can see

181
08:32.320 --> 08:35.840
here we have explicit deleted just that network statement.
