|
|
@ -40,8 +40,19 @@ class AutoAddPolicy(paramiko.client.MissingHostKeyPolicy): |
|
|
|
""" |
|
|
|
""" |
|
|
|
lock = threading.Lock() |
|
|
|
lock = threading.Lock() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def is_missing_host_keys(self, client, hostname, key): |
|
|
|
|
|
|
|
k = client._host_keys.lookup(hostname) |
|
|
|
|
|
|
|
if k is None: |
|
|
|
|
|
|
|
return True |
|
|
|
|
|
|
|
host_key = k.get(key.get_name(), None) |
|
|
|
|
|
|
|
if host_key is None: |
|
|
|
|
|
|
|
return True |
|
|
|
|
|
|
|
if host_key != key: |
|
|
|
|
|
|
|
raise paramiko.BadHostKeyException(hostname, key, host_key) |
|
|
|
|
|
|
|
|
|
|
|
def missing_host_key(self, client, hostname, key): |
|
|
|
def missing_host_key(self, client, hostname, key): |
|
|
|
with self.lock: |
|
|
|
with self.lock: |
|
|
|
|
|
|
|
if self.is_missing_host_keys(client, hostname, key): |
|
|
|
keytype = key.get_name() |
|
|
|
keytype = key.get_name() |
|
|
|
logging.info( |
|
|
|
logging.info( |
|
|
|
'Adding {} host key for {}'.format(keytype, hostname) |
|
|
|
'Adding {} host key for {}'.format(keytype, hostname) |
|
|
|