s4-python: factorize the definition of get_dsServiceName
authorMatthieu Patou <mat@matws.net>
Sun, 4 Dec 2011 13:23:34 +0000 (14:23 +0100)
committerMatthieu Patou <mat@matws.net>
Mon, 5 Dec 2011 17:23:07 +0000 (18:23 +0100)
source4/scripting/python/samba/join.py
source4/scripting/python/samba/netcmd/drs.py
source4/scripting/python/samba/netcmd/rodc.py
source4/scripting/python/samba/samdb.py

index 5f546a100dd3c93a1ea426b9635528110fdee147..b46b4d8f069303ed864e6691507de60a45cf33c5 100644 (file)
@@ -87,7 +87,7 @@ class dc_join(object):
         ctx.forest_domain_name = ctx.get_forest_domain_name()
         ctx.invocation_id = misc.GUID(str(uuid.uuid4()))
 
-        ctx.dc_ntds_dn = ctx.get_dsServiceName()
+        ctx.dc_ntds_dn = ctx.samdb.get_dsServiceName()
         ctx.dc_dnsHostName = ctx.get_dnsHostName()
         ctx.behavior_version = ctx.get_behavior_version()
 
@@ -207,10 +207,6 @@ class dc_join(object):
         return ctx.cldap_ret.pdc_dns_name
 
 
-    def get_dsServiceName(ctx):
-        res = ctx.samdb.search(base="", scope=ldb.SCOPE_BASE, attrs=["dsServiceName"])
-        return res[0]["dsServiceName"][0]
-
     def get_behavior_version(ctx):
         res = ctx.samdb.search(base=ctx.base_dn, scope=ldb.SCOPE_BASE, attrs=["msDS-Behavior-Version"])
         if "msDS-Behavior-Version" in res[0]:
index c508e2f331aba518c23910e9bd1ec76b16e7ef95..0d93298e979c493ed1097b4013676bf4c007de6f 100644 (file)
@@ -80,11 +80,6 @@ def drs_parse_ntds_dn(ntds_dn):
 
 
 
-def get_dsServiceName(samdb):
-    '''get the NTDS DN from the rootDSE'''
-    res = samdb.search(base="", scope=ldb.SCOPE_BASE, attrs=["dsServiceName"])
-    return res[0]["dsServiceName"][0]
-
 
 
 class cmd_drs_showrepl(Command):
@@ -133,7 +128,7 @@ class cmd_drs_showrepl(Command):
         samdb_connect(self)
 
         # show domain information
-        ntds_dn = get_dsServiceName(self.samdb)
+        ntds_dn = self.samdb.get_dsServiceName()
         server_dns = self.samdb.search(base="", scope=ldb.SCOPE_BASE, attrs=["dnsHostName"])[0]['dnsHostName'][0]
 
         (site, server) = drs_parse_ntds_dn(ntds_dn)
@@ -446,7 +441,7 @@ class cmd_drs_options(Command):
 
         samdb_connect(self)
 
-        ntds_dn = get_dsServiceName(self.samdb)
+        ntds_dn = self.samdb.get_dsServiceName()
         res = self.samdb.search(base=ntds_dn, scope=ldb.SCOPE_BASE, attrs=["options"])
         dsa_opts = int(res[0]["options"][0])
 
index 77d469a5dddc69b3a1c2c8b4818c1793151d5263..b0500362ef480ae01bbb01ad2ac50438458329b5 100644 (file)
@@ -59,11 +59,6 @@ class cmd_rodc_preload(Command):
         return str(res[0]["dn"])
 
 
-    def get_dsServiceName(self, samdb):
-        res = samdb.search(base="", scope=ldb.SCOPE_BASE, attrs=["dsServiceName"])
-        return res[0]["dsServiceName"][0]
-
-
     def run(self, account, sambaopts=None,
             credopts=None, versionopts=None, server=None):
 
@@ -83,7 +78,7 @@ class cmd_rodc_preload(Command):
                             credentials=creds, lp=lp)
 
         # work out the source and destination GUIDs
-        dc_ntds_dn = self.get_dsServiceName(samdb)
+        dc_ntds_dn = samdb.get_dsServiceName()
         res = samdb.search(base=dc_ntds_dn, scope=ldb.SCOPE_BASE, attrs=["invocationId"])
         source_dsa_invocation_id = misc.GUID(local_samdb.schema_format_value("objectGUID", res[0]["invocationId"][0]))
 
index 0ad6857cac21ca39c5b7d9f8f71d248c8510b675..4bd1acde4c36bb721bbd6c6baaf16438c6e155f8 100644 (file)
@@ -843,3 +843,13 @@ accountExpires: %u
         else:
             self.transaction_commit()
         return seq
+
+    def get_dsServiceName(self):
+        '''get the NTDS DN from the rootDSE'''
+        res = self.search(base="", scope=ldb.SCOPE_BASE, attrs=["dsServiceName"])
+        return res[0]["dsServiceName"][0]
+
+    def get_serverName(self):
+        '''get the server DN from the rootDSE'''
+        res = self.search(base="", scope=ldb.SCOPE_BASE, attrs=["serverName"])
+        return res[0]["serverName"][0]