GNS3 Talks: Python for Network Engineers with GNS3 (Part 1). Network programmability made easy.
ฝัง
- เผยแพร่เมื่อ 3 ธ.ค. 2024
- Udemy: Get the course for $10 here: goo.gl/QYC988
GNS3 Academy: Get the course for $10 here: goo.gl/vnZJhg
More free Python videos here: • Python Programming for...
Learn Python programming with GNS3. In this series of videos I will show you how you can quickly and easily program Cisco networks using Python. In this video we program a Cisco IOSv router using Python on an Ubuntu Docker container.
The script used in this video is available on GitHub here:
github.com/dav...
Transcription:
This is one of multiple videos discussing Python programming. Now there's a lot of information on the internet with regards to Python programming, but in these series of videos I'm going to concentrate solely on the use of Python with networking devices and specifically with gns3 .
I'm a very strong believer in practical learning. Think about it, when you were a child, did you go to university or school to learn how to ride a bike? Typically you learnt how to ride a bike by riding a bike and falling off a few times, making mistakes. But as you practiced you got better and better at riding a bike.
I think the same is true for any other skill that you want to gain and any other knowledge that you want to obtain. The best way to do it is to just do it , make mistakes, pick yourself up and try again. And with that in mind I'm going to show you how quickly you can get programming a Cisco network using Python.
In Google I've done a search for Python telnet and my first hitch is the telnet library or telnet client available in Python 2.7. Now there's a large debate in Python community about which version of Python you should learn. Python 2.7 is being replaced by Python 3. But notice on the Python website you can still download Python 2.7 and a lot of operating systems and network devices have version 2.7 by default. I'm going to show you both Python 2.7 and python 3 as part of these videos or as part of my GNS3 Python course. You may only have Python 2.7 available so it's good to know that but you should also learn Python 3 for the future.
So notice the simple script that we can copy from the Python documentation. We'll start off with a script and start programming our GNS3 topology.
In GNS3, I'm going to drag a iOS router to the workspace as well as an iOSv switch. These devices take a while to boot up, so to allow my docker containers to connect to the Internet quickly, I'm going to use a layer 2 switch. One of the docker containers available is in a blue 2 container and that's what I'm going to use in this topology rather than trying to get python running on your Windows PC or trying to get Python working on other operating systems. It's going to be a lot quicker for us just to use a docker container and add that to our GNS3 topology.
Again, my belief is start or learning as quickly as you can, make mistakes and learn from that. Don't get hung up with trying to learn the best way to do everything right away. Just get started.
Some people believe that they need to have a degree to become a programmer or use programming skills in networking. I don't necessarily agree with that. Just get started.
So on the Ubuntu machine I'm going to edit to the config. I'm going to set this device to use DHCP and click Save and click start. To boot up the network, I'm going to open up a console
to each device.
Now again the Cisco devices will take a while to boot up but our docker container has already booted up and we can already ping google.com even though the switch and the router are still
booting.
So how to get update? We will get update our references in ubuntu, that's done, will install Python.
In this first example I'm going to install Python 2.7. So Python version of Python that we're using is 2.7. 1. So here is the script that we're going to start off with it's not perfect. What we will be doing now is not necessarily the most optimized way of implementing a script like this but the
idea there is, we want to get started, get it working by for instance creating a loop back on the router and configuring VLANs on the switch and then we can build on our script and optimize it.
I'm going to use nano to create a file so let's call this python Router1 script 1 to start off with. And then I'm going to paste the code off the internet into nano. so we’re importing modules here get passes telnet library.
The device that we're going to telnet to is going to be the router. So we need to configure the router's IP address, username and password and other details for when the script telnets
to the router. So before we continue with our script let's configure the network devices. See here's the router it's booted up. Now I'll bypass the initial configuration dialog.
Transcription limited by TH-cam.
Lovin this Python content and look forward to more.
When will the Python specific course be available?. Hopefully not too expensive but whatever it is "shut up and take my money!!!"
Thank you once again.
Al, thank you for the comments! Great to get feedback like this :) I hope to get initial versions of the Linux and Python courses out in the next few weeks. I' ll probably release a starter versions so people can access content quicker and then continue to add content to them like I do with the TH-cam videos. Thoughts?
David Bombal sure sounds like a solid plan. please let the channel know where this can be purchased and hopefully it will be on Udemy and GNS3 Academy.
Are you going to cover things like Netmiko and NAPLAM?.
I would also love to see an Ansible series and would also pay for good useful practical training on Ansible.
Thank you and I'm also running through your CCNA Voice series at the moment and really enjoying that content but for very different reasons.
Thanks again.
Looking forward in youtube as well as GNS3 academy...more and more. Very soon , i would like to start network programming using python scripts configuring different types network topologies...
I will cover both Netmiko and NAPLAM and more. Initially I'll cover the basics and then get deeper and deeper. Ansible will be a separate course, but that is also on my list to create asap.
Thank you! Lots of videos coming ...
It took me about a week to Learn GNS3 and get all of this to work through trial and error. I learned so much along the way about dockers, dynamits, virl, getting DHCP to work in for ubuntu, linux commands, Nano and alot more. I didn't know what any of the was when I started and today I was able to get this python script to work in my GNS3 environment. Thanks a lot this has shown me that I do have what it takes to further my IT career. Just start is a great motto. Thanks
Simply the best introduction to Network programming with Python. Thanks a lot.
The best video tutorial for network engineer to start learning python.
Thank you. I appreciate it!
here agreed Absolutely!
Thank you so much sir, the mistake I made was using Eve-ng community edition. Switched back to GNS3 and I am using your videos. Now I have a lot of catching up too do. I really appreciate your efforts. A big thank you
Faeiz Mohammed I am curios. What was the issue with Eve-Ng community version?
Abdi Mohamed EvE Ng community has limitations unlike GNS3, also I switched to Ubuntu Linux to run GNS3 and I don’t run it on windows
Tks you, after I bought your course on udemy (python for networking), I combined automation skill with 5 years of network exp, then nearly x2 my income with new position of network admin for a securities company. Really helpful
i got recently CCNA certified and this is the first time i see programming and networking work together , this is so freakin magical !
i can only imagine the fun and euphoria i will feel having my router on GNS3 configured with loopback using a simple python script :D
thanks for the motivation to move forward in network automation however i would love to see things that python can do that are not similar to just telneting and directly configuring the routers
Really happy to hear that the video inspired you!
This was fantastic. I've been trying to pickup programming for a while (as a network engineer), but just couldn't see "WHY" I should be doing it. After seeing this, seeing the "why", it's now motivating to learn Python, and furthermore know where to start! Thanks for the great vid.
Thanks Ben! All the best with your network automation journey.
Finally i'm up and running with GNS 3 on ubuntu 16.04, thanks for this great tutorials
""the best way to do it ....is to do it""....excellent encouragement..
I think you will change my life...as a netops guy this is Gold
I went through the video, excellent introduction as well as re-enforcing
the just do it approach. As many of us experienced network engineers recall this
particular example is similar to using inspect or a ZOC like terminal emulator with
a macro recorder that utilizes a script language. In ZOC for example you record
your steps first on the device, then you just edit the macro recording for
changes/variables(username, interface numbers, IP addresses etc.), resulting in
REXX macro that I just run from ZOC to the router or switch. Very easy and powerful
and I had to do this to deploy QoS commands to over 10,000 ports on a global
network 6 years ago.
The Python approach is especially flexible when you leverage
the python interpreter on the actual network device’s OS. Since most network OS
will be Linux based in one form or another will mostly likely now have a python
2.x or 3.x interpreter built in, just as
Davide showed on the UBUNTU container. So,
for some of the more OS specific commands you can just add something to the effect of “import cisco” and
use the same concepts David outlined but on the device directly with script objects
such as cisco.cli('show hostname') or cisco.cli("config t") or cisco.cli("interface
vlan2") for example. You can save
and run the script directly on the Cisco device for operators to run to make
changes locally(a menu too), or run it from other network devices or centrally
as David showed. I did this on a Nexus NXOS on 7k and 5k a few years back. Other
venders will have their libraries as David mentioned that can be imported and
run on the device directly or you access them remotely. Very powerful indeed.
Great video and I look forward to the others. I always learn
something from David.
Great comments Jeff! Thank you for the input :)
Simply WOW!
I recently discovered David's courses. I have to say, I finally see the light!
This video was EXCELLENT! Is the first time I see Python applied to networking hands on! Thank you for that David!!!
Thanks Robert! Glad to hear you are enjoying the videos :)
Best intro to Python for Network so far. Keep up the good work!
Thank you. Stay tuned!
Love theses videos very clear and easy to understand unlike the constant issues you get with GNS3, I am constantly being bogged down with new issues which take days sometimes weeks to resolve totally hindering and slowing down the studying and learning process for me
Outstanding training methods David , it does not get any easier and any better than this. Gratitude Sir !
Thanks for the comment!
This is awesome!!! I managed to create my first ever script (I have zero programming experience). Had a few hiccups with getting it to work with windows and understanding the logic but once I got it working I was able to perform a test script to log into a device at work and do a show command then exit.
Thank you so much for the awesome tutorial!
Congratulations! Thank you for watching.
I'm a voice engineer always looking for better ways of doing what I do for many years. It's was inevitable that I needed to learn a new skill set. I was specifically looking for content your are providing. Thank You!!
Thank you for watching Joon!
David, I finally got around to trying this on a actual Cisco 3560 switch and IT WORKED Flawlessly!! Thank You for all of your informational video and especially the blogs with the DEV NET OPS, I hope it doesn't take me as long to try those out. Thanks again. You Rock!!
Thank you! And well done!
I really liked the way you are explaining things for the people who don't have any coding experience. Thanks for sharing videos about python.
Glad it was helpful!
Thank you for sharing this knowledge, been a fan of your video's for a while and wanted to thank you as your video's are awsome !! keep the good work
now I am very interest to learn python after see your lecture. ..thank you. .
I like the way you are teaching for network engineer who are Python beginners.
Glad to hear that and thank you :)
Thanks David for sharing your knowledge! I also love “practical learning” especially via TH-cam. This series that you have posted is an excellent way to have a feel of “networking programming”. Keep up the good work!
Thank you Albert! I'm glad to hear you are enjoying the videos :)
You should have been in the Queen's Birthday honours list. David Bombal MBE ;). Thanks for the superb videos you put out on various Network tech, but this has taken me to the next stage and opens the door to so much more.
This is so beautiful. Thanks David!
Thanks a lot!!!
These is like teaching a Network Engineer how take baby steps towards python. Best help one can use to get started.
Thank you! Each journey starts with one step :)
Ok, I'm hooked now! Thanks David, great tutorials. I want to start using python!
That's great news Ken! Lots more programming coming in the next few days :)
Hey David! you are doing a good job man, keep up the spirit. This is going to help a lot of network engineers across the globe. Love from INDIA
Hi David,
Thank you very much for all your hard work and this valuable set of learning material. i am enjoying the course on GNS3
You're very welcome, thanks for the feedback Newton!
10:44 - very neat, thanks for this tutorial
Sir,
Your Videos are very good that motivate me to learn the python. Because I am Network Administrator and I love to learn the New Technologies specially Cisco, Linux, GNS3, Python. Keep motivate us. Thanks
Thank you! I am glad you are enjoying my videos Muhammad!
you will need to learn Cisco, Linux ,Gns3 and Python to have a better idea of what David is doing because he is using all those tools and command here!
Go easy on yourself and try to learn one by one
amazing David! straight forward!
Thank you! I have GNS3 running on Ubuntu. If my thinking is correct, I should be able to run the python scripts without adding a Linux box into the GNS3 environment. Years ago I have used bash scripting to send IP, username, password and commands using Expect . And often gathering the show output for analysis. I'll look for your training material after I finish my intro python class.
Great Content David... Congrats
Extremely useful introduction, that you very much.
Wow beautiful! I had not seen this video!!!!
Excellent video! You just earned a new subscriber, cheers!
Thanks David - You are awesome 👏🏻
Damn! David why you are so great! Your a rockstar!
Hello Mr. David, thank you so much for this tutorial! And the Amazing part of all your videos are that on every step, you always motivates the learner. Thanks again!
Mr.Bombal biggest thanks (sorry for my bad english), good words about just do it... wery good practical learning...
Thank you! You English is great... no need to apologise :)
You are the best .. Very simple explination to a hard subject .. Can yiu please recommand books that are related to this ?
Quick word of warning just in case people are trying the copy and paste the script the formatting in the description does not work exactly. Remember to check it's exactly same as the video.
The if password loop is where you need to be careful!.
Thanks again David.
Thanks for the feedback Al. I have now moved all code examples to GitHub, so hopefully things have now improved.
great, everything works fine so far... thank you so much... salute from Zurich
You're welcome Gabi!
Excellent David thank you!!
Cheers for the attention to detail 🍻
It'd be cool if you had explained your GNS3 configuration
Very detailed explanation.
your all video is very very very help full ..thanks a Ton "David Bombal"
Thank you for watching Rezwan!
awesome stuff to learn David.....thanks a ton for this....
i love the way you teach us .... great
Thank you. I appreciate it!
David Bombal!!! a big thank you
Thanks, Juan!
Great video brother David!
Thank you!
Thanks a lot for this cours is very important content
Hi David, Its nice video series. Thanks shring such a fantastic video. Moreover i have query, Whicgh version of GNS3 required for python?
Simply great video..Many thanks David. Loved it...looking forward for more network programmability using python scripts
Thank you! Lots of Python and network programmability videos in the queue :)
Many thanks...Looking forward on this. And trying to best to follow with you...
David, What about to use python3.X, pyhton 2.X is will has not anymore support since Jan/2020? The scripts you sre using will not work with python 3.X anymore, right??
Thanks you a lot!! im a really beegginer to code. your video really empower me to do more !!
Thanks Christian, I'm glad that helped.
Hello David, thank you very much for the great video, very interesting and informative. I am curious about the way you set up the network on GNS3 (NAT) to reach out the Internet I am sure there are plenty of documentation on the internet about how to accomplish that, but I like the way you explain things therefore I was wondering if you have anything like that to look at? Again, I will be setting up a lab in GNS3, including Linux containers or just VMs in virtualbox, network devices routers and switches, and access to the outside internet on my home network. Thank you in advance.
Watch this: th-cam.com/video/2zeoC2Q4mW0/w-d-xo.html and this: th-cam.com/video/Gpje9PV1j8U/w-d-xo.html
Hello David, that is exactly what I was looking for! thank you! will keep in touch!
Very nicely walked through, thanks.
Thank you
David, what comes in the courses? I've been working Cisco Networking for almost 20 years and want to get into the programming and the newer SDN technologies. Even though I've worked in the field this long I still haven't had a certification higher than CCNP because of issues with testing.
I worked in a server farm bigger than a football field but that was old Cisco when version 11 and 12 were king. Other than your courses, what are other good materials to combine with what I know and move forward?
Nice video. Will all cisco ios be able to be automated using python?
Thanks David ...:) i was searching for this kind of tutorial....
Thank you Prabhat! Glad to hear the tutorial was helpful :)
Great video David!
Thank you for watching :)
Sir,
Can we write a script which takes ping rtt value & wait for 2*rtt time and again ping?
Good stuff!!! This could have been a great thing to use to make QoS changes to 260ish routers I had to do a while back.
Thank you for watching. Network automation can really save time :)
Thank you so much David
I can only thank you. thank you, sir
You're very welcome :)
Great video David and thanks for share your acknowledge!
Thank you for watching Carlos!
Good explanation David😊 Thanks much!
Thank you!
Great video. Thanks David.
Thanks. Stay tuned.
Hi David....Thanks for shared video. Could you please share how to install VM and inside VM how to install GNS3 and required application associated with that for to learn python for network...Just I am asking how to add doctor container and other switch and router iOS.Pleade share the link you already uploaded......Note: if any one knows pls share the link.
Dave, good job on the video, but I have 3 basic questions.
1. How did you create Ubuntu inside a docker container?
2. How exactly did you configure the NAT cloud, I assume that Ubuntu was using one interface to communicate with the GNS3 switches and another to be able to get to the Internet for the apt-get repos.
3. What served as the DNS server for the router?
Regards,
John.
Thank you John. Please search the videos on my channel that show options like these and much more: Ubuntu: th-cam.com/video/ii1ynMwXiE8/w-d-xo.html and NAT: th-cam.com/video/2zeoC2Q4mW0/w-d-xo.html
The router was not using DNS in this topology.
I'm sorry, I meant DHCP. Thank you, I will look into the links that you have provided.
The NAT device is acting as a DHCP server.
Excelente! Gracias por el contenido. Saludos desde Venezuela
De nada Jose! Enjoy the videos :)
YOU ARE THE MAN DAVID
Thanks!
Honestly i am still a beginner ( in python , makes me struggle in some parts ) , but this course made me transition into someone else with practical skills , Sir if you ever release a new cisco + python programmability course ( Paid or free ) , immediately i will be the first customer to sign in ..looking forward to it
Regards
I am working on a course. Thank you for the feedback :)
Very nice. TY David.
Thank you Jason
Hello David,
Thanks for the course. it is very helpful for the network engineer who are python beginners.
could you pls suggest from where I should get Switch IOS for GNS 3, Ubuntu container.
Thanks,
Swapnil
Wow, really cool! Thank you for sharing this knowledge!
Thanks Anthony, I'm glad that helped.
That's incredible.
Thank you
Thanks for the comment, you're welcome!
Thanks david for showing us the "Python way" but i don't get the point in it, when you can run these commands in cisco IOS in half the time
Hi, Thank you for doing such great work and for helping the beginners.
I have a case scenario where I am copying the config of various network devices (per device script :( but unable to compare the new and last configs and generate a diff report. In an ideal world, I would like to send the differences to an email. or I can print the the diff from the device and email.
Please advise me if that is possible if yes, please assist me.
Thank you :)
What are the alternative for CISCO templates ?
Hi David,
All your videos are awesome and really helpful
I wanted to learn more by purchasing course on GNS3 academy.
You provided a link for $10 course but when i opened, it shows $39
Thanks David, that is great videos.
Thanks :)
Dear David,
What's " if password: " mean?
Thank you for your valuable videos, Could you please share with me the lab preparation ? How to prepare this lab from scratch ?!
we need to find a way to get the ios for the machines he's using.
Can we create a While Loop in this case?
thanks
Hi David, Great content. I have been using your videos here and udemy to get started. But do you have a video on using Ansible/Netmiko in Pycharm on windows. I am trying to get a single workspace for all python scripts/playbooks. I can do REST calls in Pycharm, but know how to do Cli calls from the same environment - or do they not work in windows?
There's no specific videos using PyCharm, and I'm not sure whether or not he's used it (I know I haven't).
Amazing tutorial. Thank you. I have a question how does Python really help speed up configuration? I think putting everything in a notepad and copying is much faster. Please prove me wrong if I am.
This is the python tutorial that Ive been looking for. Thank you so much David. You're a very good teacher - explained very well. I just have quick question, when I close my gns3 project... I have to re-install update and python again each time. Is there a way to save this into ubuntu docker? Cheers!
Thank you. See this video: th-cam.com/video/jclRq0MQAKE/w-d-xo.html
Hello David, Great Video! But what version of GNS3 should i use? There is actually a version that i can run that shows devices represented here? It is version 2.0.2? If there is a tutorial to get this configured please let me know.
2.1 is the latest, but you might want to hold off until 2.1.1 launches (unless you've already updated since your post).
Nice intro David !
Thanks Dan! Great to see you here :)
Hi David,
Please see my script below
import getpass
import sys
import telnetlib
HOST = "192.168.131.130"
user = raw_input("Enter your telnet username: ")
password = getpass.getpass()
tn = telnetlib.Telnet(HOST)
tn.read_until("Username: ")
tn.write(user + "
")
if password:
tn.read_until("Password: ")
tn.write(password + "
")
tn.write("enable
")
tn.write("cisco123
")
tn.write("conf t
")
tn.write("int loopback0
")
tn.write("ip add 1.1.1.0 255.255.255.0
")
tn.write("end
")
tn.write("exit
")
print tn.read_all()
It asks me password and when I enter password it gets stuck and get the below error. Please help me otherwise I can't proceed.
Traceback (most recent call last):
File "pythonR1script1", line 14, in
tn.read_until("Password: ")
File "/usr/lib/python2.7/telnetlib.py", line 293, in read_until
return self._read_until_with_poll(match, timeout)
File "/usr/lib/python2.7/telnetlib.py", line 342, in _read_until_with_poll
return self.read_very_lazy()
File "/usr/lib/python2.7/telnetlib.py", line 454, in read_very_lazy
raise EOFError, 'telnet connection closed'
EOFError: telnet connection closed
Thanks very much David for sharing your knowledge! from RD
Thank you Luis!
you are the best!!!
Thank you for your those inspiring words
You're welcome! Much appreciated :)
Thanks, great tutorials!
Thank you for watching!
Thanks David this is the beginning of my carrier in network automation ;)
is this kind of a Good Network engineer learning Python to improve his work... or Strong Python programmer pickup domain knowledge of Networking and move into specific industry ?
Thanks David for your video! The question is, if i use unetlab instead of gns3, will it work?
You will have to ask their support that question. I am demonstrating on GNS3 only in these videos.
Just amazing