def get_endpoint_mapping()

in cstar/job.py [0:0]


    def get_endpoint_mapping(self, topology):
        clusters = []
        failed_hosts = []
        mappings = []
        count = 0

        endpoint_mappings = self.maybe_get_data_from_cache("endpoint_mapping")
        if endpoint_mappings is not None:
            return endpoint_mappings

        for host in topology.get_up():
            if host.cluster in clusters:
                # We need to fetch keyspaces on one node per cluster, no more.
                continue

            count = 0
            conn = self._connection(host)

            if self.key_space:
                keyspaces = [self.key_space]
            else:
                keyspaces = self.get_keyspaces(conn)
            has_error = True
            for keyspace in keyspaces:
                if not keyspace.startswith("system"):
                    debug("Fetching endpoint mapping for keyspace", keyspace)
                    res = self.run_nodetool(conn, *("describering", keyspace))
                    has_error = False

                    if res.status != 0 and not keyspace.startswith("system"):
                        has_error = True
                        break
                    describering = cstar.nodetoolparser.parse_nodetool_describering(res.out)
                    range_mapping = cstar.nodetoolparser.convert_describering_to_range_mapping(describering)
                    mappings.append(cstar.endpoint_mapping.parse(range_mapping, topology, lookup=ip_lookup))

            if has_error:
                if count >= MAX_ATTEMPTS:
                    failed_hosts += host
                    break
            else:
                clusters.append(host.cluster)

            count += 1

        if failed_hosts:
            raise HostIsDown("Following hosts couldn't be reached: {}".format(', '.join(host.fqdn for host in failed_hosts)))

        endpoint_mappings = cstar.endpoint_mapping.merge(mappings)
        pickle.dump(dict(endpoint_mappings), open(self.get_cache_file_path("endpoint_mapping"), 'wb'))
        return endpoint_mappings