From: Joe Guo Date: Wed, 3 Oct 2018 10:09:56 +0000 (+1300) Subject: uptodateness: extract function get_utdv_edges X-Git-Tag: tdb-1.3.17~1290 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac1fba31c4e87070cfc0dee32150785bedb8e249;p=thirdparty%2Fsamba.git uptodateness: extract function get_utdv_edges Extract function to reuse later. Signed-off-by: Joe Guo Reviewed-by: Douglas Bagnall Reviewed-by: Andrew Bartlett BUG: https://bugzilla.samba.org/show_bug.cgi?id=13658 --- diff --git a/python/samba/netcmd/visualize.py b/python/samba/netcmd/visualize.py index 9bdab584525..ae09b4fc353 100644 --- a/python/samba/netcmd/visualize.py +++ b/python/samba/netcmd/visualize.py @@ -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 diff --git a/python/samba/uptodateness.py b/python/samba/uptodateness.py index 90cac550073..834026c8b8f 100644 --- a/python/samba/uptodateness.py +++ b/python/samba/uptodateness.py @@ -16,12 +16,16 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . +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