media/tools/constrained_network_server/cns.py
def Get(self, key, new_port=False, **kwargs):
    """Sets up a constrained port using the requested parameters.

    Requests for the same key and constraints will result in a cached port being
    returned if possible, subject to new_port.

    Args:
      key: Used to cache ports with the given constraints.
      new_port: Whether to create a new port or use an existing one if possible.
      **kwargs: Constraints to pass into traffic control.

    Returns:
      None if no port can be setup or the port number of the constrained port.
    """
    with self._port_lock:
      # Check port key cache to see if this port is already setup. Update the
      # cache time and return the port if so. Performance isn't a concern here,
      # so just iterate over ports dict for simplicity.
      full_key = (key,) + tuple(kwargs.values())
      if not new_port:
        for port, status in self._ports.iteritems():
          if full_key == status['key']:
            self._ports[port]['last_update'] = time.time()
            return port

      # Cleanup ports on new port requests. Do it after the cache check though
      # so we don't erase and then setup the same port.
      if self._expiry_time_secs > 0:
        self.Cleanup(all_ports=False)

      # Performance isn't really an issue here, so just iterate over the port
      # range to find an unused port. If no port is found, None is returned.
      for port in xrange(self._port_range[0], self._port_range[1]):
        if port in self._ports:
          continue
        if self._SetupPort(port, **kwargs):
          kwargs['port'] = port
          self._ports[port] = {'last_update': time.time(), 'key': full_key,
                               'config': kwargs}
          return port
Sets up a constrained port using the requested parameters.

    Requests for the same key and constraints will result in a cached port being
    returned if possible, subject to new_port.

    Args:
      key: Used to cache ports with the given constraints.
      new_port: Whether to create a new port or use an existing one if possible.
      **kwargs: Constraints to pass into traffic control.

    Returns:
      None if no port can be setup or the port number of the constrained port.
    
Sets up a constrained port using the requested parameters.
Requests for the same key and constraints will result in a cached port being
returned if possible, subject to new_port.
Sets up a constrained port using the requested parameters . Requests for the same key and constraints will result in a cached port being returned if possible subject to new_port .
def Get(self, key, new_port=False, **kwargs):
    with self._port_lock:
      full_key = (key,) + tuple(kwargs.values())
      if not new_port:
        for port, status in self._ports.iteritems():
          if full_key == status['key']:
            self._ports[port]['last_update'] = time.time()
            return port
      if self._expiry_time_secs > 0:
        self.Cleanup(all_ports=False)
      for port in xrange(self._port_range[0], self._port_range[1]):
        if port in self._ports:
          continue
        if self._SetupPort(port, **kwargs):
          kwargs['port'] = port
          self._ports[port] = {'last_update': time.time(), 'key': full_key,
                               'config': kwargs}
          return port
def Get ( self , key , new_port = False , ** kwargs ) : with self . _port_lock : full_key = ( key , ) + tuple ( kwargs . values ( ) ) if not new_port : for port , status in self . _ports . iteritems ( ) : if full_key == status [ 'key' ] : self . _ports [ port ] [ 'last_update' ] = time . time ( ) return port if self . _expiry_time_secs > 0 : self . Cleanup ( all_ports = False ) for port in xrange ( self . _port_range [ 0 ] , self . _port_range [ 1 ] ) : if port in self . _ports : continue if self . _SetupPort ( port , ** kwargs ) : kwargs [ 'port' ] = port self . _ports [ port ] = { 'last_update' : time . time ( ) , 'key' : full_key , 'config' : kwargs } return port
Sets up a constrained port using the requested parameters.
Sets up a constrained port using the requested parameters .
"""Sets up a constrained port using the requested parameters.

    Requests for the same key and constraints will result in a cached port being
    returned if possible, subject to new_port.

    Args:
      key: Used to cache ports with the given constraints.
      new_port: Whether to create a new port or use an existing one if possible.
      **kwargs: Constraints to pass into traffic control.

    Returns:
      None if no port can be setup or the port number of the constrained port.
    """ # Check port key cache to see if this port is already setup. Update the # cache time and return the port if so. Performance isn't a concern here, # so just iterate over ports dict for simplicity. # Cleanup ports on new port requests. Do it after the cache check though # so we don't erase and then setup the same port. # Performance isn't really an issue here, so just iterate over the port # range to find an unused port. If no port is found, None is returned.
None if no port can be setup or the port number of the constrained port.
None if no port can be setup or the port number of the constrained port .
self
key
Used to cache ports with the given constraints.
Used to cache ports with the given constraints .
new_port
Whether to create a new port or use an existing one if possible.
Whether to create a new port or use an existing one if possible .
**kwargs
Constraints to pass into traffic control.
Constraints to pass into traffic control .