#NEWLINE# def get_ssh( self , action = None ) : #NEWLINE# #INDENT# host = self . node . get ( 'host' ) #NEWLINE# user = self . node . get ( 'user' ) #NEWLINE# password = self . node . get ( 'password' ) #NEWLINE# port = int ( self . node . get ( 'ssh-port' , os . environ . get ( 'PONI_SSH_PORT' , 22 ) ) ) #NEWLINE# if ( not host ) : #NEWLINE# #INDENT# raise errors . RemoteError ( ( "%s: 'host' property not defined" % self . node . name ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not host ) : #NEWLINE# #INDENT# raise errors . RemoteError ( ( "%s: 'user' property not defined" % self . node . name ) ) #NEWLINE# #UNINDENT# #UNINDENT# if self . key_filename : #NEWLINE# #INDENT# key_file = self . key_filename #NEWLINE# if ( not os . path . isabs ( key_file ) ) : #NEWLINE# #INDENT# key_file = ( '%s/.ssh/%s' % ( os . environ . get ( 'HOME' ) , key_file ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# key_file = None #NEWLINE# #UNINDENT# self . log . debug ( 'ssh connect: host=%s, port=%r, user=%s, key=%s' , host , port , user , key_file ) #NEWLINE# end_time = ( time . time ( ) + self . connect_timeout ) #NEWLINE# while ( time . time ( ) < end_time ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# if ( not self . _ssh ) : #NEWLINE# #INDENT# ssh = paramiko . SSHClient ( ) #NEWLINE# ssh . set_missing_host_key_policy ( paramiko . AutoAddPolicy ( ) ) #NEWLINE# ssh . connect ( host , port = port , username = user , key_filename = key_file , password = password ) #NEWLINE# self . _ssh = ssh #NEWLINE# #UNINDENT# return ( action ( self . _ssh ) if action else self . _ssh ) #NEWLINE# #UNINDENT# except ( socket . error , paramiko . SSHException ) as error : #NEWLINE# #INDENT# remaining = max ( 0 , ( end_time - time . time ( ) ) ) #NEWLINE# self . log . warning ( '%s: ssh connection to %s failed: %s: %s, retry time remaining=%.0fs' , self . node . name , host , error . __class__ . __name__ , error , remaining ) #NEWLINE# self . _ssh = None #NEWLINE# time . sleep ( 2.5 ) #NEWLINE# #UNINDENT# #UNINDENT# raise errors . RemoteError ( ( '%s: ssh connect failed: %s: %s' % ( self . node . name , error . __class__ . __name__ , error ) ) )