From e8c9ba57d10d174c79ac1aae9b53661ee8464d0f Mon Sep 17 00:00:00 2001 From: Robert Gogolok Date: Sun, 30 Dec 2007 19:26:51 +0000 Subject: Settings class to remove redundant code for parsing config file. If a module wants to access bcfg2 settings: from Bcfg2.Settings import settings git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4131 ce84e21b-d406-0410-9b95-82705330c041 --- src/sbin/bcfg2 | 10 +++++++--- src/sbin/bcfg2-info | 10 +++++++--- src/sbin/bcfg2-server | 9 +++++++-- 3 files changed, 21 insertions(+), 8 deletions(-) (limited to 'src/sbin') diff --git a/src/sbin/bcfg2 b/src/sbin/bcfg2 index a25bab65f..62f2e1775 100755 --- a/src/sbin/bcfg2 +++ b/src/sbin/bcfg2 @@ -78,11 +78,11 @@ class Client: 'setup': (('-C', '', "use given config file (default /etc/bcfg2.conf)"), False, False, '/etc/bcfg2.conf', False), 'server': (('-S', '', 'the server hostname to connect to'), - False, ('components', 'bcfg2'), 'https://localhost:6789', False), + False, ('components', 'bcfg2'), False, False), 'user': (('-u', '', 'the user to provide for authentication'), - False, ('communication', 'user'), 'root', False), + False, ('communication', 'user'), False, False), 'password': (('-x', '', 'the password to provide for authentication'), - False, ('communication', 'password'), 'password', False), + False, ('communication', 'password'), False, False), 'retries': (('-R', '', 'the number of times to retry network communication'), False, ('communication', 'retries'), '3', False), 'kevlar': (('-k', False, "run in kevlar (bulletproof) mode"), @@ -99,6 +99,10 @@ class Client: optparser = Bcfg2.Options.OptionParser('bcfg2', optinfo) self.setup = optparser.parse() + + # override default settings + settings.read_config_file(self.setup['setup']) + if getopt.getopt(sys.argv[1:], optparser.shortopt, optparser.longopt)[1]: print "Bcfg2 takes no arguments, only options" diff --git a/src/sbin/bcfg2-info b/src/sbin/bcfg2-info index f40ef3e60..6693efea2 100755 --- a/src/sbin/bcfg2-info +++ b/src/sbin/bcfg2-info @@ -6,6 +6,7 @@ import copy, logging, lxml.etree, sys, time, cmd import Bcfg2.Logging, Bcfg2.Server.Core, os import Bcfg2.Server.Plugins.Metadata, Bcfg2.Server.Plugin import Bcfg2.Options +from Bcfg2.Settings import settings logger = logging.getLogger('bcfg2-info') @@ -23,10 +24,10 @@ def printTabular(rows): print fstring % row class infoCore(cmd.Cmd, Bcfg2.Server.Core.Core): - def __init__(self, cfpath): + def __init__(self): cmd.Cmd.__init__(self) try: - Bcfg2.Server.Core.Core.__init__(self, {}, cfpath) + Bcfg2.Server.Core.Core.__init__(self) except Bcfg2.Server.Core.CoreInitError, msg: print "Core load failed because %s" % msg raise SystemExit(1) @@ -270,6 +271,9 @@ if __name__ == '__main__': optparser = Bcfg2.Options.OptionParser('bcfg2-info', optinfo) setup = optparser.parse() - loop = infoCore(setup['configfile']) + # override default settings + settings.read_config_file(setup['configfile']) + + loop = infoCore() loop.plugins['Metadata'].load_probedata() loop.do_loop() diff --git a/src/sbin/bcfg2-server b/src/sbin/bcfg2-server index e6a00efbc..554a5ae24 100755 --- a/src/sbin/bcfg2-server +++ b/src/sbin/bcfg2-server @@ -5,6 +5,7 @@ __revision__ = '$Revision$' import Bcfg2.Server.Plugins.Metadata +from Bcfg2.Settings import settings from Bcfg2.Server.Core import Core, CoreInitError from xmlrpclib import Fault from lxml.etree import XML, Element, tostring @@ -39,7 +40,7 @@ class Bcfg2Serv(Bcfg2.Component.Component): raise SetupError try: - self.Core = Core(setup, setup['configfile']) + self.Core = Core() except CoreInitError, msg: logger.critical("Fatal error: %s" % (msg)) raise SystemExit, 1 @@ -184,7 +185,7 @@ if __name__ == '__main__': 'daemon': (('-D', '', 'daemonize the server, storing PID'), False, False, False, False), 'configfile': (('-C', '', 'use this config file'), - False, False, '/etc/bcfg2.conf', False), + False, False, False, False), } SSETUP = Bcfg2.Options.OptionParser('bcfg2', OPTINFO).parse() @@ -195,6 +196,10 @@ if __name__ == '__main__': Bcfg2.Logging.setup_logging('bcfg2-server', level=level) if SSETUP['daemon']: Bcfg2.Daemon.daemonize(SSETUP['daemon']) + + # override default settings + settings.read_config_file(SSETUP['configfile']) + try: BSERV = Bcfg2Serv(SSETUP) except SetupError: -- cgit v1.2.3-1-g7c22