Now, one thing that you shouldn't be doing is reinventing the wheel.
Don't redo code.
Try and leverage what you've created previously.
So as an example, if I look at Python three for p y, we previously created a loop here that created
a bunch of VLANs on a single switch.
In the previous video we opened up a file called My Switches and then created a VLANs.
Owner the switches listed in the file.
So what you'll notice now is this code looks exactly the same as my new script.
Python three six API.
Here's Python 35. y.
Yes, python 36. p y.
The change that we're making here is we're going to use.
Thus a loop that we previously created and use that in our script.
So I've simply copied these lines of code.
And I've changed the number of VLANs to 21.
So I've been able to remove this code, which wasn't ideal.
And I've replaced it with a loop.
Apart from that.
Everything is the same as our previous script.
Previously we opened a file called My Switches.
That's what we're doing here.
We're opening up a file called My Switches, and then for each IP address in the file we are going to
telnet to the switch.
Login, go to global configuration mode and now create a bunch of VLANs on that switch.
So what I'll do is copy this code.
Go to the network automation container and create a file called Python three six.
P y.
And I'll paste that code in.
And save it.
So python three.
Python three six.
P y.
Before I press enter, notice that on switch one as an example, we only have vlans up to vlan eight.
The same is true on switch three.
Show vlan.
Brief.
We only have a vlans up to vlan eight.
Same is true on switch six.
Show VLAN brief.
We only have eight ethernet vlans so run the script username is David.
Password is Cisco.
It's toll needing to switch one at the moment he has switched to.
You can see the telnet debug.
Show we brief.
Notice 20 VLANs have been created on switch to the script is already configuring switch for.
You can see the telnet debug output show vlan brief.
We've got 20 vlans configured on the switch.
And the same is true for the other switches.
So as an example, show vlan brief on switch six.
We've got 20 vlans.
So this simple script can telnet to as many switches as we want and configure as many VLANs as we want
by making that simple change.
The script will now telnet to the switches and configure 30 VLANs.
So there's our original 20.
But now you can see 27 have been configured.
Run the command again.
30 VLANs have now been configured.
The switch has configured switch three to now configured switch for.
So in search for gain.
Shall we land?
Brief.
30 VLANs have been configured.
And on switch six.
30 VLANs have now been configured.
So this is the power of automation.
Just iterate and improve your scripts as you go along.
With just those three lines of code added to the script.
We can get to the script to configure many VLANs on many switches.
If you want to configure additional switches, simply add IP addresses to the my switches file and then
the script will loop through the file and configure those switches with the VLANs.
Now one thing we haven't done is save the configuration of our switches.
So to get the script to do that, I could simply copy and paste a line here for saving the switch configurations.
And then I could say Python three, Python three, six MP y and get to the script to telnet to each
switch.
Configure the switch and then save the switch configuration.
It's now configuring switch to.
You can see the telnet debug output.
And as you can see, the configuration has been saved.
David.
Tony added to the switch and saved the configuration.
You can see something similar in the output of the script.
So the lesson was network automation and network programmability is iterate your scripts, keep on improving
your scripts and enhancing the features available in your scripts.
Start small and then keep on improving your scripts to do more and more.