当前位置: 首页>>代码示例>>Python>>正文


Python Utilities.Network类代码示例

本文整理汇总了Python中DIRAC.Core.Utilities.Network的典型用法代码示例。如果您正苦于以下问题:Python Network类的具体用法?Python Network怎么用?Python Network使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Network类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getSocket

 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,代码行数:34,代码来源:SocketInfoFactory.py

示例2: __reduceComponentList

 def __reduceComponentList( self, componentList ):
   """
   Only keep the most restrictive components
   """
   for i in range( len( componentList ) ):
     component = componentList[i]
     for j in range( len( componentList ) ):
       if i == j or componentList[j] == False :
         continue
       potentiallyMoreRestrictiveComponent = componentList[j]
       match = True
       for key in component:
         if key not in potentiallyMoreRestrictiveComponent:
           match = False
           break
         if key == 'Host':
           result = Network.checkHostsMatch( component[key],
                                             potentiallyMoreRestrictiveComponent[key] )
           if not result[ 'OK' ] or not result[ 'Value' ]:
             match = False
             break
         else:
           if component[key] != potentiallyMoreRestrictiveComponent[key]:
             match = False
             break
       if match:
         componentList[i] = False
         break
   return [ comp for comp in componentList if comp != False ]
开发者ID:sbel,项目名称:bes3-jinr,代码行数:29,代码来源:ComponentMonitoringDB.py

示例3: __discoverURL

  def __discoverURL(self):
    """ Calculate the final URL. It is called at initialization and in connect in case of issue

        It sets:
          * self.serviceURL: the url (dips) selected as target using __findServiceURL
          * self.__URLTuple: a split of serviceURL obtained by Network.splitURL
          * self._serviceName: the last part of URLTuple (typically System/Component)
    """
    # Calculate final URL
    try:
      result = self.__findServiceURL()
    except Exception as e:
      return S_ERROR(repr(e))
    if not result['OK']:
      return result
    self.serviceURL = result['Value']
    retVal = Network.splitURL(self.serviceURL)
    if not retVal['OK']:
      return retVal
    self.__URLTuple = retVal['Value']
    self._serviceName = self.__URLTuple[-1]
    res = gConfig.getOptionsDict("/DIRAC/ConnConf/%s:%s" % self.__URLTuple[1:3])
    if res['OK']:
      opts = res['Value']
      for k in opts:
        if k not in self.kwargs:
          self.kwargs[k] = opts[k]
    return S_OK()
开发者ID:marianne013,项目名称:DIRAC,代码行数:28,代码来源:BaseClient.py

示例4: initialize

 def initialize( self ):
   self.logger = gLogger.getSubLogger( "Monitoring" )
   self.logger.debug( "Initializing Monitoring Client" )
   self.sourceDict[ 'setup' ] = gConfig.getValue( "/DIRAC/Setup" )
   self.sourceDict[ 'site' ] = DIRAC.siteName()
   if self.sourceDict[ 'componentType' ] == self.COMPONENT_SERVICE:
     self.cfgSection = PathFinder.getSystemSection( self.sourceDict[ 'componentName' ] )
   elif self.sourceDict[ 'componentType' ] == self.COMPONENT_AGENT:
     self.cfgSection = PathFinder.getAgentSection( self.sourceDict[ 'componentName' ] )
     self.setComponentLocation( Network.getFQDN() )
   elif self.sourceDict[ 'componentType' ] == self.COMPONENT_WEB:
     self.cfgSection = "/WebApp"
     self.setComponentLocation( 'http://%s' % Network.getFQDN() )
     self.setComponentName( 'WebApp' )
   elif self.sourceDict[ 'componentType' ] == self.COMPONENT_SCRIPT:
     self.cfgSection = "/Script"
   else:
     raise Exception( "Component type has not been defined" )
   gMonitoringFlusher.registerMonitoringClient( self )
   # ExitCallback.registerExitCallback( self.forceFlush )
   self.__initialized = True
开发者ID:DIRACGrid,项目名称:DIRAC,代码行数:21,代码来源:MonitoringClient.py

示例5: __init__

 def __init__( self, optionsDictionary ):
   threading.Thread.__init__( self )
   self.__interactive = optionsDictionary[ 'Interactive' ]
   self.__sleep = optionsDictionary[ 'SleepTime' ]
   self._messageQueue = Queue.Queue()
   self._Transactions = []
   self._alive = True
   self._site = optionsDictionary[ 'Site' ]
   self._hostname = Network.getFQDN()
   self._logLevels = LogLevels()
   self._negativeLevel = self._logLevels.getLevelValue( 'ERROR' )
   self._positiveLevel = self._logLevels.getLevelValue( 'ALWAYS' )
   self._maxBundledMessages = 20
   self.setDaemon(1)
   self.start()
