WEBVTT

1
00:00.000 --> 00:03.930
So friends, now that we know how to send get requests and Python and we can

2
00:03.930 --> 00:07.000
ultimately work with the response in a programmatic manner,

3
00:07.000 --> 00:11.200
let's now target a network device that has been enabled for risk-conf.

4
00:11.200 --> 00:15.010
So one of the best utilities that you can use for automation and programm

5
00:15.010 --> 00:18.700
ability for testing and learning is to go to the Cisco DevNet sandbox.

6
00:18.700 --> 00:21.900
If I click this link here, make sure you have an account in login.

7
00:21.900 --> 00:24.400
Now what I will do is I will launch the sandbox.

8
00:24.400 --> 00:28.460
Now what I am going to do is I am going to search for Xe for Cisco iOS Xe and

9
00:28.460 --> 00:31.400
this one here, at least when I am recording this right now,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

9
00:28.460 --> 00:31.400
this one here, at least when I am recording this right now,

10
00:31.400 --> 00:32.400
this is the one that is available.

11
00:32.400 --> 00:38.110
Cisco iOS Xe on the cat 8kV always on, always on means that we don't have to

12
00:38.110 --> 00:38.900
reserve a spot.

13
00:38.900 --> 00:40.400
So this is really quite handy.

14
00:40.400 --> 00:43.400
So let's go and click this here to see the connection details.

15
00:43.400 --> 00:46.400
So we can see here to actually connect to the device.

16
00:46.400 --> 00:47.900
This is the public URL.

17
00:47.900 --> 00:53.100
We have the login username, the password and we can see the risk-conf port is 4

18
00:53.100 --> 00:53.900
443.

19
00:53.900 --> 00:57.400
So let's go and see how we can actually make a request then to what it will do.

20
00:57.400 --> 00:58.900
Let me just create a new directory here.

21
00:58.900 --> 01:01.010
If I do not know what, let's keep it on the same directory that is not as the
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

21
00:58.900 --> 01:01.010
If I do not know what, let's keep it on the same directory that is not as the

22
01:01.010 --> 01:01.400
matter.

23
01:01.400 --> 01:04.400
Let's create a script called script2.py.

24
01:04.400 --> 01:05.900
So let's open this up.

25
01:05.900 --> 01:09.400
So first things first, we are going to import the request library once again.

26
01:09.400 --> 01:10.900
There is no surprise right there.

27
01:10.900 --> 01:15.400
So let's go and define our headers in once again, new little dictionary.

28
01:15.400 --> 01:18.900
So this time the cable still will be except because it is an except header.

29
01:18.900 --> 01:21.900
But the corresponding value is a little bit different.

30
01:21.900 --> 01:26.400
As opposed to simply being application for word slash JSON,

31
01:26.400 --> 01:32.900
it's actually going to be application yang hyphen data plus JSON like so.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

31
01:26.400 --> 01:32.900
it's actually going to be application yang hyphen data plus JSON like so.

32
01:32.900 --> 01:37.030
This is because the data is going to be yang modeled and again formatted in

33
01:37.030 --> 01:37.400
JSON.

34
01:37.400 --> 01:39.900
This is what we're looking for from the server.

35
01:39.900 --> 01:42.900
So let's now define our URL.

36
01:42.900 --> 01:44.900
So let's go and grab the connection information.

37
01:44.900 --> 01:47.900
So we can see here the public URL, at least when I am recording this.

38
01:47.900 --> 01:50.400
At this time is this particular one right here.

39
01:50.400 --> 01:51.400
Let's copy it.

40
01:51.400 --> 01:53.900
And all I will do is I'll paste this in.

41
01:53.900 --> 01:56.900
I'll put it in quotation marks right here.

42
01:56.900 --> 01:59.900
And all I will do is I will add on at the start 80 to PS.

43
01:59.900 --> 02:01.900
Go on forward slash forward slash.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

43
01:59.900 --> 02:01.900
Go on forward slash forward slash.

44
02:01.900 --> 02:06.360
Now, crucially, we're going to be connecting over port 443 to default Rescon

45
02:06.360 --> 02:06.900
port.

46
02:06.900 --> 02:10.900
Now this part here might look a little bit strange.

47
02:10.900 --> 02:12.400
So let's just follow this.

48
02:12.400 --> 02:15.900
What I'm going to do here is I'm going to say forward slash Rescon.

49
02:15.900 --> 02:20.900
Forward slash data forward slash I ETF dash interfaces.

50
02:20.900 --> 02:22.900
Colon interfaces.

51
02:22.900 --> 02:24.400
Let me just zoom out a little bit.

52
02:24.400 --> 02:28.670
So as I mentioned in the opening, this part here is actually referenced in the

53
02:28.670 --> 02:29.400
Yang Tree.

54
02:29.400 --> 02:32.840
Now you may recall when we first talked about Yang in an earlier scale, we have
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

