in src/sagemaker_training/smdataparallel.py [0:0]
def _can_connect(host, port=22):
# type: (str, int) -> bool
"""Check if the connection to provided ``host`` and ``port`` is possible.
Args:
host (str): Hostname for the host to check connection.
port (int): Port name of the host to check connection on.
"""
try:
logger.debug("Testing connection to host %s at port %s", host, port)
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host, port=port)
logger.info("Can connect to host %s at port %s", host, port)
return True
except Exception: # pylint: disable=broad-except
logger.info("Cannot connect to host %s at port %s. Retrying...", host, port)
return False
finally:
client.close()
logger.info("Connection closed")