From 74f7080b1593b446c89f0d940bbdcdb025168cfd Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Thu, 4 Oct 2018 00:42:08 +1300 Subject: [PATCH] uptodateness: migrate get_kcc_and_dsas as a function We need to reuse it in drs cmd. Signed-off-by: Joe Guo Reviewed-by: Douglas Bagnall Reviewed-by: Andrew Bartlett BUG: https://bugzilla.samba.org/show_bug.cgi?id=13658 --- python/samba/netcmd/visualize.py | 20 ++++---------------- python/samba/uptodateness.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/python/samba/netcmd/visualize.py b/python/samba/netcmd/visualize.py index 05fdc013aa1..a0eb676eb31 100644 --- a/python/samba/netcmd/visualize.py +++ b/python/samba/netcmd/visualize.py @@ -47,6 +47,7 @@ from samba.uptodateness import ( get_utdv_edges, get_utdv_distances, get_utdv_max_distance, + get_kcc_and_dsas, ) COMMON_OPTIONS = [ @@ -100,19 +101,6 @@ class GraphCommand(Command): samdb = SamDB(url=H, credentials=creds, lp=lp) return samdb - def get_kcc_and_dsas(self, H, lp, creds): - """Get a readonly KCC object and the list of DSAs it knows about.""" - unix_now = int(time.time()) - kcc = KCC(unix_now, readonly=True) - kcc.load_samdb(H, lp, creds) - - dsa_list = kcc.list_dsas() - dsas = set(dsa_list) - if len(dsas) != len(dsa_list): - print("There seem to be duplicate dsas", file=sys.stderr) - - return kcc, dsas - def write(self, s, fn=None, suffix='.dot'): """Decide whether we're dealing with a filename, a tempfile, or stdout, and write accordingly. @@ -233,7 +221,7 @@ class cmd_reps(GraphCommand): # replication graph. lp = sambaopts.get_loadparm() creds = credopts.get_credentials(lp, fallback_machine=True) - local_kcc, dsas = self.get_kcc_and_dsas(H, lp, creds) + local_kcc, dsas = get_kcc_and_dsas(H, lp, creds) unix_now = local_kcc.unix_now partition = get_partition(local_kcc.samdb, partition) @@ -442,7 +430,7 @@ class cmd_ntdsconn(GraphCommand): creds = None H = self.import_ldif_db(importldif, lp) - local_kcc, dsas = self.get_kcc_and_dsas(H, lp, creds) + local_kcc, dsas = get_kcc_and_dsas(H, lp, creds) local_dsa_dn = local_kcc.my_dsa_dnstr.split(',', 1)[1] vertices = set() attested_edges = [] @@ -678,7 +666,7 @@ class cmd_uptodateness(GraphCommand): # replication graph. lp = sambaopts.get_loadparm() creds = credopts.get_credentials(lp, fallback_machine=True) - local_kcc, dsas = self.get_kcc_and_dsas(H, lp, creds) + local_kcc, dsas = get_kcc_and_dsas(H, lp, creds) self.samdb = local_kcc.samdb partition = get_partition(self.samdb, partition) diff --git a/python/samba/uptodateness.py b/python/samba/uptodateness.py index e5e0fc30a9b..847a35d60e3 100644 --- a/python/samba/uptodateness.py +++ b/python/samba/uptodateness.py @@ -26,6 +26,21 @@ from ldb import SCOPE_BASE, LdbError from samba import nttime2unix, dsdb from samba.netcmd import CommandError from samba.samdb import SamDB +from samba.kcc import KCC + + +def get_kcc_and_dsas(url, lp, creds): + """Get a readonly KCC object and the list of DSAs it knows about.""" + unix_now = int(time.time()) + kcc = KCC(unix_now, readonly=True) + kcc.load_samdb(url, lp, creds) + + dsa_list = kcc.list_dsas() + dsas = set(dsa_list) + if len(dsas) != len(dsa_list): + print("There seem to be duplicate dsas", file=sys.stderr) + + return kcc, dsas def get_partition_maps(samdb): -- 2.34.1