1
00:00:05,270 --> 00:00:05,480
Okay.

2
00:00:05,480 --> 00:00:07,070
So this is just for us as humans.

3
00:00:07,070 --> 00:00:09,530
Show IP interface brief doesn't really help us.

4
00:00:09,560 --> 00:00:15,920
What I'm going to do now, however, is use the command json pretty.

5
00:00:16,190 --> 00:00:20,360
So this line in yellow is actually the only change in the script.

6
00:00:20,450 --> 00:00:25,010
But I've put the full script in this PowerPoint presentation so that you can download it.

7
00:00:25,280 --> 00:00:26,510
So let's use Nano.

8
00:00:26,510 --> 00:00:27,620
Nano once again.

9
00:00:28,580 --> 00:00:30,260
Nano is a simple text editor.

10
00:00:30,920 --> 00:00:33,290
Similar to Notepad on Windows, if you like.

11
00:00:33,690 --> 00:00:38,930
I want to say Nano Python two and what I'll do is paste my script in here.

12
00:00:39,350 --> 00:00:41,060
He had pasted it correctly.

13
00:00:41,660 --> 00:00:43,640
So I'll save that script.

14
00:00:43,670 --> 00:00:46,160
Only difference once again is this.

15
00:00:47,240 --> 00:00:51,410
So Python three, run the second script.

16
00:00:52,460 --> 00:00:59,630
This should give us our JSON information, so we should be able to get the JSON information back from

17
00:00:59,630 --> 00:01:00,800
the Nexus device.

18
00:01:01,220 --> 00:01:02,210
And there you go.

19
00:01:02,600 --> 00:01:03,200
So.

20
00:01:04,360 --> 00:01:05,290
Scrolling up.

21
00:01:06,070 --> 00:01:13,510
By using that single command, I've now been able to S-H to the device, retrieve the data.

22
00:01:14,110 --> 00:01:15,910
It's in JSON format.

23
00:01:15,940 --> 00:01:18,260
Notice double inverted commas.

24
00:01:18,280 --> 00:01:19,600
We've got a colon.

25
00:01:19,720 --> 00:01:21,340
We've got a comma at the end.

26
00:01:21,370 --> 00:01:24,400
Make sure you recognize this formatting.

27
00:01:24,400 --> 00:01:26,640
I've said it once again many times.

28
00:01:26,650 --> 00:01:29,800
If you don't have a colon there, there would be an incorrect answer.

29
00:01:29,830 --> 00:01:32,890
If this is a semicolon, that would be an incorrect answer.

30
00:01:32,920 --> 00:01:34,810
It has to look like this.

31
00:01:35,080 --> 00:01:37,150
No comma at the end here.

32
00:01:37,990 --> 00:01:38,260
Okay.

33
00:01:38,260 --> 00:01:40,420
But once again, that's just given us some data.

34
00:01:40,540 --> 00:01:50,260
Perhaps not that useful, but let's do something useful with the data now and let's get the prefix from

35
00:01:50,260 --> 00:01:52,950
the data and the interface.

36
00:01:52,960 --> 00:01:59,320
So basically I'm using a script now to pull back the first interface and the first IP address.

37
00:01:59,680 --> 00:02:02,950
The worry in the next script, I'm going to show you how to do that from multiple interfaces.

38
00:02:03,580 --> 00:02:07,450
So now, Liz, we've got two Python scripts.

39
00:02:07,450 --> 00:02:09,449
Let's create a third Python script.

40
00:02:09,460 --> 00:02:13,750
So Nano Python three dot p y.

41
00:02:13,960 --> 00:02:18,010
I'll paste the script in the stuff that we've added.

42
00:02:18,310 --> 00:02:26,230
Is this so we pulling back specific interface information now I have made done something.

43
00:02:26,230 --> 00:02:29,700
Badshah I'm using double inverted commas and single inverted commas in Python.

44
00:02:29,710 --> 00:02:31,840
You should standardize on one.

45
00:02:32,350 --> 00:02:37,000
I'll fix that in the script that I give you, but that's fine.

46
00:02:37,900 --> 00:02:40,930
Python will accept that even though it's not great practice.

47
00:02:41,260 --> 00:02:47,950
But hopefully what will happen now is this will connect to that Nexus device once again searching across

48
00:02:47,950 --> 00:02:50,410
the Internet and it's going to pull back.

49
00:02:50,950 --> 00:02:55,570
First interface, first IP address and then display that and there we go.

50
00:02:56,400 --> 00:02:56,530
Okay.

51
00:02:56,620 --> 00:03:04,060
So just to prove it, here's my Nexus device once again, first interface, first IP address.

52
00:03:05,950 --> 00:03:07,680
There's that information.

