summaryrefslogtreecommitdiffstats
path: root/src/sbin
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2007-12-31 11:21:10 +0000
committerNarayan Desai <desai@mcs.anl.gov>2007-12-31 11:21:10 +0000
commitef5051726a3aa1f0192bd8d99c5c5b1ee9f067af (patch)
tree57bf0854d95c18cced379921657f746ad5faab04 /src/sbin
parent104a1e27cee2d5524460d26c83d3e920cd88b2e9 (diff)
downloadbcfg2-ef5051726a3aa1f0192bd8d99c5c5b1ee9f067af.tar.gz
bcfg2-ef5051726a3aa1f0192bd8d99c5c5b1ee9f067af.tar.bz2
bcfg2-ef5051726a3aa1f0192bd8d99c5c5b1ee9f067af.zip
Switch over to more Options usage and complete tests (everything appears to work now)
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4142 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/sbin')
-rwxr-xr-xsrc/sbin/bcfg2-admin10
-rwxr-xr-xsrc/sbin/bcfg2-info14
-rwxr-xr-xsrc/sbin/bcfg2-ping-sweep22
-rwxr-xr-xsrc/sbin/bcfg2-query12
-rwxr-xr-xsrc/sbin/bcfg2-repo-validate33
-rwxr-xr-xsrc/sbin/bcfg2-server23
6 files changed, 46 insertions, 68 deletions
diff --git a/src/sbin/bcfg2-admin b/src/sbin/bcfg2-admin
index ba979ec3b..fb9a58c7d 100755
--- a/src/sbin/bcfg2-admin
+++ b/src/sbin/bcfg2-admin
@@ -3,7 +3,6 @@
import getopt, difflib, logging, lxml.etree, os, popen2, re, socket, sys, ConfigParser
import Bcfg2.Server.Core, Bcfg2.Logging
-from Bcfg2.Settings import settings
log = logging.getLogger('bcfg-admin')
@@ -19,7 +18,8 @@ def mode_import(modename):
if __name__ == '__main__':
Bcfg2.Logging.setup_logging('bcfg2-admin', to_console=True)
- configfile = settings.CONFIG_FILE
+ # Some sensible defaults
+ configfile = "/etc/bcfg2.conf"
try:
opts, args = getopt.getopt(sys.argv[1:], 'hC:', ['help', 'configfile='])
@@ -36,9 +36,6 @@ if __name__ == '__main__':
if opt in ("-C", "--configfile"):
configfile = arg
- # override default settings
- settings.read_config_file(configfile)
-
modes = [x.lower() for x in Bcfg2.Server.Admin.__all__]
modes.remove('mode')
@@ -55,8 +52,7 @@ if __name__ == '__main__':
mode_cls = mode_import(modname)
except ImportError, e:
log.error("Failed to load admin mod %s: %s" % (modname, e))
- raise SystemExit(0)
- mode = mode_cls()
+ mode = mode_cls(configfile)
mode(args[1:])
else:
print "unknown mode %s" % args[0]
diff --git a/src/sbin/bcfg2-info b/src/sbin/bcfg2-info
index 6693efea2..bde7ef868 100755
--- a/src/sbin/bcfg2-info
+++ b/src/sbin/bcfg2-info
@@ -6,7 +6,6 @@ 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')
@@ -263,16 +262,11 @@ if __name__ == '__main__':
Bcfg2.Logging.setup_logging('bcfg2-info', to_syslog=False)
optinfo = {
- 'configfile': (('-C', '<configfile>', "use given config file (default /etc/bcfg2.conf)"),
- False, False, '/etc/bcfg2.conf', False),
- 'help': (('-h', False, "print this help message"),
- False, False, False, True)
+ 'configfile': Bcfg2.Options.CFILE,
+ 'help': Bcfg2.Options.HELP,
}
- optparser = Bcfg2.Options.OptionParser('bcfg2-info', optinfo)
- setup = optparser.parse()
-
- # override default settings
- settings.read_config_file(setup['configfile'])
+ setup = Bcfg2.Options.OptionParser(optinfo)
+ setup.parse(sys.argv[1:])
loop = infoCore()
loop.plugins['Metadata'].load_probedata()
diff --git a/src/sbin/bcfg2-ping-sweep b/src/sbin/bcfg2-ping-sweep
index 02e6d1f0e..ae4918d1f 100755
--- a/src/sbin/bcfg2-ping-sweep
+++ b/src/sbin/bcfg2-ping-sweep
@@ -5,24 +5,20 @@
__revision__ = '$Revision$'
from os import dup2, execl, fork, uname, wait
-import lxml.etree, sys, time, ConfigParser
-from Bcfg2.Settings import settings
+import lxml.etree, sys, time
+import Bcfg2.Options
if __name__ == '__main__':
+ opts = {'repo': Bcfg2.Options.SERVER_REPOSITORY,
+ 'configfile': Bcfg2.Options.CFILE}
+ setup = Bcfg2.Options.OptionParser(opts)
+ setup.parse(sys.argv[1:])
-
- # override default settings
- if '-C' in sys.argv:
- settings.read_config_file(sys.argv[sys.argv.index('-C') + 1])
-
- clientdatapath = "%s/Metadata/clients.xml" % settings.SERVER_REPOSITORY
+ cfpath opts['configfile']
+ clientdatapath = "%s/Metadata/clients.xml" % opts['repo']
- try:
- clientElement = lxml.etree.parse(clientdatapath)
- except:
- print "Failed to parse '%s'" % clientdatapath
- raise SystemExit, 1
+ clientElement = lxml.etree.parse(clientdatapath)
hostlist = [client.get('name') for client in clientElement.findall("Client")]
pids = {}
diff --git a/src/sbin/bcfg2-query b/src/sbin/bcfg2-query
index 46d4fab3c..3f0209192 100755
--- a/src/sbin/bcfg2-query
+++ b/src/sbin/bcfg2-query
@@ -1,10 +1,13 @@
#!/usr/bin/python
-# FIXME add -C <configfile> support
-
import lxml.etree, sys, ConfigParser
-from Bcfg2.Settings import settings
+CP = ConfigParser.ConfigParser()
+CP.read(['/etc/bcfg2.conf'])
+try:
+ prefix = CP.get('server', 'repository')
+except:
+ prefix = "/var/lib/bcfg2"
if len(sys.argv) < 2:
print "Usage bcfg2-query -d|u|p <profile name>"
@@ -17,9 +20,6 @@ if len(sys.argv) < 2:
print "\t -a\t shows all clients"
sys.exit(1)
-prefix = settings.SERVER_REPOSITORY
-
-
xml = lxml.etree.parse('%s/Metadata/clients.xml'%prefix)
if '-p' in sys.argv:
profile = sys.argv[sys.argv.index('-p') + 1]
diff --git a/src/sbin/bcfg2-repo-validate b/src/sbin/bcfg2-repo-validate
index ebfd87f25..09abcba98 100755
--- a/src/sbin/bcfg2-repo-validate
+++ b/src/sbin/bcfg2-repo-validate
@@ -3,24 +3,23 @@
'''bcfg2-repo-validate checks all xml files in Bcfg2 repos against their respective XML schemas'''
__revision__ = '$Revision$'
-import glob, lxml.etree, os, sys, ConfigParser
-from Bcfg2.Settings import settings
+import glob, lxml.etree, os, sys
-if __name__ == '__main__':
- verbose = False
- if '-v' in sys.argv:
- verbose = True
- sys.argv.remove('-v')
- # override default settings
- if '-C' in sys.argv:
- settings.read_config_file(sys.argv[sys.argv.index('-C') + 1])
+import Bcfg2.Options
- schemadir = "%s/share/bcfg2/schemas" % (settings.SERVER_PREFIX)
- try:
- os.chdir(schemadir)
- except:
- print "Failed to change to schema dir '%s'" % schemadir
- raise SystemExit(1)
+if __name__ == '__main__':
+ opts = {'repo': Bcfg2.Options.SERVER_REPOSITORY,
+ 'prefix': Bcfg2.Options.INSTALL_PREFIX,
+ 'verbose': Bcfg2.Options.VERBOSE,
+ 'configfile': Bcfg2.Options.CFILE}
+ setup = Bcfg2.Options.OptionParser(opts)
+ setup.parse(sys.argv[1:])
+ verbose = opts['verbose']
+ cpath = opts['configfile']
+ prefix = opts['prefix']
+ schemadir = "%s/share/bcfg2/schemas" % (prefix)
+ os.chdir(schemadir)
+ repo = opts['repo']
filesets = {'metadata':("%s/Metadata/groups.xml", "%s/metadata.xsd"),
'clients':("%s/Metadata/clients.xml", "%s/clients.xsd"),
@@ -40,7 +39,7 @@ if __name__ == '__main__':
print "Failed to process schema %s" % (schemaname%(schemadir))
failures = 1
continue
- for filename in glob.glob(spec%(settings.SERVER_REPOSITORY)):
+ for filename in glob.glob(spec%(repo)):
try:
datafile = lxml.etree.parse(open(filename))
except SyntaxError:
diff --git a/src/sbin/bcfg2-server b/src/sbin/bcfg2-server
index 554a5ae24..4c941e0ac 100755
--- a/src/sbin/bcfg2-server
+++ b/src/sbin/bcfg2-server
@@ -5,7 +5,6 @@ __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
@@ -176,19 +175,16 @@ class Bcfg2Serv(Bcfg2.Component.Component):
if __name__ == '__main__':
OPTINFO = {
- 'verbose': (('-v', False, 'enable verbose output'),
- False, False, False, True),
- 'debug': (('-d', False, 'enable debugging output'),
- False, False, False, True),
- 'help': (('-h', False, 'display this usage information'),
- False, False, False, True),
- 'daemon': (('-D', '<pidfile>', 'daemonize the server, storing PID'),
- False, False, False, False),
- 'configfile': (('-C', '<conffile>', 'use this config file'),
- False, False, False, False),
+ 'verbose': Bcfg2.Options.VERBOSE,
+ 'debug': Bcfg2.Options.DEBUG,
+ 'help': Bcfg2.Options.HELP,
+ 'daemon': Bcfg2.Options.DAEMON,
+ 'configfile': Bcfg2.Options.CFILE,
}
- SSETUP = Bcfg2.Options.OptionParser('bcfg2', OPTINFO).parse()
+ SSETUP = Bcfg2.Options.OptionParser(OPTINFO)
+ SSETUP.parse(sys.argv[1:])
+ print SSETUP
level = 0
if '-D' in sys.argv:
Bcfg2.Logging.setup_logging('bcfg2-server', to_console=False, level=level)
@@ -197,9 +193,6 @@ if __name__ == '__main__':
if SSETUP['daemon']:
Bcfg2.Daemon.daemonize(SSETUP['daemon'])
- # override default settings
- settings.read_config_file(SSETUP['configfile'])
-
try:
BSERV = Bcfg2Serv(SSETUP)
except SetupError: