def ssh_connect(host, timeout=10):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
error_message = None
try:
ssh.connect(host, username='root', key_filename=SSH_KEY_FILENAME,
timeout=timeout)
except (AuthenticationException, SSHException) as e:
error_message =\
'{0}.\nCheck hostname, check that user from which '.format(e) +\
'Kuberdock runs (usually nginx) has ability to login as root on ' \
'this node, and try again'
except socket.timeout:
error_message = 'Connection timeout({0} sec). '.format(timeout) +\
'Check hostname and try again'
except socket.error as e:
error_message =\
'{0} Check hostname, your credentials, and try again'.format(e)
except IOError as e:
error_message =\
'ssh_connect: cannot use SSH-key: {0}'.format(e)
return ssh, error_message
评论列表
文章目录