Padheye.com : Discover Excellence

The Path To Discover Excellence.

Thursday, 25 February 2016

Writing an SSH Driver with Python

 

Starting the file

The first thing you want to do is ensure you have access to all the libraries you need in your file. Thus, at the very beginning, include these libraries:

  • Paramiko client allows you to actually connect to devices with SSH
  • AuthenticationException allows you to catch problems with the authentication
  • Threading and Time allows us to perform timeout function, like read all text until timeout
  • re brings regular expressions, required for the expect function
  • The driver allows you to structure your SSH Driver in a standard way so that you can later  create connections independent from the underlying protocol
  • DriverError helps you to notify other classes if you encountered an error during the connection

To do all of that, you can use this code at the beginning of your ssh.py file.

from paramiko import client
from paramiko.ssh_exception import AuthenticationException
import threading
import time
import re
from .driver import Driver, DriverError

No comments:

Post a Comment