Add destructor to SSHClient

Newer versions of paramiko require a client object to be explicitly
closed.  Fortunately, we wrap all of our use of paramiko client
objects in our own class.  Add a destructor to our class which
closes the client object.

Note, this has been tested to work (and is needed) even if a
connection is not established.

Change-Id: I5dff7ed254567968b42d053b85004769f8647ecb
This commit is contained in:
James E. Blair 2017-02-28 15:47:00 -08:00
parent 2216e349c0
commit d616e61723
1 changed files with 9 additions and 6 deletions

View File

@ -25,14 +25,17 @@ class SSHClient(object):
def __init__(self, ip, username, password=None, pkey=None,
key_filename=None, log=None, look_for_keys=False,
allow_agent=False):
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
client.connect(ip, username=username, password=password, pkey=pkey,
key_filename=key_filename, look_for_keys=look_for_keys,
allow_agent=allow_agent)
self.client = client
self.client = paramiko.SSHClient()
self.client.set_missing_host_key_policy(paramiko.WarningPolicy())
self.client.connect(ip, username=username, password=password,
pkey=pkey, key_filename=key_filename,
look_for_keys=look_for_keys,
allow_agent=allow_agent)
self.log = log
def __del__(self):
self.client.close()
def ssh(self, action, command, get_pty=True, output=False):
if self.log:
self.log.debug("*** START to %s" % action)