WEBVTT

1
00:00.000 --> 00:03.960
Now we have the ability to send show commands to verify the state of our

2
00:03.960 --> 00:04.640
devices.

3
00:04.640 --> 00:09.360
Let's now learn how we can modify our devices by now sending configurations.

4
00:09.360 --> 00:12.320
Once again, we're going to be utilizing NetMico.

5
00:12.320 --> 00:14.800
So if that said, let's go and do it then.

6
00:14.800 --> 00:17.840
So what I will do here is let me go and well,

7
00:17.840 --> 00:20.640
yeah, let's go and create a little configuration file, okay?

8
00:20.640 --> 00:25.680
So let's just create a little file called globalconfig.txt, okay?

9
00:25.680 --> 00:26.880
So let's open this up.

10
00:26.880 --> 00:30.960
So all I'm going to do here is to write some Cisco specific syntax.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

10
00:26.880 --> 00:30.960
So all I'm going to do here is to write some Cisco specific syntax.

11
00:30.960 --> 00:35.920
So let's imagine I wanted to give everyone an NTP server configuration of 1234.

12
00:35.920 --> 00:39.040
Let's now go with SNMP server community.

13
00:39.040 --> 00:41.840
Let's just call this test community and get it read only.

14
00:41.840 --> 00:44.720
Let's add a message of the day banner.

15
00:44.720 --> 00:46.960
Just say this is an automated banner.

16
00:46.960 --> 00:51.200
And let's just imagine we're going to say router OSPF, process ID1.

17
00:51.200 --> 00:54.560
And let's just advertise all networks with the quad zeros.

18
00:54.560 --> 00:58.000
And let's have a well card that matches all IP addresses and we'll put it into

19
00:58.000 --> 00:58.880
areas 0, okay?

20
00:58.880 --> 01:01.920
So pretty much this is going to be the configuration that is going to go on all
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

20
00:58.880 --> 01:01.920
So pretty much this is going to be the configuration that is going to go on all

21
01:01.920 --> 01:03.520
of our devices in the network.

22
01:03.520 --> 01:06.160
Now remember, earlier on within this particular skill,

23
01:06.160 --> 01:10.400
we know that we can read particular files and we want to be able to

24
01:10.400 --> 01:13.360
well send them line by line by line.

25
01:13.360 --> 01:14.800
So let's check out and see how we can do this.

26
01:14.800 --> 01:16.320
What I will do is create a new file.

27
01:16.320 --> 01:18.800
Let's just say touch example six.py.

28
01:18.800 --> 01:22.000
Let's open you up such as import connect handler with NetMico.

29
01:22.000 --> 01:25.780
And let's use my context manager. So I'll say with open and I'll specify the

30
01:25.780 --> 01:26.880
name of the file I want to open,

31
01:26.880 --> 01:29.760
which is going to be a globalconfig.txt.

32
01:29.760 --> 01:33.440
It's going to be opened in read mode and what is open as the variable target
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

32
01:29.760 --> 01:33.440
It's going to be opened in read mode and what is open as the variable target

33
01:33.440 --> 01:33.920
file.

34
01:33.920 --> 01:36.640
And what I'll do is I will say myconfig is equal to

35
01:36.640 --> 01:40.480
and I'll take my target file object and I'll use the read lines method.

36
01:40.480 --> 01:42.880
Remember, this is going to give us a list object.

37
01:42.880 --> 01:46.400
So right now if I just print out my config and to answer,

38
01:46.400 --> 01:49.280
as we can see right here, we have the first line of configuration,

39
01:49.280 --> 01:53.340
then effectively in new line, i.e. a return key, then the next line, so on, so

40
01:53.340 --> 01:53.920
forth.

41
01:53.920 --> 01:56.160
Now we just don't want to print out this information.

42
01:56.160 --> 01:58.480
We want to pass it into NetMico.

43
01:58.480 --> 02:02.000
Now similarly, we also want to be able to loop through all of our devices.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

43
01:58.480 --> 02:02.000
Now similarly, we also want to be able to loop through all of our devices.

44
02:02.000 --> 02:04.240
Now our devices happen to be with any YAML files.

45
02:04.240 --> 02:08.640
I'll say import YAML and let's use a new context manager.

46
02:08.640 --> 02:09.840
So I'll say with open.

47
02:09.840 --> 02:12.000
In fact, what I will do just for quickness.

48
02:12.000 --> 02:14.240
Let me just copy the logic from a previous script.

49
02:14.240 --> 02:15.600
Speed things up a little bit.

50
02:15.600 --> 02:16.400
Paste this in.

51
02:16.400 --> 02:19.280
Let me just change the name here so we're not copying the same information.

