summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/Admin
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2013-01-16 13:28:06 -0500
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2013-01-17 09:25:45 -0500
commitebe7542db7217c2fac3d7111e80f94caedfb69e2 (patch)
tree964db7ae511795d80b3ae50f3e14bc9f3344756a /src/lib/Bcfg2/Server/Admin
parentae58c24f72a8ed72327fbc3f7305bd69ec6a13db (diff)
downloadbcfg2-ebe7542db7217c2fac3d7111e80f94caedfb69e2.tar.gz
bcfg2-ebe7542db7217c2fac3d7111e80f94caedfb69e2.tar.bz2
bcfg2-ebe7542db7217c2fac3d7111e80f94caedfb69e2.zip
added module-level OptionParser to avoid passing it as an argument or global all over
Diffstat (limited to 'src/lib/Bcfg2/Server/Admin')
-rw-r--r--src/lib/Bcfg2/Server/Admin/Compare.py4
-rw-r--r--src/lib/Bcfg2/Server/Admin/Init.py24
-rw-r--r--src/lib/Bcfg2/Server/Admin/Perf.py22
-rw-r--r--src/lib/Bcfg2/Server/Admin/Pull.py4
-rw-r--r--src/lib/Bcfg2/Server/Admin/Reports.py4
-rw-r--r--src/lib/Bcfg2/Server/Admin/Snapshots.py4
-rw-r--r--src/lib/Bcfg2/Server/Admin/Syncdb.py10
-rw-r--r--src/lib/Bcfg2/Server/Admin/Xcmd.py29
-rw-r--r--src/lib/Bcfg2/Server/Admin/__init__.py20
9 files changed, 61 insertions, 60 deletions
diff --git a/src/lib/Bcfg2/Server/Admin/Compare.py b/src/lib/Bcfg2/Server/Admin/Compare.py
index c56dd0a8f..820271a2f 100644
--- a/src/lib/Bcfg2/Server/Admin/Compare.py
+++ b/src/lib/Bcfg2/Server/Admin/Compare.py
@@ -9,8 +9,8 @@ class Compare(Bcfg2.Server.Admin.Mode):
__usage__ = ("<old> <new>\n\n"
" -r\trecursive")
- def __init__(self, setup):
- Bcfg2.Server.Admin.Mode.__init__(self, setup)
+ def __init__(self):
+ Bcfg2.Server.Admin.Mode.__init__(self)
self.important = {'Path': ['name', 'type', 'owner', 'group', 'mode',
'important', 'paranoid', 'sensitive',
'dev_type', 'major', 'minor', 'prune',
diff --git a/src/lib/Bcfg2/Server/Admin/Init.py b/src/lib/Bcfg2/Server/Admin/Init.py
index 14065980d..cf4bd4c0c 100644
--- a/src/lib/Bcfg2/Server/Admin/Init.py
+++ b/src/lib/Bcfg2/Server/Admin/Init.py
@@ -143,14 +143,9 @@ def create_conf(confpath, confdata):
class Init(Bcfg2.Server.Admin.Mode):
"""Interactively initialize a new repository."""
- options = {'configfile': Bcfg2.Options.CFILE,
- 'plugins': Bcfg2.Options.SERVER_PLUGINS,
- 'proto': Bcfg2.Options.SERVER_PROTOCOL,
- 'repo': Bcfg2.Options.SERVER_REPOSITORY,
- 'sendmail': Bcfg2.Options.SENDMAIL_PATH}
-
- def __init__(self, setup):
- Bcfg2.Server.Admin.Mode.__init__(self, setup)
+
+ def __init__(self):
+ Bcfg2.Server.Admin.Mode.__init__(self)
self.data = dict()
self.plugins = Bcfg2.Options.SERVER_PLUGINS.default
@@ -177,9 +172,16 @@ class Init(Bcfg2.Server.Admin.Mode):
Bcfg2.Server.Admin.Mode.__call__(self, args)
# Parse options
- opts = Bcfg2.Options.OptionParser(self.options)
- opts.parse(args)
- self._set_defaults(opts)
+ setup = Bcfg2.Options.get_option_parser()
+ setup.add_options(dict(configfile=Bcfg2.Options.CFILE,
+ plugins=Bcfg2.Options.SERVER_PLUGINS,
+ proto=Bcfg2.Options.SERVER_PROTOCOL,
+ repo=Bcfg2.Options.SERVER_REPOSITORY,
+ sendmail=Bcfg2.Options.SENDMAIL_PATH))
+ opts = sys.argv[1:]
+ opts.remove(self.__class__.__name__.lower())
+ setup.reparse(argv=opts)
+ self._set_defaults(setup)
# Prompt the user for input
self._prompt_config()
diff --git a/src/lib/Bcfg2/Server/Admin/Perf.py b/src/lib/Bcfg2/Server/Admin/Perf.py
index 86eb6810d..7448855ce 100644
--- a/src/lib/Bcfg2/Server/Admin/Perf.py
+++ b/src/lib/Bcfg2/Server/Admin/Perf.py
@@ -11,17 +11,17 @@ class Perf(Bcfg2.Server.Admin.Mode):
def __call__(self, args):
output = [('Name', 'Min', 'Max', 'Mean', 'Count')]
- optinfo = {
- 'ca': Bcfg2.Options.CLIENT_CA,
- 'certificate': Bcfg2.Options.CLIENT_CERT,
- 'key': Bcfg2.Options.SERVER_KEY,
- 'password': Bcfg2.Options.SERVER_PASSWORD,
- 'server': Bcfg2.Options.SERVER_LOCATION,
- 'user': Bcfg2.Options.CLIENT_USER,
- 'timeout': Bcfg2.Options.CLIENT_TIMEOUT,
- }
- setup = Bcfg2.Options.OptionParser(optinfo)
- setup.parse(sys.argv[1:])
+ setup = Bcfg2.Options.get_option_parser()
+ setup.add_options(dict(ca=Bcfg2.Options.CLIENT_CA,
+ certificate=Bcfg2.Options.CLIENT_CERT,
+ key=Bcfg2.Options.SERVER_KEY,
+ password=Bcfg2.Options.SERVER_PASSWORD,
+ server=Bcfg2.Options.SERVER_LOCATION,
+ user=Bcfg2.Options.CLIENT_USER,
+ timeout=Bcfg2.Options.CLIENT_TIMEOUT))
+ opts = sys.argv[1:]
+ opts.remove(self.__class__.__name__.lower())
+ setup.reparse(argv=opts)
proxy = Bcfg2.Proxy.ComponentProxy(setup['server'],
setup['user'],
setup['password'],
diff --git a/src/lib/Bcfg2/Server/Admin/Pull.py b/src/lib/Bcfg2/Server/Admin/Pull.py
index 130e85b67..1905fac3c 100644
--- a/src/lib/Bcfg2/Server/Admin/Pull.py
+++ b/src/lib/Bcfg2/Server/Admin/Pull.py
@@ -22,8 +22,8 @@ class Pull(Bcfg2.Server.Admin.MetadataCore):
"-I", "interactive",
"-s", "stdin"))
- def __init__(self, setup):
- Bcfg2.Server.Admin.MetadataCore.__init__(self, setup)
+ def __init__(self):
+ Bcfg2.Server.Admin.MetadataCore.__init__(self)
self.log = False
self.mode = 'interactive'
diff --git a/src/lib/Bcfg2/Server/Admin/Reports.py b/src/lib/Bcfg2/Server/Admin/Reports.py
index 6e313e84b..bb5ee352b 100644
--- a/src/lib/Bcfg2/Server/Admin/Reports.py
+++ b/src/lib/Bcfg2/Server/Admin/Reports.py
@@ -69,8 +69,8 @@ class Reports(Bcfg2.Server.Admin.Mode):
" Django commands:\n " \
+ "\n ".join(django_commands))
- def __init__(self, setup):
- Bcfg2.Server.Admin.Mode.__init__(self, setup)
+ def __init__(self):
+ Bcfg2.Server.Admin.Mode.__init__(self)
try:
import south
except ImportError:
diff --git a/src/lib/Bcfg2/Server/Admin/Snapshots.py b/src/lib/Bcfg2/Server/Admin/Snapshots.py
index c2d279391..bf44d1451 100644
--- a/src/lib/Bcfg2/Server/Admin/Snapshots.py
+++ b/src/lib/Bcfg2/Server/Admin/Snapshots.py
@@ -21,8 +21,8 @@ class Snapshots(Bcfg2.Server.Admin.Mode):
'package': Package,
'snapshot': Snapshot}
- def __init__(self, setup):
- Bcfg2.Server.Admin.Mode.__init__(self, setup)
+ def __init__(self):
+ Bcfg2.Server.Admin.Mode.__init__(self)
self.session = Bcfg2.Server.Snapshots.setup_session(self.configfile)
self.cfile = self.configfile
diff --git a/src/lib/Bcfg2/Server/Admin/Syncdb.py b/src/lib/Bcfg2/Server/Admin/Syncdb.py
index 4ba840b86..84ad93ae0 100644
--- a/src/lib/Bcfg2/Server/Admin/Syncdb.py
+++ b/src/lib/Bcfg2/Server/Admin/Syncdb.py
@@ -8,15 +8,17 @@ from django.core.management import setup_environ, call_command
class Syncdb(Bcfg2.Server.Admin.Mode):
""" Sync the Django ORM with the configured database """
- options = {'configfile': Bcfg2.Options.WEB_CFILE}
def __call__(self, args):
# Parse options
- opts = Bcfg2.Options.OptionParser(self.options)
- opts.parse(args)
+ setup = Bcfg2.Options.get_option_parser()
+ setup.add_option("web_configfile", Bcfg2.Options.WEB_CFILE)
+ opts = sys.argv[1:]
+ opts.remove(self.__class__.__name__.lower())
+ setup.reparse(argv=opts)
setup_environ(Bcfg2.settings)
- Bcfg2.Server.models.load_models(cfile=opts['configfile'])
+ Bcfg2.Server.models.load_models(cfile=setup['web_configfile'])
try:
call_command("syncdb", interactive=False, verbosity=0)
diff --git a/src/lib/Bcfg2/Server/Admin/Xcmd.py b/src/lib/Bcfg2/Server/Admin/Xcmd.py
index 79eeebc7c..7f9f32816 100644
--- a/src/lib/Bcfg2/Server/Admin/Xcmd.py
+++ b/src/lib/Bcfg2/Server/Admin/Xcmd.py
@@ -12,17 +12,17 @@ class Xcmd(Bcfg2.Server.Admin.Mode):
__usage__ = "<command>"
def __call__(self, args):
- optinfo = {
- 'server': Bcfg2.Options.SERVER_LOCATION,
- 'user': Bcfg2.Options.CLIENT_USER,
- 'password': Bcfg2.Options.SERVER_PASSWORD,
- 'key': Bcfg2.Options.SERVER_KEY,
- 'certificate': Bcfg2.Options.CLIENT_CERT,
- 'ca': Bcfg2.Options.CLIENT_CA,
- 'timeout': Bcfg2.Options.CLIENT_TIMEOUT,
- }
- setup = Bcfg2.Options.OptionParser(optinfo)
- setup.parse(args)
+ setup = Bcfg2.Options.get_option_parser()
+ setup.add_options(dict(ca=Bcfg2.Options.CLIENT_CA,
+ certificate=Bcfg2.Options.CLIENT_CERT,
+ key=Bcfg2.Options.SERVER_KEY,
+ password=Bcfg2.Options.SERVER_PASSWORD,
+ server=Bcfg2.Options.SERVER_LOCATION,
+ user=Bcfg2.Options.CLIENT_USER,
+ timeout=Bcfg2.Options.CLIENT_TIMEOUT))
+ opts = sys.argv[1:]
+ opts.remove(self.__class__.__name__.lower())
+ setup.reparse(argv=opts)
Bcfg2.Proxy.RetryMethod.max_retries = 1
proxy = Bcfg2.Proxy.ComponentProxy(setup['server'],
setup['user'],
@@ -34,12 +34,9 @@ class Xcmd(Bcfg2.Server.Admin.Mode):
if len(setup['args']) == 0:
print("Usage: xcmd <xmlrpc method> <optional arguments>")
return
- cmd = setup['args'][0]
- args = ()
- if len(setup['args']) > 1:
- args = tuple(setup['args'][1:])
+ cmd = args[0]
try:
- data = getattr(proxy, cmd)(*args)
+ data = getattr(proxy, cmd)(*setup['args'])
except xmlrpclib.Fault:
flt = sys.exc_info()[1]
if flt.faultCode == 7:
diff --git a/src/lib/Bcfg2/Server/Admin/__init__.py b/src/lib/Bcfg2/Server/Admin/__init__.py
index 19175533f..20577633a 100644
--- a/src/lib/Bcfg2/Server/Admin/__init__.py
+++ b/src/lib/Bcfg2/Server/Admin/__init__.py
@@ -35,15 +35,15 @@ class Mode(object):
__usage__ = None
__args__ = []
- def __init__(self, setup):
- self.setup = setup
- self.configfile = setup['configfile']
+ def __init__(self):
+ self.setup = Bcfg2.Options.get_option_parser()
+ self.configfile = self.setup['configfile']
self.__cfp = False
self.log = logging.getLogger('Bcfg2.Server.Admin.Mode')
usage = "bcfg2-admin %s" % self.__class__.__name__.lower()
if self.__usage__ is not None:
usage += " " + self.__usage__
- setup.hm = usage
+ self.setup.hm = usage
def getCFP(self):
""" get a config parser for the Bcfg2 config file """
@@ -129,19 +129,19 @@ class MetadataCore(Mode):
__plugin_whitelist__ = None
__plugin_blacklist__ = None
- def __init__(self, setup):
- Mode.__init__(self, setup)
+ def __init__(self):
+ Mode.__init__(self)
if self.__plugin_whitelist__ is not None:
- setup['plugins'] = [p for p in setup['plugins']
+ self.setup['plugins'] = [p for p in self.setup['plugins']
if p in self.__plugin_whitelist__]
elif self.__plugin_blacklist__ is not None:
- setup['plugins'] = [p for p in setup['plugins']
+ self.setup['plugins'] = [p for p in self.setup['plugins']
if p not in self.__plugin_blacklist__]
# admin modes don't need to watch for changes. one shot is fine here.
- setup['filemonitor'] = 'pseudo'
+ self.setup['filemonitor'] = 'pseudo'
try:
- self.bcore = Bcfg2.Server.Core.BaseCore(setup)
+ self.bcore = Bcfg2.Server.Core.BaseCore()
except Bcfg2.Server.Core.CoreInitError:
msg = sys.exc_info()[1]
self.errExit("Core load failed: %s" % msg)