當前位置: 首頁>>代碼示例>>Python>>正文


Python Network.getIPsForHostName方法代碼示例

本文整理匯總了Python中DIRAC.Core.Utilities.Network.getIPsForHostName方法的典型用法代碼示例。如果您正苦於以下問題:Python Network.getIPsForHostName方法的具體用法?Python Network.getIPsForHostName怎麽用?Python Network.getIPsForHostName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DIRAC.Core.Utilities.Network的用法示例。


在下文中一共展示了Network.getIPsForHostName方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: getSocket

# 需要導入模塊: from DIRAC.Core.Utilities import Network [as 別名]
# 或者: from DIRAC.Core.Utilities.Network import getIPsForHostName [as 別名]
 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 )
開發者ID:JanEbbing,項目名稱:DIRAC,代碼行數:36,代碼來源:SocketInfoFactory.py


注:本文中的DIRAC.Core.Utilities.Network.getIPsForHostName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。