Select Page

Python For Network Engineer 2

by | 2-Jan-2021 | DevOps, Programming

Python For Network Engineers 2

(1) Create switch VLANs using loops

Ubuntu-1

  • Create VLAN using loop function (Figure 1)
    • Use “for” to create loop
    • Notice that there is an error when we try to run the script, can’t mix “str” and “int” objects
  • Fix the error (Figure 2)
    • Change integer to string using str(n)
  • Connect to multiple switches (Figure 3)
    • Use “for” to create loop

(2) Opening Files and spacing importance

Ubuntu-1

  • Read the list of Switch IP addresses from a file
    • Create new text file: myswitches (Figure 1)
    • Use “open()” function to open file (Figure 2)
  • White spacing makes different logic
    • Using the same level of spacing groups the line of codes together under the loop function (Figure 3)
    • We don’t want the “end”, “wr”, and “exit” to be inside the loop (Figure 4)
  • Script link

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *