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 (cherry picked from commit d616e61723207ed0e29ea69d67908a00ebf2cdfb)
This commit is contained in:
parent
e454b27852
commit
1b04cf979f
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user