Exemple #1
0
 def getSocket( self, hostAddress, **kwargs ):
   hostName = hostAddress[0]
   retVal = self.generateClientInfo( hostName, kwargs )
   if not retVal[ 'OK' ]:
     return retVal
   socketInfo = retVal[ 'Value' ]
   retVal = Network.getIPsForHostName( hostName )
   if not retVal[ 'OK' ]:
     return S_ERROR( "Could not resolve %s: %s" % ( hostName, retVal[ 'Message' ] ) )
   ipList = List.randomize( retVal[ 'Value' ] )
   for i in range( 3 ):
     connected = False
     errorsList = []
     for ip in ipList :
       ipAddress = ( ip, hostAddress[1] )
       retVal = self.__connect( socketInfo, ipAddress )
       if retVal[ 'OK' ]:
         sslSocket = retVal[ 'Value' ]
         connected = True
         break
       errorsList.append( "%s: %s" % ( ipAddress, retVal[ 'Message' ] ) )
     if not connected:
       return S_ERROR( "Could not connect to %s: %s" % ( hostAddress, "," .join( [ e for e in errorsList ] ) ) )
     retVal = socketInfo.doClientHandshake()
     if retVal[ 'OK' ]:
       #Everything went ok. Don't need to retry
       break
   #Did the auth or the connection fail?
   if not retVal['OK']:
     return retVal
   if 'enableSessions' in kwargs and kwargs[ 'enableSessions' ]:
     sessionId = hash( hostAddress )
     gSessionManager.set( sessionId, sslSocket.get_session() )
   return S_OK( socketInfo )
Exemple #2
0
  def getSocket( self, hostAddress, **kwargs ):
    hostName = hostAddress[0]
    retVal = self.generateClientInfo( hostName, kwargs )
    if not retVal[ 'OK' ]:
      return retVal
    socketInfo = retVal[ 'Value' ]
    retVal = Network.getIPsForHostName( hostName )
    if not retVal[ 'OK' ]:
      return S_ERROR( "Could not resolve %s: %s" % ( hostName, retVal[ 'Message' ] ) )
    ipList = retVal[ 'Value' ] #In that case the first ip always  the correct one.

    for _ in xrange( 1 ): #TODO: this retry can be reduced.
      connected = False
      errorsList = []
      for ip in ipList :
        ipAddress = ( ip, hostAddress[1] )
        retVal = self.__connect( socketInfo, ipAddress )
        if retVal[ 'OK' ]:
          sslSocket = retVal[ 'Value' ]
          connected = True
          break
        errorsList.append( "%s: %s" % ( ipAddress, retVal[ 'Message' ] ) )
      if not connected:
        return S_ERROR( "Could not connect to %s: %s" % ( hostAddress, "," .join( [ e for e in errorsList ] ) ) )
      retVal = socketInfo.doClientHandshake()
      if retVal[ 'OK' ]:
        #Everything went ok. Don't need to retry
        break
    #Did the auth or the connection fail?
    if not retVal['OK']:
      return retVal
    if 'enableSessions' in kwargs and kwargs[ 'enableSessions' ]:
      sessionId = hash( hostAddress )
      gSessionManager.set( sessionId, sslSocket.get_session() )
    return S_OK( socketInfo )