コード例 #1
0
    def _resolve_host(self, req_func, allow_redirect, path, operation,
                      **kwargs):
        """
        internal function used to resolve federation and HA and
        return response of resolved host.
        """
        uri_without_host = self._create_uri(path, operation, **kwargs)
        hosts = self._resolve_federation(path)
        for host in hosts:
            hostport = host.split(':')
            uri = uri_without_host.format(
                host=hostport[0],
                port=int(hostport[1]) if len(hostport) > 1 else self.port)
            try:
                response = req_func(uri,
                                    allow_redirects=allow_redirect,
                                    timeout=self.timeout,
                                    **self.request_extra_opts)

                if not _is_standby_exception(response):
                    _move_active_host_to_head(hosts, host)
                    return response
            except requests.exceptions.RequestException as e:
                traceback.print_exc()
                print("Error connecting to host {}".format(host))
                continue
        raise errors.ActiveHostNotFound(msg="Could not find active host")
コード例 #2
0
    def _resolve_host(self, req_func, allow_redirect, path, operation,
                      **kwargs):
        """
        This is where the magic happens, and where omniduct handles redirects
        during federation and HA.
        """
        import requests
        uri_without_host = self._create_uri(path, operation, **kwargs)
        hosts = self._resolve_federation(path)
        for host in hosts:
            uri = uri_without_host.format(host=host)
            try:
                while True:
                    response = req_func(uri,
                                        allow_redirects=False,
                                        timeout=self.timeout,
                                        **self.request_extra_opts)

                    if allow_redirect and response.status_code == http_client.TEMPORARY_REDIRECT:
                        uri = self._make_uri_local(
                            response.headers['location'])
                    else:
                        break

                if not allow_redirect and response.status_code == http_client.TEMPORARY_REDIRECT:
                    response.headers['location'] = self._make_uri_local(
                        response.headers['location'])

                if not _is_standby_exception(response):
                    _move_active_host_to_head(hosts, host)
                    return response
            except requests.exceptions.RequestException:
                pass
        raise errors.ActiveHostNotFound(msg="Could not find active host")
コード例 #3
0
    def _resolve_host(self, req_func, allow_redirect,
                      path, operation, **kwargs):
        """
        internal function used to resolve federation and HA and
        return response of resolved host.
        """
        uri_without_host = self._create_uri(path, operation, **kwargs)
        hosts = self._resolve_federation(path)
        for host in hosts:
            uri = uri_without_host.format(host=host)
            response = req_func(uri, allow_redirects=allow_redirect,
                                timeout=self.timeout)

            if not _is_standby_exception(response):
                _move_active_host_to_head(hosts, host)
                return response
        raise errors.ActiveHostNotFound(msg="Could not find active host")