52
02:19.280 --> 02:21.840
Let's just change it to target devices and again here.

53
02:21.840 --> 02:24.080
Change to target devices.

54
02:24.080 --> 02:26.000
Now big, big difference here.

55
02:26.000 --> 02:30.720
With respect to NetMico, this send command method is only used for sending show
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

55
02:26.000 --> 02:30.720
With respect to NetMico, this send command method is only used for sending show

56
02:30.720 --> 02:32.160
commands pretty much.

57
02:32.160 --> 02:35.840
When this method is called NetMico is going to type the enable command

58
02:35.840 --> 02:39.360
so that we're in privacy exec mode, which is where we send our show commands

59
02:39.360 --> 02:39.920
from.

60
02:39.920 --> 02:43.760
When we want to send configuration changes, we don't just do enable.

61
02:43.760 --> 02:47.660
We also want to go to global config mode by typing "convt" or "configure

62
02:47.660 --> 02:48.160
terminal".

63
02:48.160 --> 02:52.080
So what I will do here is I'm going to use an entirely different method.

64
02:52.080 --> 02:55.200
And I'm going to say send config set.

65
02:55.200 --> 02:56.240
See this one right here?

66
02:56.240 --> 02:57.280
Let's choose this.

67
02:57.280 --> 03:01.520
Now what I'm going to do here is inside the parentheses, I'm going to pass in
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

67
02:57.280 --> 03:01.520
Now what I'm going to do here is inside the parentheses, I'm going to pass in

68
03:01.520 --> 03:03.040
the myconfig object,

69
03:03.040 --> 03:06.720
which ultimately stores the line by line list of all my configurations.

70
03:06.720 --> 03:09.760
So let's now pass in myconfig right here.

71
03:09.760 --> 03:13.280
And if I just save this, what I can do is if I clear the screen.

72
03:13.280 --> 03:17.920
And I now run the script and to enter, we send the commands to the first device

73
03:17.920 --> 03:17.920
,

74
03:17.920 --> 03:20.480
then to the second, and then lastly the fourth.

75
03:20.480 --> 03:21.120
So you see this?

76
03:21.120 --> 03:23.360
See how we're able to send each one line by line?

77
03:23.360 --> 03:24.480
There's the first line.

78
03:24.480 --> 03:26.000
Here is the second line.

79
03:26.000 --> 03:26.960
Here is the third.

80
03:26.960 --> 03:29.600
So on so forth for every single device.

81
03:29.600 --> 03:31.680
So what I can now do is go and verify these changes.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

81
03:29.600 --> 03:31.680
So what I can now do is go and verify these changes.

82
03:31.680 --> 03:33.440
Let's go and check device number one.

83
03:33.440 --> 03:35.280
For example, let's open this up.

84
03:35.280 --> 03:39.120
If I hit "return", straight away we can see the banner has been configured.

85
03:39.120 --> 03:41.840
I find out to enable mode and go undo showrun.

86
03:41.840 --> 03:44.560
Straight away we can see we have our OSPF configuration.

87
03:44.560 --> 03:48.640
We also have our SNMP community, as well as our NTP server configured.

88
03:48.640 --> 03:52.640
Now similarly if I go and close this down, let's go to the next one, device

89
03:52.640 --> 03:53.440
number two.

90
03:53.440 --> 03:56.000
If I hit "return", again we see the automated banner.

91
03:56.000 --> 03:59.280
If I do enable and then showrun, let's press "Spacebar".

92
03:59.280 --> 04:01.920
Again we see our router OSPF configuration.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

92
03:59.280 --> 04:01.920
Again we see our router OSPF configuration.

93
04:01.920 --> 04:04.720
Here is our banner, here is our SNMP community,

94
04:04.720 --> 04:06.800
and we also have our NTP server.

95
04:06.800 --> 04:08.880
And this is also true for devices 3 and 4.

96
04:08.880 --> 04:12.320
So as we can see here, we are beginning to tie everything together.

97
04:12.320 --> 04:16.250
We're able to read in regular data and parse it into a list object, line by

98
04:16.250 --> 04:16.640
line.

99
04:16.640 --> 04:20.100
We're able to load in device information, it has been stored in YAML and make

100
04:20.100 --> 04:20.880
it accessible.

101
04:20.880 --> 04:23.440
We're now utilizing NetMico as well as Lips.

102
04:23.440 --> 04:27.030
And then we're ultimately combining that information and utilizing it with NetM

103
04:27.030 --> 04:27.280
ico

104
04:27.280 --> 04:31.520
to send the configurations to the target devices, utilizing a Python Lip.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

104
04:27.280 --> 04:31.520
to send the configurations to the target devices, utilizing a Python Lip.
