GNS3 Talks: Python for Network Engineers with GNS3 (Part 4) - Create switch VLANs using loops

David Bombal · Beginner ·📊 Data Analytics & Business Intelligence ·9y ago

Key Takeaways

Creates switch VLANs using loops with Python for network engineers in GNS3

Full Transcript

this is one of multiple videos teaching you network programmability using Python and genus [Music] [Music] 3 now in the previous video we created switch one script 2. py and I told you that it's inefficient to create a vlans in this way on a switch now it works so as an example we can use the command S1 script 2. py and the script SC will tnet to the switch and create various vlans but it's an inefficient way of adding vlans or doing repetitive work let's see if we can clear up this code and do it better now to do that we're going to create a loop a loop is essentially telling the computer to do something for a certain amount of time so in this example I'm going to do a range I'm going to say do the following in the range 2 to 10 now in Python spacing is very important think about how the Cisco iOS works or the iOS of many networking devices work when we looking at code so as an example this code or configuration if you prefer of a CSCO router do you agree that this space is very important this space indicates that this IP address is configured under this loop back all this code here belongs to this interface and so forth and so on we know that this network command belongs under the OSF writing process if I try to type Network 0.0.0.0 here in global configuration mode the router doesn't accept it that space is telling us that this piece of code or configuration belongs under the writing process this code belongs under this interface so use that as an analogy for what we're doing here the code that we're now going to write belongs under the for Loop so what we're going to write to the switch is VLAN space plus n plus carriage return so those two lines will allow us to replace the code that we've got here what I'll do is paste that back but notice I'm going to press Tab and what we want to do here is say plus n Plus carriage return now when we run this script it's going to fail because this is an integer and this is a string and I'll talk about that in a moment but essentially what we've done is we've replaced all of this code with three lines and we can extend that by for instance doing 2 to 20 so what I'll do is I'll save that code and I'll run it but notice the problem when we run the code we told that line 23 in our script in other words this line is mixing strings and integers so I'll run python directly and notice what we told when we enter type one in Brackets we told that this is an integer type David that's a string or type this way is a string but type let's say 1.5 is a floating value integers are whole numbers floating numbers as an example allow us to have fractions in our numbers now we told once again that we can't mix string and integer objects so we're not going to let that stop us what we're going to do here is change the integer to a string and all we're going to do is type string or Str Str and brackets around that n to change it to a string value and save the script now on the switch at the moment show VLAN shows us that we have ethernet vlans 1 to8 configured we're not going to worry about token ring and fddi but what happens when we run our script so David put the password in and notice what happens it's creating vlans 2 to9 so previously we had one to8 now show VLAN brief shows us that we have a VLAN 9 and this is the power of Loops if we want to add let's say vlans 2 to 20 we simply change that one value run our script again notice it's created VLS 2 to 19 so show vline brief notice the VLS are created and one thing I should say is if we want to create two to 20 we need to add one extra value there so let's run the script again this is the great thing about programming if you make a mistake you can just correct it and what's great with gns3 is you can actually see what your program or script is doing so notice we have VLAN 20 created so it was as simple as that to write a script that creates multiple vlans on a cisa switch it's not a very long script it only has a few lines in it let's be a little bit ridiculous now and this is the power of programming I'll create 100 vlans on our switch so run the script again and while that's running in the background notice the VLS are being created we can see 27 VLS now 32 VLS now we at 36 now you may say that you could copy and paste from an Excel spreadsheet but remember with loops we can now create a Loops within Loops so what we could do is rather than just connecting to one switch we can Loop across multiple switches and run this code across multiple switches hope you enjoyed this video if it was of benefit to you please like it and please subscribe to my YouTube channel I wish you all the very best

Original Description

Udemy: Get the course for $10 here: https://goo.gl/QYC988 GNS3 Academy: Get the course for $10 here: https://goo.gl/vnZJhg More free Python videos here: https://www.youtube.com/playlist?list=PLhfrWIlLOoKPn7T9FtvbOWX8GxgsFFNwn Script used in this video is available on GitHub here: https://github.com/davidbombal/pythonvideos/commit/da3045beca3c1b8766b2c9c92d2cdf55b3b8f7f1 Transcription: This is one of multiple videos teaching you network programmability using Python and GNS3. In the previous video we created S1script2.py and I told you that it's inefficient to create VLANs in this way on a switch, now it works. So as an example, we can use the command S1script2.py and the script will telnet to the switch and create various VLANs, but it's an inefficient way of adding VLANs or doing repetitive work. Let's see if we can clear up this code and do it better. Now to do that we're going to create a loop. A loop is essentially telling the computer to do something for a certain amount of time. So in this example I'm going to do a range. I'm going to say do the following in the range 2 to 10. Now in Python, spacing is very important. Think about how the Cisco IOS works or the IOS of many networking devices work. When we’re looking at code so as an example, this code or configuration if you prefer of a Cisco router, do you agree that this space is very important? This space indicates that this IP address is configured under this loopback. All of this code here belongs to this interface and so forth and so on. We know that this network command belongs under the OSPF routing process. If I try to type network 0.0.0.0 here in global configuration mode, the router doesn't accept it that space is telling us that this piece of code or configuration belongs under the routing process. This code belongs under this interface. So use that as an analogy for what we're doing here. The code that we're now going to write belongs under the for-loop. So what we're going to writ
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from David Bombal · David Bombal · 0 of 60

