'For internal use only.'

def add_or_renew_pool(self, host, is_host_addition):

    distance = self._profile_manager.distance(host)
    if (distance == HostDistance.IGNORED):
        return None
    def run_add_or_renew_pool():
        try:
            if (self._protocol_version >= 3):
                new_pool = HostConnection(host, distance, self)
            else:
                new_pool = HostConnectionPool(host, distance, self)
        except AuthenticationFailed as auth_exc:
            conn_exc = ConnectionException(str(auth_exc), host=host)
            self.cluster.signal_connection_failure(host, conn_exc, is_host_addition)
            return False
        except Exception as conn_exc:
            log.warning('Failed    to    create    connection    pool    for    new    host    %s:', host, exc_info=conn_exc)
            self.cluster.signal_connection_failure(host, conn_exc, is_host_addition, expect_host_to_be_down=True)
            return False
        previous = self._pools.get(host)
        with self._lock:
            while (new_pool._keyspace != self.keyspace):
                self._lock.release()
                set_keyspace_event = Event()
                errors_returned = []
                def callback(pool, errors):
                    errors_returned.extend(errors)
                    set_keyspace_event.set()
                new_pool._set_keyspace_for_all_conns(self.keyspace, callback)
                set_keyspace_event.wait(self.cluster.connect_timeout)
                if ((not set_keyspace_event.is_set()) or errors_returned):
                    log.warning('Failed    setting    keyspace    for    pool    after    keyspace    changed    during    connect:    %s', errors_returned)
                    self.cluster.on_down(host, is_host_addition)
                    new_pool.shutdown()
                    self._lock.acquire()
                    return False
                self._lock.acquire()
            self._pools[host] = new_pool
        log.debug('Added    pool    for    host    %s    to    session', host)
        if previous:
            previous.shutdown()
        return True
    return self.submit(run_add_or_renew_pool)
