From the course: Network Automation Quick Start

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Loops within loops

Loops within loops

- [Instructor] Now previously we created a script, python32.py. If I look into the contents of that file, we can see that the network automation container telnets to a switch that's hard coded in the script and then creates some VLANs on that switch. So using this as our basis, let's now extend the script to use a file of IP addresses. So rather than hard coding an IP address into the script, let's open a file called myswitches. What you'll notice is this script is very similar to what we created previously. This code is essentially the same, except here we've got a hard coded IP address, here I've simply left host equal to localhost and notice at line eight we change things, because we're going to open a file called myswitches and only later are we going to telnet to the device, unlike what we did in our original script. The reason for doing this, is we wanna open up a file called myswitches and then for each line or entry in that file, we going to telnet to the switch and create the…

Contents