53
00:03:07,690 --> 00:03:10,960
Now, you might say, okay, but I want the state information.

54
00:03:10,960 --> 00:03:12,340
So something like this.

55
00:03:12,760 --> 00:03:15,190
And remember, we can simply edit that.

56
00:03:17,320 --> 00:03:18,430
Using our script.

57
00:03:18,850 --> 00:03:20,290
So let's edit the script.

58
00:03:20,830 --> 00:03:24,010
So rather than just seeing this data.

59
00:03:25,030 --> 00:03:30,730
What we said is we want to get protocol, state information, so we'll copy that line.

60
00:03:32,440 --> 00:03:32,830
Paste.

61
00:03:33,940 --> 00:03:44,410
And what we want is proto state is the name that they use and I'll save the script, so run it again.

62
00:03:44,740 --> 00:03:46,750
So we should get the protocol status.

63
00:03:46,750 --> 00:03:51,040
We should get the interface name, we should get the IP address.

64
00:03:52,180 --> 00:03:54,900
This, however, will only be for one interface.

65
00:03:54,910 --> 00:03:55,540
Next script.

66
00:03:55,540 --> 00:03:59,260
I'll change that and make it better.

67
00:03:59,560 --> 00:04:01,330
Now the formatting here is not great.

68
00:04:01,330 --> 00:04:02,860
I mean, that's just saying up.

69
00:04:03,130 --> 00:04:05,680
You could print out information.

70
00:04:05,690 --> 00:04:07,780
This is the whole idea with iteration.

71
00:04:07,780 --> 00:04:12,130
So rather than just saying that, you could say print interface.

72
00:04:14,220 --> 00:04:15,790
And while I'm here, let's fix this.

73
00:04:16,829 --> 00:04:22,410
I'd have to fix that for all the data to be consistent.

74
00:04:23,910 --> 00:04:25,560
I could do a fine and replace.

75
00:04:25,560 --> 00:04:27,840
I suppose they would actually make a lot more sense.

76
00:04:28,970 --> 00:04:30,200
Then doing it manually.

77
00:04:34,000 --> 00:04:38,470
But the idea in Python is something called Pep eight.

78
00:04:38,620 --> 00:04:42,770
Pep eight is talking about best practices.

79
00:04:42,790 --> 00:04:46,720
The moral of the story is be consistent so we could say print.

80
00:04:48,860 --> 00:04:49,970
IP address.

81
00:04:55,040 --> 00:04:56,120
Print.

82
00:04:56,980 --> 00:04:58,300
Protocol status.

83
00:05:00,250 --> 00:05:01,560
These are just examples.

84
00:05:01,570 --> 00:05:05,910
You could do what you wanted here, and this is the power of programming.

85
00:05:05,920 --> 00:05:09,050
You just change it the way that you want it to change.

86
00:05:09,730 --> 00:05:11,440
So it's got a problem.

87
00:05:11,440 --> 00:05:19,000
And this is my python to history getting to me in Python three.

88
00:05:19,480 --> 00:05:23,920
We need to use a function for print print as a function.

89
00:05:24,220 --> 00:05:26,230
So this needs to be in brackets.

90
00:05:26,920 --> 00:05:27,880
Save that.

91
00:05:27,880 --> 00:05:28,840
Run it again.

92
00:05:29,840 --> 00:05:37,730
Hopefully this once again will connect to that Nexus device and will tell us IP address, interface

93
00:05:37,730 --> 00:05:41,380
and protocol status and also showed in a little bit nicer format.

94
00:05:41,390 --> 00:05:42,410
So here we go.

95
00:05:42,410 --> 00:05:43,970
There's the output of that script.

96
00:05:44,420 --> 00:05:48,080
Now you might say, okay, but I want the information for all interfaces.

97
00:05:48,080 --> 00:05:53,330
So I've got the script across two PowerPoint slides here.

98
00:05:53,990 --> 00:05:58,010
What I'm doing here is creating a loop.

99
00:05:58,520 --> 00:06:01,910
So we are all using a for loop here.

100
00:06:02,910 --> 00:06:07,080
What we're doing is getting the length of the rows.

101
00:06:07,080 --> 00:06:09,060
So how many rows are there?

102
00:06:09,390 --> 00:06:17,940
So if we jump back onto the device, so this is going directly to the device show IP interface brief

103
00:06:17,940 --> 00:06:19,170
JSON pretty.

104
00:06:20,110 --> 00:06:28,270
Row interface tells us how many interfaces they are one, two, three, four, etc..

105
00:06:28,750 --> 00:06:30,820
Show IP interface brief would just show us that.

106
00:06:30,820 --> 00:06:32,350
So here are all the interfaces.

