def __init__(self, conf): validate_service_conf(conf) self.running = True self.conf = conf self.logger = get_logger(conf) self.load_services() self.init_watchers(self.conf['services'])
def __init__(self, conf, request_prefix="", no_ns_in_url=False, endpoint=None, request_attempts=REQUEST_ATTEMPTS, logger=None, **kwargs): """ :param request_prefix: text to insert in between endpoint and requested URL :type request_prefix: `str` :param no_ns_in_url: do not insert namespace name between endpoint and `request_prefix` :type no_ns_in_url: `bool` :param request_attempts: number of attempts for the request in case of error 503 (defaults to 1) :raise oio.common.exceptions.ServiceBusy: if all attempts fail """ assert request_attempts > 0 validate_service_conf(conf) self.ns = conf.get('namespace') self.conf = conf self.logger = logger or get_logger(conf) # Look for an endpoint in the application configuration if not endpoint: endpoint = self.conf.get('proxyd_url', None) # Look for an endpoint in the namespace configuration if not endpoint: ns_conf = load_namespace_conf(self.ns) endpoint = ns_conf.get('proxy') # Historically, the endpoint did not contain any scheme self.proxy_scheme = 'http' split_endpoint = endpoint.split('://', 1) if len(split_endpoint) > 1: self.proxy_scheme = split_endpoint[0] self.proxy_netloc = split_endpoint[-1] ep_parts = list() ep_parts.append(self.proxy_scheme + ':/') ep_parts.append(self.proxy_netloc) ep_parts.append("v3.0") if not no_ns_in_url: ep_parts.append(self.ns) if request_prefix: ep_parts.append(request_prefix.lstrip('/')) self._request_attempts = request_attempts super(ProxyClient, self).__init__(endpoint='/'.join(ep_parts), service_type='proxy', **kwargs)
def __init__(self, conf, pool_manager=None, request_prefix="", no_ns_in_url=False, endpoint=None, request_attempts=REQUEST_ATTEMPTS, logger=None, **kwargs): """ :param pool_manager: an optional pool manager that will be reused :type pool_manager: `urllib3.PoolManager` :param request_prefix: text to insert in between endpoint and requested URL :type request_prefix: `str` :param no_ns_in_url: do not insert namespace name between endpoint and `request_prefix` :type no_ns_in_url: `bool` :param request_attempts: number of attempts for the request in case of error 503 :raise oio.common.exceptions.ServiceBusy: if all attempts fail """ assert request_attempts > 0 validate_service_conf(conf) self.ns = conf.get('namespace') self.conf = conf self.logger = logger or get_logger(conf) if not endpoint: endpoint = self.conf.get('proxyd_url', None) ep_parts = list() if endpoint: self.proxy_netloc = endpoint.lstrip("http://") else: ns_conf = load_namespace_conf(self.ns) self.proxy_netloc = ns_conf.get('proxy') ep_parts.append("http:/") ep_parts.append(self.proxy_netloc) ep_parts.append("v3.0") if not no_ns_in_url: ep_parts.append(self.ns) if request_prefix: ep_parts.append(request_prefix.lstrip('/')) self._request_attempts = request_attempts super(ProxyClient, self).__init__(endpoint='/'.join(ep_parts), **kwargs)