GNS3 Talks: Python for Network Engineers with GNS3 (Part 11) - Paramiko, SSH, Python and Cisco

preview_player
Показать описание

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.

================================
Script on GitHub:
================================

================================
Install Paramiko:
================================
apt-get update
apt-get install python -y
apt-get install build-essential libssl-dev libffi-dev -y
apt-get install python-pip -y
apt-get installpython-dev # You may need to install this as well
pip install cryptography
pip install paramiko

================================
Al's GNS3 community entry:
================================

Transcription:

Since I started recording the Python for Network Engineers videos, the number one request has been to demonstrate the use of SSH with Python and Cisco devices.

So as we can see here, there are a number of requests for SSH and Paramiko.
This is one of multiple videos teaching you network programmability using Python and GNS3.
Al, as an example has even gone further and created an entry on the GNS3 community showing you how to install Paramiko and Netmiko on the Ubuntu client that I've been demonstrating in these videos. So thanks Al for sharing.

I'm going to demonstrate how to install Paramiko using the steps that Al has shared on the GNS3 community.

In this topology I've got an Ubuntu docker container which I've configured to use DHCP. That's now booted and got an IP address from the NAT cloud.

So I'll demonstrate in a moment how to configure SSH on the switch and then we'll configure the Ubuntu client to use Paramiko and SSH to configure the switch. The module that I'm going to use for SSH is Paramiko.

I've written a script which I've linked below on github that imports Paramiko and uses SSH to connect to the Cisco switch and configure some options on the switch. We'll configure some loopback interfaces and then we'll run a loop to configure VLANs on the switch.
So I'm hoping that this video and script help you configure network devices using SSH rather than just relying on telnet.

Ok so the first thing we need to do is install Paramiko and Python on this Ubuntu client. This Ubuntu client has just booted up, doesn't have any configuration apart from an IP address.
So what I'll simply do here is follow the list of commands that Al has put on the GNS3 community and I'll reference the links below.

So install Python, install some additional software, install pip. I'll use pip to install cryptography and then we'll use pip to install Paramiko. You simply need to wait for the processes to complete. So install Paramiko here as well and I'll upgrade pip while I'm here.
So once again, Paramiko is now installed on this Ubuntu server.

So that's been done. I'll specify an enable password of cisco and in this example I'll configure a username of david password of cisco and give david level 15 privileges on the vty lines.

I'll use the login local command and transport input all. So SSH is now configured on the switch. what we can do now is have a look at our python script. So we're going to import Paramiko, we're also going to import a time you may want to add some delays in your script and that's what sleep allows you to do. So I'm sleeping one second before I'm outputting the session when I'm creating the VLANs on the switch.
Рекомендации по теме
Комментарии
Автор

The best Python course for Network Engineers is getting better and better.

robertpetrusevski
Автор

The best python videos I’ve found on YouTube regarding python automation for Network Engineers. Great content in getting started in network automation. I’ve been watching these videos all weekend.

prajez
Автор

Thank you very much!
When I watched these videos this week, I thought: How can I take advantage of this in my Work? Well I found the video about backups. It was fantastic. I was just thinking in that use. Then I told myself: "It is important the security. Remember the risks about telnet". So today you upload this great video

DiegoDominguezTapia
Автор

Thank you David for mentioning my link.
I thought it may help someone but was not expecting it to be shown on a video.

Can't wait for the new site and full training course to be released. Put me down for a place on this anyway as I'm liking following along with this series and reading some of the comments are very inspiring as I have seen several network engineers mention how useful this is in getting started into Python and automation without being totally overwhelming.

Thanks so much for taking the time to make these videos.

BTW also a big Sublime Text fanboy!!!.

alreid
Автор

The whole time I've been watching this series, I was thinking, why use telnet when ssh is what's used most of the time? perfect!

Just-Browsing-
Автор

Wow, thank you for these videos! I've been trying to learn Python for the past few months, on and off...I'm not a coder by any means, I know a basic bit of HTML but what I am pretty well versed in is Cisco IOS CLI (I hold the CCNA R&S/CCNA SECURITY/ Cisco SCYBER/ CCNA CYBER-OPS) and I'm pretty familiar with Linux. These videos not only taught me ALOT of awesome techniques for automating configurations, but I even have a much greater understanding of Python scripting in general. I'm going to go over other Python video courses and Codeacademy work I've done and I have a very good feeling it will make much greater sense! Thank you, you are an excellent instructor!

anthonysbarat
Автор

you videos about python are very help full to start learn network automation

saadahmadkhan
Автор

Such an excellent series! Thanks for sharing -

nicolasfrancia
Автор

Cheers David for another great video !!!

refaiabdeen
Автор

excellent video series thank you for presenting a very practical approach.

vaibhaveng
Автор

exactly what I needed.. very well explained

f-rbvl
Автор

Execelente video, fue de mucha ayuda, era lo que estaba tratando de hacer desde año pasado, gracias.

collito
Автор

Thanks.

Just wonder if there's one for expect
Before pushing in next line

andyng
Автор

Hey David,

I'm receiving error messages when trying to download paramiko/cryptography module on my Ubuntu Docker. Is there an updated walkthrough or video series on how to install paramiko in GNS3? I've also reached out to the GNS3 community forum for assistance on my error messages as well.

Thank for all the content and information so far. It's been very helpful!

Best,
Kirby

kirbs
Автор

Thank you very much
it's good video for me to start the road of python, hope you can publish more easy understanding video

yuanjie
Автор

ssh video is very good david thank you.You are explaining in such a way that any layman can understand keep doing the great work. I have one query regarding time.sleep, in production environment the configurations will be pretty huge and we are not aware the time required to execute the command.So is there any way to wait until till the command gets executed fully before proceeding the next command without specifying the time manually

kishorekannanp
Автор

Very informative videos David. I have a query. How do we use paramiko to form an ssh connection with the router(and run commands on this router) that is connected via switch?

hamidrazahashmi
Автор

David, your course is amazing!

Since we're talking automation, I got bored to install the tools everytime I had to close the project in GNS3, so I've created a Docker Ubuntu image oriented towards "Python for network engineers" scope. It has all necessary tools installed. I've tested for 2-3 days and it works fine.



Thanks again David for taking the time and effort to create these videos!

calinc.
Автор

I tried installing paramiko, python and all but it could not work.

patriceminimah
Автор

Hi David. Greetings from Brazil. Amazing video for SSH my friend.
Do you have any option to save an output for a command like "show tech-support"?
The size is more than 100Mb. How can I save in a file?

polliluiz