开发者ID:sbel,项目名称:bes3-jinr,代码行数:15,代码来源:RemoteBackend.py

示例6: __addFoundDefinedComponent

 def __addFoundDefinedComponent( self, compDictList ):
   cD = self.walkSet( self.__requiredSet, compDictList[0] )
   dbD = self.walkSet( self.__dbSet, compDictList[0] )
   now = Time.dateTime()
   unmatched = compDictList
   for dbComp in dbD:
     if 'Status' not in dbComp:
       self.__setStatus( dbComp, 'OK' )
       if dbComp[ 'Type' ] == "service":
         if 'Port' not in dbComp:
           self.__setStatus( dbComp, 'Error', "Port is not defined" )
         elif dbComp[ 'Port' ] not in [ compDict[ 'Port' ] for compDict in compDictList if 'Port' in compDict ]:
           self.__setStatus( compDict, 'Error',
                             "Port (%s) is different that specified in the CS" % dbComp[ 'Port' ] )
       elapsed = now - dbComp[ 'LastHeartbeat' ]
       elapsed = elapsed.days * 86400 + elapsed.seconds
       if elapsed > self.__maxSecsSinceHeartbeat:
         self.__setStatus( dbComp, "Error",
                           "Last heartbeat was received at %s (%s secs ago)" % ( dbComp[ 'LastHeartbeat' ],
                                                                                 elapsed ) )
     cD.append( dbComp )
     #See if we have a perfect match
     newUnmatched = []
     for unmatchedComp in unmatched:
       perfectMatch = True
       for field in unmatchedComp:
         if field in ( 'Status', 'Message' ):
           continue
         if field not in dbComp:
           perfectMatch = False
           continue
         if field == 'Host':
           result = Network.checkHostsMatch( unmatchedComp[ field ], dbComp[ field ] )
           if not result[ 'OK' ] or not result[ 'Value' ]:
             perfectMatch = False
         else:
           if unmatchedComp[ field ] != dbComp[ field ]:
             perfectMatch = False
       if not perfectMatch:
         newUnmatched.append( unmatchedComp )
     unmatched = newUnmatched
   for unmatchedComp in unmatched:
     self.__setStatus( unmatchedComp, "Error", "There is no component up with this properties" )
     cD.append( unmatchedComp )
开发者ID:sbel,项目名称:bes3-jinr,代码行数:44,代码来源:ComponentMonitoringDB.py

示例7: siteName

def siteName():
  """
  Determine and return DIRAC name for current site
  """
  global __siteName

  if not __siteName:
  
    #FIXME: does this ever happen that we have to use the defaultValue if getValue ???
    from DIRAC.Core.Utilities import Network
    # Some Defaults if not present in the configuration
    fqdn = Network.getFQDN()
    if len( fqdn.split( '.' ) ) > 2 :
    # Use the last component of the FQDN as country code if there are more than 2 components
      _siteName = 'DIRAC.Client.%s' % fqdn.split( '.' )[-1]
    else:
      # else use local as country code
      _siteName = 'DIRAC.Client.local'
    
    __siteName = gConfig.getValue( '/LocalSite/Site', _siteName )

  return __siteName
开发者ID:graciani,项目名称:DIRAC,代码行数:22,代码来源:__init__.py

示例8: getHostname

 def getHostname( self ):
   hostname = self.getOption( "/DIRAC/Hostname" )
   if not hostname:
     return Network.getFQDN()
   return hostname
开发者ID:IgorPelevanyuk,项目名称:DIRAC,代码行数:5,代码来源:ServiceConfiguration.py

示例9: __generateUniqueClientName

 def __generateUniqueClientName(self):
   hashStr = ":".join((Time.toString(), str(random.random()), Network.getFQDN(), gLogger.getName()))
   hexHash = md5(hashStr).hexdigest()
   return hexHash
开发者ID:DIRACGrid,项目名称:DIRAC,代码行数:4,代码来源:MessageClient.py

