Exemple #1
0
    def run(self,
            H=None,
            partition=None,
            json=False,
            maximum=False,
            median=False,
            full=False,
            sambaopts=None,
            credopts=None,
            versionopts=None,
            quiet=False,
            verbose=False):

        lp = sambaopts.get_loadparm()
        creds = credopts.get_credentials(lp, fallback_machine=True)
        local_kcc, dsas = get_kcc_and_dsas(H, lp, creds)
        samdb = local_kcc.samdb
        short_partitions, _ = get_partition_maps(samdb)
        if partition:
            if partition in short_partitions:
                part_dn = short_partitions[partition]
                # narrow down to specified partition only
                short_partitions = {partition: part_dn}
            else:
                raise CommandError("unknown partition %s" % partition)

        filters = []
        if maximum:
            filters.append('maximum')
        if median:
            filters.append('median')

        partitions_distances = {}
        partitions_summaries = {}
        for part_name, part_dn in short_partitions.items():
            utdv_edges = get_utdv_edges(local_kcc, dsas, part_dn, lp, creds)
            distances = get_utdv_distances(utdv_edges, dsas)
            summary = get_utdv_summary(distances, filters=filters)
            partitions_distances[part_name] = distances
            partitions_summaries[part_name] = summary

        if full:
            # always print json format
            output = self.format_as_json(partitions_distances)
        else:
            if json:
                output = self.format_as_json(partitions_summaries)
            else:
                output = self.format_as_text(partitions_summaries)

        print(output, file=self.outf)
Exemple #2
0
    def run(self,
            H=None,
            output=None,
            shorten_names=False,
            key=True,
            talk_to_remote=False,
            sambaopts=None,
            credopts=None,
            versionopts=None,
            color=None,
            color_scheme=None,
            utf8=False,
            format=None,
            importldif=None,
            xdot=False,
            partition=None,
            max_digits=3):
        if not talk_to_remote:
            print(
                "this won't work without talking to the remote servers "
                "(use -r)",
                file=self.outf)
            return

        # We use the KCC libraries in readonly mode to get the
        # replication graph.
        lp = sambaopts.get_loadparm()
        creds = credopts.get_credentials(lp, fallback_machine=True)
        local_kcc, dsas = get_kcc_and_dsas(H, lp, creds)
        self.samdb = local_kcc.samdb
        partition = get_partition(self.samdb, partition)

        short_partitions, long_partitions = get_partition_maps(self.samdb)
        color_scheme = self.calc_distance_color_scheme(color, color_scheme,
                                                       output)

        for part_name, part_dn in short_partitions.items():
            if partition not in (part_dn, None):
                continue  # we aren't doing this partition

            utdv_edges = get_utdv_edges(local_kcc, dsas, part_dn, lp, creds)

            distances = get_utdv_distances(utdv_edges, dsas)

            max_distance = get_utdv_max_distance(distances)

            digits = min(max_digits, len(str(max_distance)))
            if digits < 1:
                digits = 1
            c_scale = 10**digits

            s = full_matrix(distances,
                            utf8=utf8,
                            colour=color_scheme,
                            shorten_names=shorten_names,
                            generate_key=key,
                            grouping_function=get_dnstr_site,
                            colour_scale=c_scale,
                            digits=digits,
                            ylabel='DC',
                            xlabel='out-of-date-ness')

            self.write('\n%s\n\n%s' % (part_name, s), output)