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

Published: 15 April 2017
on channel: David Bombal
52,426
875

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:    • Python Programming for Network Engineers  

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:
================================
https://github.com/davidbombal/python...

================================
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:
================================
https://gns3.com/discussions/docker-u...

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 as an example the Ubuntu client can ping google.com. The Cisco switch in this topology has just booted but has no configuration on it.

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.

This is a Python implementation of the SSH version 2 protocol which provides both client and server functionality. You can find out more information about Paramiko on paramiko.org or docs.paramiko.org.

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.

In this example I'm using sublime text which is a great text editor. You can find out more about sublime text on their website sublimetext.com. Unfortunately no one pays me money to recommend these products. This is just stuff that I've found useful and you may be interested in knowing about as well.

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 follow these steps if you want to install Paramiko on your Ubuntu client. So that's the Ubuntu device configured. We now need to configure the switch for SSH. So to set up a SSH on the switch the first thing we need to do is configure a hostname which we've done already. Then we're going to specify a domain name which in this case I'm going to call CCIE Python.com. Then we're going to generate some keys so cryptic key generate RSA. I'll use 1024 as the number of bits.

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.


Watch video GNS3 Talks: Python for Network Engineers with GNS3 (Part 11) - Paramiko, SSH, Python and Cisco online, duration hours minute second in high quality that is uploaded to the channel David Bombal 15 April 2017. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 52,426 times and liked it 875 visitors.