示例10: __findServiceURL

  def __findServiceURL(self):
    """
        Discovers the URL of a service, taking into account gateways, multiple URLs, banned URLs


        If the site on which we run is configured to use gateways (/DIRAC/Gateways/<siteName>),
        these URLs will be used. To ignore the gateway, it is possible to set KW_IGNORE_GATEWAYS
        to False in kwargs.

        If self._destinationSrv (given as constructor attribute) is a properly formed URL,
        we just return this one. If we have to use a gateway, we just replace the server name in the url.

        The list of URLs defined in the CS (<System>/URLs/<Component>) is randomized

        This method also sets some attributes:
          * self.__nbOfUrls = number of URLs
          * self.__nbOfRetry = 2 if we have more than 2 urls, otherwise 3
          * self.__bannedUrls is reinitialized if all the URLs are banned

        :return: the selected URL

    """
    if not self.__initStatus['OK']:
      return self.__initStatus

    # Load the Gateways URLs for the current site Name
    gatewayURL = False
    if self.KW_IGNORE_GATEWAYS not in self.kwargs or not self.kwargs[self.KW_IGNORE_GATEWAYS]:
      dRetVal = gConfig.getOption("/DIRAC/Gateways/%s" % DIRAC.siteName())
      if dRetVal['OK']:
        rawGatewayURL = List.randomize(List.fromChar(dRetVal['Value'], ","))[0]
        gatewayURL = "/".join(rawGatewayURL.split("/")[:3])

    # If what was given as constructor attribute is a properly formed URL,
    # we just return this one.
    # If we have to use a gateway, we just replace the server name in it
    for protocol in gProtocolDict:
      if self._destinationSrv.find("%s://" % protocol) == 0:
        gLogger.debug("Already given a valid url", self._destinationSrv)
        if not gatewayURL:
          return S_OK(self._destinationSrv)
        gLogger.debug("Reconstructing given URL to pass through gateway")
        path = "/".join(self._destinationSrv.split("/")[3:])
        finalURL = "%s/%s" % (gatewayURL, path)
        gLogger.debug("Gateway URL conversion:\n %s -> %s" % (self._destinationSrv, finalURL))
        return S_OK(finalURL)

    if gatewayURL:
      gLogger.debug("Using gateway", gatewayURL)
      return S_OK("%s/%s" % (gatewayURL, self._destinationSrv))

    # We extract the list of URLs from the CS (System/URLs/Component)
    try:
      urls = getServiceURL(self._destinationSrv, setup=self.setup)
    except Exception as e:
      return S_ERROR("Cannot get URL for %s in setup %s: %s" % (self._destinationSrv, self.setup, repr(e)))
    if not urls:
      return S_ERROR("URL for service %s not found" % self._destinationSrv)

    failoverUrls = []
    # Try if there are some failover URLs to use as last resort
    try:
      failoverUrlsStr = getServiceFailoverURL(self._destinationSrv, setup=self.setup)
      if failoverUrlsStr:
        failoverUrls = failoverUrlsStr.split(',')
    except Exception as e:
      pass

    # We randomize the list, and add at the end the failover URLs (System/FailoverURLs/Component)
    urlsList = List.randomize(List.fromChar(urls, ",")) + failoverUrls
    self.__nbOfUrls = len(urlsList)
    self.__nbOfRetry = 2 if self.__nbOfUrls > 2 else 3  # we retry 2 times all services, if we run more than 2 services
    if self.__nbOfUrls == len(self.__bannedUrls):
      self.__bannedUrls = []  # retry all urls
      gLogger.debug("Retrying again all URLs")

    if len(self.__bannedUrls) > 0 and len(urlsList) > 1:
      # we have host which is not accessible. We remove that host from the list.
      # We only remove if we have more than one instance
      for i in self.__bannedUrls:
        gLogger.debug("Removing banned URL", "%s" % i)
        urlsList.remove(i)

    # Take the first URL from the list
    #randUrls = List.randomize( urlsList ) + failoverUrls

    sURL = urlsList[0]

    # If we have banned URLs, and several URLs at disposals, we make sure that the selected sURL
    # is not on a host which is banned. If it is, we take the next one in the list using __selectUrl
    # If we have banned URLs, and several URLs at disposals, we make sure that the selected sURL
    # is not on a host which is banned. If it is, we take the next one in the list using __selectUrl

    if len(self.__bannedUrls) > 0 and self.__nbOfUrls > 2:  # when we have multiple services then we can
      # have a situation when two services are running on the same machine with different ports...
      retVal = Network.splitURL(sURL)
      nexturl = None
      if retVal['OK']:
        nexturl = retVal['Value']

#.........这里部分代码省略.........
开发者ID:marianne013,项目名称:DIRAC,代码行数:101,代码来源:BaseClient.py


注:本文中的DIRAC.Core.Utilities.Network类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。