]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
uptodateness: migrate more methods from visualize
authorJoe Guo <joeg@catalyst.net.nz>
Wed, 3 Oct 2018 09:39:04 +0000 (22:39 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 18 Oct 2018 04:15:24 +0000 (06:15 +0200)
Move methods from cmd_uptodateness to new module.
Will reuse in drs cmd 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 568d111830b53eb166d1598eacc7da864f9fd902..2f87dbe433de9760ffe8f20983903890e362d6b2 100644 (file)
@@ -42,6 +42,8 @@ from samba.compat import text_type
 from samba.uptodateness import (
     get_partition_maps,
     get_partition,
+    get_own_cursor,
+    get_utdv,
 )
 
 COMMON_OPTIONS = [
@@ -658,36 +660,6 @@ class cmd_uptodateness(GraphCommand):
                help="display this many digits of out-of-date-ness"),
     ]
 
-    def get_utdv(self, samdb, dn):
-        """This finds the uptodateness vector in the database."""
-        cursors = []
-        config_dn = samdb.get_config_basedn()
-        for c in dsdb._dsdb_load_udv_v2(samdb, dn):
-            inv_id = str(c.source_dsa_invocation_id)
-            res = samdb.search(base=config_dn,
-                               expression=("(&(invocationId=%s)"
-                                           "(objectClass=nTDSDSA))" % inv_id),
-                               attrs=["distinguishedName", "invocationId"])
-            settings_dn = str(res[0]["distinguishedName"][0])
-            prefix, dsa_dn = settings_dn.split(',', 1)
-            if prefix != 'CN=NTDS Settings':
-                raise CommandError("Expected NTDS Settings DN, got %s" %
-                                   settings_dn)
-
-            cursors.append((dsa_dn,
-                            inv_id,
-                            int(c.highest_usn),
-                            nttime2unix(c.last_sync_success)))
-        return cursors
-
-    def get_own_cursor(self, samdb):
-            res = samdb.search(base="",
-                               scope=SCOPE_BASE,
-                               attrs=["highestCommittedUSN"])
-            usn = int(res[0]["highestCommittedUSN"][0])
-            now = int(time.time())
-            return (usn, now)
-
     def run(self, H=None, output=None, shorten_names=False,
             key=True, talk_to_remote=False,
             sambaopts=None, credopts=None, versionopts=None,
@@ -716,7 +688,7 @@ class cmd_uptodateness(GraphCommand):
             if partition not in (part_dn, None):
                 continue  # we aren't doing this partition
 
-            cursors = self.get_utdv(self.samdb, part_dn)
+            cursors = get_utdv(self.samdb, part_dn)
 
             # we talk to each remote and make a matrix of the vectors
             # -- for each partition
@@ -729,8 +701,8 @@ class cmd_uptodateness(GraphCommand):
                 ldap_url = "ldap://%s" % res[0]["dNSHostName"][0]
                 try:
                     samdb = self.get_db(ldap_url, sambaopts, credopts)
-                    cursors = self.get_utdv(samdb, part_dn)
-                    own_usn, own_time = self.get_own_cursor(samdb)
+                    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
index 06e8f175b5c41e8566eb3b8e263085a1bd077cc7..90cac5500733ee9d637939f5bcf5d28a3bc52a0c 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/>.
+import time
 
+from ldb import SCOPE_BASE
+
+from samba import nttime2unix, dsdb
 from samba.netcmd import CommandError
 
 
@@ -48,3 +52,35 @@ def get_partition(samdb, part):
         if part not in long_partitions:
             raise CommandError("unknown partition %s" % part)
     return part
+
+
+def get_utdv(samdb, dn):
+    """This finds the uptodateness vector in the database."""
+    cursors = []
+    config_dn = samdb.get_config_basedn()
+    for c in dsdb._dsdb_load_udv_v2(samdb, dn):
+        inv_id = str(c.source_dsa_invocation_id)
+        res = samdb.search(base=config_dn,
+                           expression=("(&(invocationId=%s)"
+                                       "(objectClass=nTDSDSA))" % inv_id),
+                           attrs=["distinguishedName", "invocationId"])
+        settings_dn = str(res[0]["distinguishedName"][0])
+        prefix, dsa_dn = settings_dn.split(',', 1)
+        if prefix != 'CN=NTDS Settings':
+            raise CommandError("Expected NTDS Settings DN, got %s" %
+                               settings_dn)
+
+        cursors.append((dsa_dn,
+                        inv_id,
+                        int(c.highest_usn),
+                        nttime2unix(c.last_sync_success)))
+    return cursors
+
+
+def get_own_cursor(samdb):
+    res = samdb.search(base="",
+                       scope=SCOPE_BASE,
+                       attrs=["highestCommittedUSN"])
+    usn = int(res[0]["highestCommittedUSN"][0])
+    now = int(time.time())
+    return (usn, now)