mirror of
https://github.com/samba-team/samba.git
synced 2025-02-28 01:58:17 +03:00
upgradeprovision: Use logging infrastructure.
This commit is contained in:
parent
3552ad3ab1
commit
d9d0d54475
@ -22,9 +22,10 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
import shutil
|
||||
import logging
|
||||
import optparse
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
# Allow to run from s4 source directory (without installing samba)
|
||||
@ -120,22 +121,22 @@ parser.add_option("--full", help="Perform full upgrade of the samdb (schema, con
|
||||
|
||||
opts = parser.parse_args()[0]
|
||||
|
||||
handler = logging.StreamHandler(sys.stdout)
|
||||
upgrade_logger = logging.getLogger("upgradeprovision")
|
||||
upgrade_logger.addHandler(handler)
|
||||
|
||||
provision_logger = logging.getLogger("provision")
|
||||
provision_logger.addHandler(handler)
|
||||
|
||||
whatToLog = define_what_to_log(opts)
|
||||
|
||||
def messageprovision(text):
|
||||
"""Print a message if quiet is not set
|
||||
|
||||
:param text: Message to print """
|
||||
if opts.debugprovision or opts.debugall:
|
||||
print text
|
||||
|
||||
def message(what,text):
|
||||
def message(what, text):
|
||||
"""Print a message if this message type has been selected to be printed
|
||||
|
||||
:param what: Category of the message
|
||||
:param text: Message to print """
|
||||
if (whatToLog & what) or what <= 0:
|
||||
print text
|
||||
upgrade_logger.info("%s", text)
|
||||
|
||||
if len(sys.argv) == 1:
|
||||
opts.interactive = True
|
||||
@ -199,10 +200,10 @@ def sanitychecks(credentials,session_info,names,paths):
|
||||
sam_ldb = Ldb(paths.samdb, session_info=session, credentials=creds,lp=lp,options=["modules:samba_dsdb"])
|
||||
|
||||
sam_ldb.set_session_info(session)
|
||||
res = sam_ldb.search(expression="objectClass=ntdsdsa",base=str(names.configdn),
|
||||
scope=SCOPE_SUBTREE,attrs=["dn"],controls=["search_options:1:2"])
|
||||
res = sam_ldb.search(expression="objectClass=ntdsdsa", base=str(names.configdn),
|
||||
scope=SCOPE_SUBTREE, attrs=["dn"], controls=["search_options:1:2"])
|
||||
if len(res) == 0:
|
||||
print "No DC found, your provision is most probalby hardly broken !"
|
||||
print "No DC found, your provision is most probably hardly broken !"
|
||||
return False
|
||||
elif len(res) != 1:
|
||||
print "Found %d domain controllers, for the moment upgradeprovision is not able to handle upgrade on \
|
||||
@ -945,7 +946,7 @@ if __name__ == '__main__':
|
||||
# With all this information let's create a fresh new provision used as reference
|
||||
message(SIMPLE, "Creating a reference provision")
|
||||
provisiondir = tempfile.mkdtemp(dir=paths.private_dir, prefix="referenceprovision")
|
||||
newprovision(names, setup_dir, creds, session, smbconf, provisiondir, messageprovision)
|
||||
newprovision(names, setup_dir, creds, session, smbconf, provisiondir, provision_logger)
|
||||
# Get file paths of this new provision
|
||||
newpaths = get_paths(param, targetdir=provisiondir)
|
||||
populate_backlink(newpaths, creds, session,names.schemadn)
|
||||
|
@ -54,11 +54,11 @@ def get_paths(param, targetdir=None, smbconf=None):
|
||||
smbconf = param.default_path()
|
||||
|
||||
if not os.path.exists(smbconf):
|
||||
raise ProvisioningError("Unable to find smb.conf ...")
|
||||
raise ProvisioningError("Unable to find smb.conf")
|
||||
|
||||
lp = param.LoadParm()
|
||||
lp.load(smbconf)
|
||||
paths = provision_paths_from_lp(lp,lp.get("realm"))
|
||||
paths = provision_paths_from_lp(lp, lp.get("realm"))
|
||||
return paths
|
||||
|
||||
|
||||
@ -71,7 +71,8 @@ def find_provision_key_parameters(param, credentials, session_info, paths,
|
||||
:param session_info: Session object
|
||||
:param paths: A list of path to provision object
|
||||
:param smbconf: Path to the smb.conf file
|
||||
:return: A list of key provision parameters"""
|
||||
:return: A list of key provision parameters
|
||||
"""
|
||||
|
||||
lp = param.LoadParm()
|
||||
lp.load(paths.smbconf)
|
||||
@ -80,14 +81,15 @@ def find_provision_key_parameters(param, credentials, session_info, paths,
|
||||
# NT domain, kerberos realm, root dn, domain dn, domain dns name
|
||||
names.domain = string.upper(lp.get("workgroup"))
|
||||
names.realm = lp.get("realm")
|
||||
basedn = "DC=" + names.realm.replace(".",",DC=")
|
||||
basedn = "DC=" + names.realm.replace(".", ",DC=")
|
||||
names.dnsdomain = names.realm
|
||||
names.realm = string.upper(names.realm)
|
||||
# netbiosname
|
||||
secrets_ldb = Ldb(paths.secrets, session_info=session_info,
|
||||
credentials=credentials,lp=lp, options=["modules:samba_secrets"])
|
||||
# Get the netbiosname first (could be obtained from smb.conf in theory)
|
||||
res = secrets_ldb.search(expression="(flatname=%s)"%names.domain,base="CN=Primary Domains", scope=SCOPE_SUBTREE, attrs=["sAMAccountName"])
|
||||
res = secrets_ldb.search(expression="(flatname=%s)" % names.domain,
|
||||
base="CN=Primary Domains", scope=SCOPE_SUBTREE, attrs=["sAMAccountName"])
|
||||
names.netbiosname = str(res[0]["sAMAccountName"]).replace("$","")
|
||||
|
||||
names.smbconf = smbconf
|
||||
|
@ -16,6 +16,7 @@
|
||||
# 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 logging
|
||||
import optparse
|
||||
import os, sys
|
||||
|
||||
@ -45,16 +46,19 @@ parser.add_option("--targetdir", type="string", metavar="DIR",
|
||||
|
||||
opts, args = parser.parse_args()
|
||||
|
||||
def message(text):
|
||||
"""Print a message if quiet is not set."""
|
||||
if not opts.quiet:
|
||||
print text
|
||||
|
||||
logger = logging.getLogger("upgrade")
|
||||
logger.addHandler(logging.StreamHandler(sys.stdout))
|
||||
if opts.quiet:
|
||||
logger.setLevel(logging.WARNING)
|
||||
else:
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
if len(args) < 1:
|
||||
parser.print_usage()
|
||||
sys.exit(1)
|
||||
|
||||
message("Reading Samba3 databases and smb.conf")
|
||||
logger.info("Reading Samba3 databases and smb.conf")
|
||||
|
||||
libdir = args[0]
|
||||
if not os.path.isdir(libdir):
|
||||
@ -68,7 +72,7 @@ else:
|
||||
|
||||
samba3 = Samba3(libdir, smbconf)
|
||||
|
||||
message("Provisioning")
|
||||
logger.info("Provisioning")
|
||||
|
||||
setup_dir = opts.setupdir
|
||||
if setup_dir is None:
|
||||
@ -78,6 +82,6 @@ lp = sambaopts.get_loadparm()
|
||||
smbconf = lp.configfile
|
||||
creds = credopts.get_credentials(lp)
|
||||
|
||||
upgrade_provision(samba3, setup_dir, message, credentials=creds,
|
||||
upgrade_provision(samba3, setup_dir, logger, credentials=creds,
|
||||
session_info=system_session(), smbconf=smbconf,
|
||||
targetdir=opts.targetdir)
|
||||
|
Loading…
x
Reference in New Issue
Block a user