107
00:06:32,830 --> 00:06:42,430
This length command allows me to work out how many interfaces they are, and then it just loops those

108
00:06:42,430 --> 00:06:44,710
commands for the number of interfaces that we've got.

109
00:06:45,490 --> 00:06:45,730
Okay.

110
00:06:45,730 --> 00:06:47,020
So first thing is.

111
00:06:48,690 --> 00:06:51,650
Knit Mico configuration.

112
00:06:51,660 --> 00:06:57,660
So Liz, we are now working on a Python script for a Python forward API.

113
00:06:58,290 --> 00:07:03,450
I'll paste that in that basically once again just allows me to connect to the device.

114
00:07:03,730 --> 00:07:06,750
Didn't have enough space in PowerPoint.

115
00:07:09,060 --> 00:07:12,510
I'll copy this into the VM now.

116
00:07:12,960 --> 00:07:19,830
So the big difference now is it's using the command and then finding out how many interfaces there are

117
00:07:19,830 --> 00:07:25,830
and then using a loop to basically run these commands multiple times for the number of interfaces that

118
00:07:25,830 --> 00:07:26,490
we have.

119
00:07:27,240 --> 00:07:31,860
So clear the screen Python three, Python four dot p y.

120
00:07:31,890 --> 00:07:37,950
This should hopefully now give us IP address an interface name for all the interfaces on that device.

121
00:07:38,820 --> 00:07:42,780
And to prove it, I'll create some extra interfaces and run the script again and we should see that.

122
00:07:44,230 --> 00:07:45,150
So there you go.

123
00:07:45,160 --> 00:07:49,210
All the interfaces on the device and the IP addresses.

124
00:07:49,450 --> 00:07:55,810
So if I show that side by side, there are all the interfaces on the device and the IP addresses.

125
00:07:56,050 --> 00:07:57,460
But let's create another loopback.

126
00:07:57,460 --> 00:08:01,960
So let's create a loopback to IP address.

127
00:08:01,960 --> 00:08:04,510
Two, two, two, two, slash.

128
00:08:06,170 --> 00:08:18,260
Three Mosque interface loop three IP address slash 32 mosque show IP interface brief.

129
00:08:18,290 --> 00:08:22,460
I've just created two additional loopback interfaces.

130
00:08:23,390 --> 00:08:24,860
So run that script again.

131
00:08:25,370 --> 00:08:30,440
This is once again connecting to that device in dev net and pulling back the information.

132
00:08:30,440 --> 00:08:31,430
And there you go.

133
00:08:31,460 --> 00:08:37,010
Additional loopback interfaces are shown just to prove it once more.

134
00:08:37,490 --> 00:08:40,610
Last interface loopback for IP address.

135
00:08:42,230 --> 00:08:50,630
Quadruple for show IP interface brief new interfaces created run the script again.

136
00:08:50,630 --> 00:08:55,610
We didn't previously have loopback for in the output here, but hopefully we will now.

137
00:08:56,270 --> 00:08:57,170
And there we go.

138
00:08:58,680 --> 00:09:00,870
So why are we using JSON?

139
00:09:00,900 --> 00:09:05,190
Much easier to work with this kind of data when you've got a Python script.

140
00:09:05,220 --> 00:09:12,420
It's very difficult to find information if it's a string, if it's just data that's in an formatted

141
00:09:12,420 --> 00:09:13,140
format.

142
00:09:13,140 --> 00:09:21,420
So if it's just some kind of data that's like this capture, not easy for a machine to read that we

143
00:09:21,420 --> 00:09:26,370
want to put it in a format that's easy for a machine to query and interpret.

144
00:09:26,400 --> 00:09:30,990
Your Python scripts are going to be so much easier if the data is in JSON.

145
00:09:31,020 --> 00:09:31,920
Trust me.

146
00:09:32,010 --> 00:09:37,470
Try and do that kind of stuff with just strings and parsing the string, trying to find where the data

147
00:09:37,470 --> 00:09:39,060
is and extracting a piece of data.

148
00:09:39,090 --> 00:09:45,570
It's very hard to do that with traditional mechanisms, so much easier if the data is correctly formatted

149
00:09:45,570 --> 00:09:48,750
using JSON or even XML or YAML.

150
00:09:49,200 --> 00:09:53,400
Big idea for doing this is to make it easy for machines to read.

151
00:09:54,150 --> 00:09:54,390
Okay.

152
00:09:54,390 --> 00:09:55,350
So hopefully you've learned something.

153
00:09:55,380 --> 00:09:58,740
I went to quite a bit of detail there with regards to the Python scripts.

154
00:09:58,830 --> 00:10:03,870
You don't have to learn Python for the exam, but for the real world, I'd highly recommend it.

