def load_current_replica_table(self, samdb):
        """Method to load the NC replica's listed for DSA object.

        This method queries the samdb for (hasMasterNCs, msDS-hasMasterNCs,
        hasPartialReplicaNCs, msDS-HasDomainNCs, msDS-hasFullReplicaNCs, and
        msDS-HasInstantiatedNCs) to determine complete list of NC replicas that
        are enumerated for the DSA.  Once a NC replica is loaded it is
        identified (schema, config, etc) and the other replica attributes
        (partial, ro, etc) are determined.

        :param samdb: database to query for DSA replica list
        """
        ncattrs = [ # not RODC - default, config, schema (old style)
                    "hasMasterNCs",
                    # not RODC - default, config, schema, app NCs
                    "msDS-hasMasterNCs",
                    # domain NC partial replicas
                    "hasPartialReplicaNCs",
                    # default domain NC
                    "msDS-HasDomainNCs",
                    # RODC only - default, config, schema, app NCs
                    "msDS-hasFullReplicaNCs",
                    # Identifies if replica is coming, going, or stable
                    "msDS-HasInstantiatedNCs" ]
        try:
            res = samdb.search(base=self.dsa_dnstr, scope=ldb.SCOPE_BASE,
                               attrs=ncattrs)

        except ldb.LdbError, (enum, estr):
            raise Exception("Unable to find nTDSDSA NCs for (%s) - (%s)" %
                            (self.dsa_dnstr, estr))

        # The table of NCs for the dsa we are searching
        tmp_table = {}

        # We should get one response to our query here for
        # the ntds that we requested
        if len(res[0]) > 0:

            # Our response will contain a number of elements including
            # the dn of the dsa as well as elements for each
            # attribute (e.g. hasMasterNCs).  Each of these elements
            # is a dictonary list which we retrieve the keys for and
            # then iterate over them
            for k in res[0].keys():
                if k == "dn":
                    continue

                # For each attribute type there will be one or more DNs
                # listed.  For instance DCs normally have 3 hasMasterNCs
                # listed.
                for value in res[0][k]:
                    # Turn dn into a dsdb_Dn so we can use
                    # its methods to parse a binary DN
                    dsdn = dsdb_Dn(samdb, value)
                    flags = dsdn.get_binary_integer()
                    dnstr = str(dsdn.dn)

                    if not dnstr in tmp_table.keys():
                        rep = NCReplica(self.dsa_dnstr, self.dsa_guid, dnstr)
                        tmp_table[dnstr] = rep
                    else:
                        rep = tmp_table[dnstr]

                    if k == "msDS-HasInstantiatedNCs":
                        rep.set_instantiated_flags(flags)
                        continue

                    rep.identify_by_dsa_attr(samdb, k)

                    # if we've identified the default domain NC
                    # then save its DN string
                    if rep.is_default():
                       self.default_dnstr = dnstr
        else:
            raise Exception("No nTDSDSA NCs for (%s)" % self.dsa_dnstr)

        # Assign our newly built NC replica table to this dsa
        self.current_rep_table = tmp_table
dataset/ETHPy150Open byt3bl33d3r/pth-toolkit/lib/python2.7/site-packages/samba/kcc_utils.py/DirectoryServiceAgent.load_current_replica_table/original