uptodateness: extract function get_utdv_edges
authorJoe Guo <joeg@catalyst.net.nz>
Wed, 3 Oct 2018 10:09:56 +0000 (23:09 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 18 Oct 2018 04:15:24 +0000 (06:15 +0200)
Extract function to reuse later.

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 9bdab584525a05459b6eaf405f63c50ec9db2928..ae09b4fc353b16c6f213ad382588693b1a1557a1 100644 (file)
@@ -44,6 +44,7 @@ from samba.uptodateness import (
     get_partition,
     get_own_cursor,
     get_utdv,
+    get_utdv_edges,
 )
 
 COMMON_OPTIONS = [
@@ -688,27 +689,7 @@ class cmd_uptodateness(GraphCommand):
             if partition not in (part_dn, None):
                 continue  # we aren't doing this partition
 
-            # we talk to each remote and make a matrix of the vectors
-            # -- for each partition
-            # normalise by oldest
-            utdv_edges = {}
-            for dsa_dn in dsas:
-                res = local_kcc.samdb.search(dsa_dn,
-                                             scope=SCOPE_BASE,
-                                             attrs=["dNSHostName"])
-                ldap_url = "ldap://%s" % res[0]["dNSHostName"][0]
-                try:
-                    samdb = self.get_db(ldap_url, sambaopts, credopts)
-                    cursors = get_utdv(samdb, part_dn)
-                    own_usn, own_time = get_own_cursor(samdb)
-                    remotes = {dsa_dn: own_usn}
-                    for dn, guid, usn, t in cursors:
-                        remotes[dn] = usn
-                except LdbError as e:
-                    print("Could not contact %s (%s)" % (ldap_url, e),
-                          file=sys.stderr)
-                    continue
-                utdv_edges[dsa_dn] = remotes
+            utdv_edges = get_utdv_edges(local_kcc, dsas, part_dn, lp, creds)
 
             distances = {}
             max_distance = 0
index 90cac5500733ee9d637939f5bcf5d28a3bc52a0c..834026c8b8f022fc08b5527bb4c4e85705f3ec1d 100644 (file)
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
+from __future__ import print_function
+
+import sys
 import time
 
-from ldb import SCOPE_BASE
+from ldb import SCOPE_BASE, LdbError
 
 from samba import nttime2unix, dsdb
 from samba.netcmd import CommandError
+from samba.samdb import SamDB
 
 
 def get_partition_maps(samdb):
@@ -84,3 +88,28 @@ def get_own_cursor(samdb):
     usn = int(res[0]["highestCommittedUSN"][0])
     now = int(time.time())
     return (usn, now)
+
+
+def get_utdv_edges(local_kcc, dsas, part_dn, lp, creds):
+    # we talk to each remote and make a matrix of the vectors
+    # for each partition
+    # normalise by oldest
+    utdv_edges = {}
+    for dsa_dn in dsas:
+        res = local_kcc.samdb.search(dsa_dn,
+                                     scope=SCOPE_BASE,
+                                     attrs=["dNSHostName"])
+        ldap_url = "ldap://%s" % res[0]["dNSHostName"][0]
+        try:
+            samdb = SamDB(url=ldap_url, credentials=creds, lp=lp)
+            cursors = get_utdv(samdb, part_dn)
+            own_usn, own_time = get_own_cursor(samdb)
+            remotes = {dsa_dn: own_usn}
+            for dn, guid, usn, t in cursors:
+                remotes[dn] = usn
+        except LdbError as e:
+            print("Could not contact %s (%s)" % (ldap_url, e),
+                  file=sys.stderr)
+            continue
+        utdv_edges[dsa_dn] = remotes
+    return utdv_edges