← Previous Next →
1 RYU SDN Controller Part 4: Graphical User Interface (GUI): Practical GNS3 SDN and OpenFlow
RYU SDN Controller Part 4: Graphical User Interface (GUI): Practical GNS3 SDN and OpenFlow
David Bombal
2 HPE Network Protector SDN Application Part 1 - Introduction
HPE Network Protector SDN Application Part 1 - Introduction
David Bombal
3 HPE Network Protector SDN Application Part 2 : DNS Interception using OpenFlow
HPE Network Protector SDN Application Part 2 : DNS Interception using OpenFlow
David Bombal
4 HPE Network Protector SDN Application Part 3 - Lab Setup using Physical Switches
HPE Network Protector SDN Application Part 3 - Lab Setup using Physical Switches
David Bombal
5 HPE Network Protector SDN Application Part 4 - Demo of malicious websites blocked
HPE Network Protector SDN Application Part 4 - Demo of malicious websites blocked
David Bombal
6 HPE Network Protector SDN Application Part 5 - Demo OpenFlow table interception flows
HPE Network Protector SDN Application Part 5 - Demo OpenFlow table interception flows
David Bombal
7 HPE Network Protector SDN Application Part 6 - Demo of Physical Switch configuration
HPE Network Protector SDN Application Part 6 - Demo of Physical Switch configuration
David Bombal
8 HPE Network Protector SDN Application Part 7 - Demo Service Insertion Tunnel / GRE Tunnel
HPE Network Protector SDN Application Part 7 - Demo Service Insertion Tunnel / GRE Tunnel
David Bombal
9 HPE Network Protector SDN Application Part 8 - Demo SDN OpenFlow Reporting
HPE Network Protector SDN Application Part 8 - Demo SDN OpenFlow Reporting
David Bombal
10 HPE Network Protector SDN Application Part 9 - Demo switches interception of DNS traffic
HPE Network Protector SDN Application Part 9 - Demo switches interception of DNS traffic
David Bombal
11 GNS3 Talks: GNS3 version 1.5.X Appliance Tips
GNS3 Talks: GNS3 version 1.5.X Appliance Tips
David Bombal
12 CCNA 200-125 Exam: AAA demo: TACACS+ with GNS3
CCNA 200-125 Exam: AAA demo: TACACS+ with GNS3
David Bombal
13 GNS3 2.0.0 beta 2 install
GNS3 2.0.0 beta 2 install
David Bombal
14 CCNA #012: Learn SNMP with GNS3, Wireshark and Solarwinds NPM - CCNA 200-125 exam
CCNA #012: Learn SNMP with GNS3, Wireshark and Solarwinds NPM - CCNA 200-125 exam
David Bombal
15 CCNA #013: Spanning Tree CCNA Exam Questions: Know the answer? CCNA 200-125 exam
CCNA #013: Spanning Tree CCNA Exam Questions: Know the answer? CCNA 200-125 exam
David Bombal
16 GNS3 2.0.0 beta : GNS3 VM integration with GNS3 GUI
GNS3 2.0.0 beta : GNS3 VM integration with GNS3 GUI
David Bombal
17 CCNA #018: Routing exam questions: Who wins? OSPF, EIGRP or RIP? Sure? CCNA 200-125 exam
CCNA #018: Routing exam questions: Who wins? OSPF, EIGRP or RIP? Sure? CCNA 200-125 exam
David Bombal
18 CCNA #019: Spanning Tree CCNA Exam Questions: Root Bridge, Root Port and more: CCNA 200-125 exam
CCNA #019: Spanning Tree CCNA Exam Questions: Root Bridge, Root Port and more: CCNA 200-125 exam
David Bombal
19 GNS3 Download, installation and configuration - GNS3 1.5.3 and Windows 10
GNS3 Download, installation and configuration - GNS3 1.5.3 and Windows 10
David Bombal
20 CCNA #023 EIGRP Neighbor Troubleshooting (DUAL Issues) for the CCNA 200-125 Exam
CCNA #023 EIGRP Neighbor Troubleshooting (DUAL Issues) for the CCNA 200-125 Exam
David Bombal
21 GNS3 2.0 Architecture and schema Part 1: What is the GNS3 Controller?
GNS3 2.0 Architecture and schema Part 1: What is the GNS3 Controller?
David Bombal
22 GNS3 2.0 Architecture and schema Part 2: Emulators and virtualization
GNS3 2.0 Architecture and schema Part 2: Emulators and virtualization
David Bombal
23 CCNA #028 VTP Troubleshooting for the CCNA 200-125 Exam
CCNA #028 VTP Troubleshooting for the CCNA 200-125 Exam
David Bombal
24 CCNA #029 VTP & DTP Troubleshooting for the CCNA 200-125 Exam
CCNA #029 VTP & DTP Troubleshooting for the CCNA 200-125 Exam
David Bombal
25 CCNA #030 VTP Troubleshooting for the CCNA 200-125 Exam
CCNA #030 VTP Troubleshooting for the CCNA 200-125 Exam
David Bombal
26 GNS3 : How to download Cisco IOS images and VIRL images. Which is the best? How do you get them?
GNS3 : How to download Cisco IOS images and VIRL images. Which is the best? How do you get them?
David Bombal
27 GNS3 ASA setup: Import and configure Cisco ASAv with GNS3
GNS3 ASA setup: Import and configure Cisco ASAv with GNS3
David Bombal
28 GNS3 switching setup and options: Cisco and other switching options in GNS3
GNS3 switching setup and options: Cisco and other switching options in GNS3
David Bombal
29 GNS3 switching setup and options Part 2: GNS3 unmanaged built-in switch
GNS3 switching setup and options Part 2: GNS3 unmanaged built-in switch
David Bombal
30 GNS3 switching setup and options Part 3: Router on a sick with GNS3 unmanaged built-in switch
GNS3 switching setup and options Part 3: Router on a sick with GNS3 unmanaged built-in switch
David Bombal
31 GNS3 switching setup and options Part 4: Etherswitch Router for Cisco Dynamips Part 1
GNS3 switching setup and options Part 4: Etherswitch Router for Cisco Dynamips Part 1
David Bombal
32 GNS3 switching setup and options Part 5: Etherswitch Router for Cisco Dynamips Part 2
GNS3 switching setup and options Part 5: Etherswitch Router for Cisco Dynamips Part 2
David Bombal
33 GNS3 switching setup and options Part 6: Etherswitch, Wireshark, 802.1Q, InterVLAN routing
GNS3 switching setup and options Part 6: Etherswitch, Wireshark, 802.1Q, InterVLAN routing
David Bombal
34 GNS3 Talks: Docker, Open vSwitch, SDN and OpenFlow Part 1: GNS3 Switching Part 7
GNS3 Talks: Docker, Open vSwitch, SDN and OpenFlow Part 1: GNS3 Switching Part 7
David Bombal
35 GNS3 Talks: Docker, Open vSwitch, SDN and OpenFlow Part 2: GNS3 Switching Part 8
GNS3 Talks: Docker, Open vSwitch, SDN and OpenFlow Part 2: GNS3 Switching Part 8
David Bombal
36 GNS3 Talks: Docker, Open vSwitch, SDN and OpenFlow Part 3: GNS3 Switching Part 9
GNS3 Talks: Docker, Open vSwitch, SDN and OpenFlow Part 3: GNS3 Switching Part 9
David Bombal
37 GNS3 Talks: Docker, Open vSwitch, SDN and OpenFlow Part 4: GNS3 Switching Part 10
GNS3 Talks: Docker, Open vSwitch, SDN and OpenFlow Part 4: GNS3 Switching Part 10
David Bombal
38 GNS3 Talks: Docker, Open vSwitch, SDN and OpenFlow Part 5: GNS3 Switching Part 11
GNS3 Talks: Docker, Open vSwitch, SDN and OpenFlow Part 5: GNS3 Switching Part 11
David Bombal
39 GNS3 Nexus (NX-OSv) switch setup and configuration Part 1: GNS3 switching options Part 12
GNS3 Nexus (NX-OSv) switch setup and configuration Part 1: GNS3 switching options Part 12
David Bombal
40 GNS3 Nexus (NX-OSv) switch setup and configuration Part 2: GNS3 switching options Part 13
GNS3 Nexus (NX-OSv) switch setup and configuration Part 2: GNS3 switching options Part 13
David Bombal
41 GNS3 Talks: Docker, Open vSwitch, SDN and OpenFlow Part 6: GNS3 Switching Part 14
GNS3 Talks: Docker, Open vSwitch, SDN and OpenFlow Part 6: GNS3 Switching Part 14
David Bombal
42 GNS3 Talks: Docker, Open vSwitch, SDN and OpenFlow Part 7: GNS3 Switching Part 15
GNS3 Talks: Docker, Open vSwitch, SDN and OpenFlow Part 7: GNS3 Switching Part 15
David Bombal
43 GNS3 Cisco CSR 1000v setup and configuration Part 1: GNS3 NFV
GNS3 Cisco CSR 1000v setup and configuration Part 1: GNS3 NFV
David Bombal
44 GNS3 Cisco CSR 1000v setup and configuration Part 2: GNS3 NFV
GNS3 Cisco CSR 1000v setup and configuration Part 2: GNS3 NFV
David Bombal
45 GNS3 Talks: Use the NAT node to connect GNS3 to the Internet easily!
GNS3 Talks: Use the NAT node to connect GNS3 to the Internet easily!
David Bombal
46 GNS3 Talks: GNS3 2.0 RC1 is now available
GNS3 Talks: GNS3 2.0 RC1 is now available
David Bombal
47 GNS3 Talks: GNS3 2.0 Portable Projects - easily export and import GNS3 projects
GNS3 Talks: GNS3 2.0 Portable Projects - easily export and import GNS3 projects
David Bombal
48 GNS3 Talks: Multiple clients sharing projects in real time, plus console session shadowing!
GNS3 Talks: Multiple clients sharing projects in real time, plus console session shadowing!
David Bombal
49 CCNA #035 NAT Troubleshooting Scenario 1 - Can you find the issue? CCNA Exam 200-125 troubleshooting
CCNA #035 NAT Troubleshooting Scenario 1 - Can you find the issue? CCNA Exam 200-125 troubleshooting
David Bombal
50 CCNA #036 NAT Troubleshooting Scenario 2 - Can you find the issue? CCNA Exam 200-125 troubleshooting
CCNA #036 NAT Troubleshooting Scenario 2 - Can you find the issue? CCNA Exam 200-125 troubleshooting
David Bombal
51 GNS3 Talks: ESXi, GNS3 VM and KVM support Part 1: leverage servers and the cloud
GNS3 Talks: ESXi, GNS3 VM and KVM support Part 1: leverage servers and the cloud
David Bombal
52 CCNA #037 OSPF Troubleshooting - can you find the issue? CCNA Exam 200-125 troubleshooting
CCNA #037 OSPF Troubleshooting - can you find the issue? CCNA Exam 200-125 troubleshooting
David Bombal
53 GNS3 Talks: ESXi, GNS3 VM and KVM support Part 2:  leverage servers and the cloud
GNS3 Talks: ESXi, GNS3 VM and KVM support Part 2: leverage servers and the cloud
David Bombal
54 CCNA #038 NAT Troubleshooting Scenario 3 - Can you find the issue? CCNA Exam 200-125 troubleshooting
CCNA #038 NAT Troubleshooting Scenario 3 - Can you find the issue? CCNA Exam 200-125 troubleshooting
David Bombal
55 CCNA #039 - OSPF DR, BR and DROTHER Election - do you know the answers?
CCNA #039 - OSPF DR, BR and DROTHER Election - do you know the answers?
David Bombal
56 CCNA #040 NAT Troubleshooting Scenario 4 - Can you find the issue? CCNA Exam 200-125 troubleshooting
CCNA #040 NAT Troubleshooting Scenario 4 - Can you find the issue? CCNA Exam 200-125 troubleshooting
David Bombal
57 GNS3 Talks: Arista vEOS GNS3 import and configuration Part 1
GNS3 Talks: Arista vEOS GNS3 import and configuration Part 1
David Bombal
58 CCNA #041 - OSPF DR, BR and DROTHER Election - do you know the answers?
CCNA #041 - OSPF DR, BR and DROTHER Election - do you know the answers?
David Bombal
59 GNS3 Talks: Arista vEOS GNS3 import and configuration Part 2
GNS3 Talks: Arista vEOS GNS3 import and configuration Part 2
David Bombal
60 GNS3 Talks: ipterm: Linux, Docker, Python, SDN and more! Part 1
GNS3 Talks: ipterm: Linux, Docker, Python, SDN and more! Part 1
David Bombal

Related Reads

📰
12.4 Million US Business Registrations Are Sitting on State Open-Data Portals, Free
Unlock 12.4 million US business registrations for free from state open-data portals and boost your business intelligence
Dev.to · Brad Ju
📰
Mau Naik Level? Ini Advanced Data Science Techniques untuk Data Analytics
Learn advanced data science techniques for data analytics to improve business decision-making
Medium · Data Science
📰
I Finally Understood AWS Data Pipelines After Following a Single Customer Click
Learn how to understand AWS Data Pipelines by following a customer click, making it easier to design and implement data workflows
Dev.to · Anupa Supul
📰
Beyond the Basics: Streamlit, Dash, and Bokeh for Interactive Dashboards
Learn to create interactive dashboards with Streamlit, Dash, and Bokeh, going beyond basic data visualization tools
Dev.to · RoyserVillanueva
Up next
ChatGPT Will Make Your Excel & Google Sheets x10 Better!
Educraft
Watch →