54
02:29.400 --> 02:32.840
Now you may recall when we first talked about Yang in an earlier scale, we have

55
02:32.840 --> 02:34.900
three different main styles of Yang Models.

56
02:34.900 --> 02:36.400
We have the I ETF Yang Models.

57
02:36.400 --> 02:37.400
This is an open standard.

58
02:37.400 --> 02:39.900
We also have open config Models.

59
02:39.900 --> 02:42.900
Once again, this is also open and vendor neutral.

60
02:42.900 --> 02:47.600
And then we also have the native Yang Models that are device or rather vendor

61
02:47.600 --> 02:48.400
specific.

62
02:48.400 --> 02:52.900
So Cisco specific Yang Models or Juniper specific Yang Models.

63
02:52.900 --> 02:57.950
The one I'm using here is a vendor neutral one, meaning that this particular

64
02:57.950 --> 03:00.900
request would work perfectly fine on a Cisco device.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

64
02:57.950 --> 03:00.900
request would work perfectly fine on a Cisco device.

65
03:00.900 --> 03:03.900
And it would also work perfectly fine on a Juniper device.

66
03:03.900 --> 03:07.410
And more importantly, the way the information we come back would be structured

67
03:07.410 --> 03:08.400
in the same style.

68
03:08.400 --> 03:09.400
So that's all we're doing here.

69
03:09.400 --> 03:13.080
In the upper specifying, we want a very particular resource. We want to see

70
03:13.080 --> 03:17.400
interface information modeled in the I ETF interfaces Yang style.

71
03:17.400 --> 03:20.170
And now what I will do is just pretty much as we saw before, I will create a

72
03:20.170 --> 03:22.400
little variable to hold my response.

73
03:22.400 --> 03:23.900
I will use the request library.

74
03:23.900 --> 03:25.900
I'm going to have a get request.

75
03:25.900 --> 03:28.900
And I'll just simply say the URL is equal to the URL I have to find above.

76
03:28.900 --> 03:32.400
I'll see the headers are equal to the headers I have to find above.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

76
03:28.900 --> 03:32.400
I'll see the headers are equal to the headers I have to find above.

77
03:32.400 --> 03:34.400
But this part here is also a bit different.

78
03:34.400 --> 03:36.400
The previous request that we did.

79
03:36.400 --> 03:39.470
We didn't actually have to configure any type of authentication. We didn't have

80
03:39.470 --> 03:41.400
to say a username a password that type of thing.

81
03:41.400 --> 03:45.880
So what I will do here in this case is I'm going to pass in the auth keyword of

82
03:45.880 --> 03:47.400
say auth is equal to.

83
03:47.400 --> 03:49.900
And I'm going to make this what is known as the Python tuple.

84
03:49.900 --> 03:51.900
So I'm going to have parentheses here.

85
03:51.900 --> 03:57.120
And now I will just pass in the user name, which if we go to the sandbox, the

86
03:57.120 --> 03:58.900
user name right here is admin.

87
03:58.900 --> 04:00.900
As we can see, let's copy this.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

87
03:58.900 --> 04:00.900
As we can see, let's copy this.

88
04:00.900 --> 04:01.900
So paste this in.

89
04:01.900 --> 04:03.900
And then I'll have a comma.

90
04:03.900 --> 04:08.000
And now specify what the password is. So again, we go back, check the

91
04:08.000 --> 04:08.900
credentials.

92
04:08.900 --> 04:11.900
Again, just check this because like I say, they often happen to change.

93
04:11.900 --> 04:16.240
So if you just blame the copy and paste from this particular skill, then well,

94
04:16.240 --> 04:17.400
they might be out of date.

95
04:17.400 --> 04:18.400
So just be aware of that.

96
04:18.400 --> 04:19.400
So paste this in.

97
04:19.400 --> 04:22.980
And now what I will do is just as we saw before, I will say verify is equal to

98
04:22.980 --> 04:23.400
false.

99
04:23.400 --> 04:26.830
And now we should pretty much have all the details that we need in order to

100
04:26.830 --> 04:27.900
make our request.

101
04:27.900 --> 04:32.400
So all I will do now is I will say prints, response and save you.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

101
04:27.900 --> 04:32.400
So all I will do now is I will say prints, response and save you.

102
04:32.400 --> 04:33.400
So let's give it a go.

103
04:33.400 --> 04:36.900
We'll save Python 3 script 2.py before I actually run this.

104
04:36.900 --> 04:38.900
Let's pull this up and now we'll hit enter.

105
04:38.900 --> 04:40.400
And now look at this right here.

106
04:40.400 --> 04:42.400
We're getting back this warning right here once again.

107
04:42.400 --> 04:44.400
In fact, let me just disable that one more time.

108
04:44.400 --> 04:45.400
Go up to the top.

109
04:45.400 --> 04:46.900
Let's disable the warning.

110
04:46.900 --> 04:48.400
I'll go up, try again.

111
04:48.400 --> 04:52.280
So this time once again, we're getting our 200 response very much like with a

112
04:52.280 --> 04:53.400
regular rest API.

113
04:53.400 --> 04:56.900
The difference here though is this time we're now talking to a router.

114
04:56.900 --> 04:59.900
So what I will do here is if I go back up.

115
04:59.900 --> 05:02.900
And once again, I say I want to see the text response.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

115
04:59.900 --> 05:02.900
And once again, I say I want to see the text response.

116
05:02.900 --> 05:04.900
Let's give me the string based data.

117
05:04.900 --> 05:05.900
Hit enter.

118
05:05.900 --> 05:06.900
Look at it right here.

119
05:06.900 --> 05:10.400
We're now seeing all of the Yang model data of this particular device.

120
05:10.400 --> 05:12.900
So we can see here we have gigabit ethernet 1.

121
05:12.900 --> 05:13.900
We have the name here.

122
05:13.900 --> 05:17.400
It has a description on this interface configured by admin.

123
05:17.400 --> 05:20.900
We can see the IPv4 address here.

124
05:20.900 --> 05:21.900
See this right here.

125
05:21.900 --> 05:23.400
And it's corresponding net mask.

126
05:23.400 --> 05:25.900
And once again, this is all structured in JSON.

127
05:25.900 --> 05:28.900
And once again, if I want to access this as Python objects,

128
05:28.900 --> 05:32.400
like with send dictionaries, then I'll call the JSON method.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

128
05:28.900 --> 05:32.400
like with send dictionaries, then I'll call the JSON method.

129
05:32.400 --> 05:36.400
In fact, to make this look a little bit more readable, obviously from rich

130
05:36.400 --> 05:38.400
import prints as our prints.

131
05:38.400 --> 05:41.650
This will just give me some nice formatting and coloration to make things a

132
05:41.650 --> 05:42.900
little easier to read.

133
05:42.900 --> 05:48.900
I'll say pip3 install rich, perfect, and run this script again.

134
05:48.900 --> 05:49.900
So we have a response.

135
05:49.900 --> 05:53.070
And if I just scroll on up, what we can actually do now is just basically call

136
05:53.070 --> 05:53.400
the key.

137
05:53.400 --> 05:54.900
So this is the outer key right here.

138
05:54.900 --> 05:55.900
So let's copy here.

139
05:55.900 --> 05:57.900
And a similar way to what we just did.

140
05:57.900 --> 05:58.900
Let's paste this in.

141
05:58.900 --> 05:59.900
Save this.

142
05:59.900 --> 06:00.400
Arow up.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

142
05:59.900 --> 06:00.400
Arow up.

143
06:00.400 --> 06:01.400
Try again.

144
06:01.400 --> 06:02.900
Now we strip away the outer key.

145
06:02.900 --> 06:04.900
So I can grab the interface here.

146
06:04.900 --> 06:05.900
Let's put the next key.

147
06:05.900 --> 06:06.900
Paste it in.

148
06:06.900 --> 06:08.900
And right after this, we're going to have a list object.

149
06:08.900 --> 06:11.900
So what I can then do is call a particular index.

150
06:11.900 --> 06:13.900
So let's maybe go with index position zero.

151
06:13.900 --> 06:15.900
Let's try this and run this script.

152
06:15.900 --> 06:18.400
Now we're getting much more specific information.

153
06:18.400 --> 06:21.900
And again, if I want to get the name key for this particular interface,

154
06:21.900 --> 06:23.900
I can then call it save you.

155
06:23.900 --> 06:24.900
Arow up.

156
06:24.900 --> 06:25.400
Try again.

157
06:25.400 --> 06:29.900
And as we can see here, we're just targeting this very precise piece of data.

158
06:29.900 --> 06:33.440
So now all of our configurations, and I mean all of our configurations are now
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

158
06:29.900 --> 06:33.440
So now all of our configurations, and I mean all of our configurations are now

159
06:33.440 --> 06:35.400
available as programmatic data.

160
06:35.400 --> 06:36.900
Everything has been young model.

161
06:36.900 --> 06:39.900
And like I say, this particular structure, the way I would parse this,

162
06:39.900 --> 06:44.450
would be the exact same way on a jitter per device because we are using an open

163
06:44.450 --> 06:47.900
vendor neutral young model, the IETF models.

164
06:47.900 --> 06:51.400
So now we're talking programmatically to a device over 80 dps.

165
06:51.400 --> 06:55.400
This all seems very, very good, but again, the mysterious part was how exactly

166
06:55.400 --> 07:00.320
did I know to actually put this particular URL to get this very particular
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

166
06:55.400 --> 07:00.320
did I know to actually put this particular URL to get this very particular

167
07:00.320 --> 07:01.400
piece of information?

168
07:01.400 --> 07:03.400
Well, once again, it's all about young.

169
07:03.400 --> 07:06.400
Let's talk about that a little bit more in the very next video.
