uptodateness: migrate get_kcc_and_dsas as a function
authorJoe Guo <joeg@catalyst.net.nz>
Wed, 3 Oct 2018 11:42:08 +0000 (00:42 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 18 Oct 2018 04:15:25 +0000 (06:15 +0200)
We need to reuse it in drs cmd.

Signed-off-by: Joe Guo <joeg@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13658

python/samba/netcmd/visualize.py
python/samba/uptodateness.py

index 05fdc013aa18bc288c3e23b8c5f8b82f7a17c37d..a0eb676eb31fc1a1894ab5a01cc37e3802bba580 100644 (file)
@@ -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)
 
index e5e0fc30a9b84fc2e9dc3e0fc41104bf4f243363..847a35d60e34daa0b57e37c5821712f7c8b9b156 100644 (file)
@@ -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):