def _resolve_target(self, hostname, path): """Returns the server and instance that should handle this request. Args: hostname: A string containing the value of the host header in the request or None if one was not present. path: A string containing the path of the request. Returns: A tuple (servr, inst) where: servr: The server.Server that should handle this request. inst: The instance.Instance that should handle this request or None if the server's load balancing should decide on the instance. Raises: request_info.ServerDoesNotExistError: if hostname is not known. """ if self._port == 80: default_address = self.host else: default_address = '%s:%s' % (self.host, self._port) if not hostname or hostname == default_address: return self._server_for_request(path), None default_address_offset = hostname.find(default_address) if default_address_offset > 0: prefix = hostname[:default_address_offset - 1] if '.' in prefix: raise request_info.ServerDoesNotExistError( 'Server does not exist: %s' % prefix) return self._get_server(prefix, None), None else: if ':' in hostname: port = int(hostname.split(':', 1)[1]) else: port = 80 try: servr, inst = self._port_registry.get(port) except KeyError: raise request_info.ServerDoesNotExistError( 'No server found at: %s' % hostname) if not servr: servr = self._server_for_request(path) return servr, inst
def _get_server(self, server_name, version): if not server_name: server_name = 'default' if server_name not in self._server_name_to_server: raise request_info.ServerDoesNotExistError(server_name) elif (version is not None and version != self._server_configurations[server_name].major_version): raise request_info.VersionDoesNotExistError() return self._server_name_to_server[server_name]
def get_default_version(self, servr): """Returns the default version for a server. Args: servr: A str containing the name of the server. Returns: A str containing the default version for the specified server. Raises: request_info.ServerDoesNotExistError: The server does not exist. """ if servr in self._server_configurations: return self._server_configurations[servr].major_version else: raise request_info.ServerDoesNotExistError(servr)
def get_server_by_name(self, servr): """Returns the server with the given name. Args: servr: A str containing the name of the server. Returns: The server.Server with the provided name. Raises: request_info.ServerDoesNotExistError: The server does not exist. """ try: return self._server_name_to_server[servr] except KeyError: raise request_info.ServerDoesNotExistError(servr)