summaryrefslogtreecommitdiffstats
path: root/src/sbin
diff options
context:
space:
mode:
Diffstat (limited to 'src/sbin')
-rwxr-xr-xsrc/sbin/bcfg27
-rwxr-xr-xsrc/sbin/bcfg2-admin4
-rwxr-xr-xsrc/sbin/bcfg2-build-reports306
-rwxr-xr-xsrc/sbin/bcfg2-crypt54
-rwxr-xr-xsrc/sbin/bcfg2-info13
-rwxr-xr-xsrc/sbin/bcfg2-lint40
-rwxr-xr-xsrc/sbin/bcfg2-report-collector4
-rwxr-xr-xsrc/sbin/bcfg2-server4
-rwxr-xr-xsrc/sbin/bcfg2-test2
9 files changed, 60 insertions, 374 deletions
diff --git a/src/sbin/bcfg2 b/src/sbin/bcfg2
index 444e86a7c..62f749b80 100755
--- a/src/sbin/bcfg2
+++ b/src/sbin/bcfg2
@@ -3,8 +3,8 @@
import sys
import signal
-import Bcfg2.Options
from Bcfg2.Client.Client import Client
+from Bcfg2.Options import load_option_parser, CLIENT_COMMON_OPTIONS
def cb_sigint_handler(signum, frame):
@@ -13,8 +13,7 @@ def cb_sigint_handler(signum, frame):
def main():
- optinfo = Bcfg2.Options.CLIENT_COMMON_OPTIONS
- setup = Bcfg2.Options.OptionParser(optinfo)
+ setup = load_option_parser(CLIENT_COMMON_OPTIONS)
setup.parse(sys.argv[1:])
if setup['args']:
@@ -23,7 +22,7 @@ def main():
raise SystemExit(1)
signal.signal(signal.SIGINT, cb_sigint_handler)
- return Client(setup).run()
+ return Client().run()
if __name__ == '__main__':
sys.exit(main())
diff --git a/src/sbin/bcfg2-admin b/src/sbin/bcfg2-admin
index 31e49c00b..3bce7fdab 100755
--- a/src/sbin/bcfg2-admin
+++ b/src/sbin/bcfg2-admin
@@ -42,7 +42,7 @@ def main():
optinfo = dict()
optinfo.update(Bcfg2.Options.CLI_COMMON_OPTIONS)
optinfo.update(Bcfg2.Options.SERVER_COMMON_OPTIONS)
- setup = Bcfg2.Options.OptionParser(optinfo)
+ setup = Bcfg2.Options.load_option_parser(optinfo)
# override default help message to include description of all modes
setup.hm = "Usage:\n\n%s\n%s" % (setup.buildHelpMessage(),
create_description())
@@ -81,7 +81,7 @@ def main():
err = sys.exc_info()[1]
log.error("Failed to load admin mode %s: %s" % (modname, err))
raise SystemExit(1)
- mode = mode_cls(setup)
+ mode = mode_cls()
try:
mode(setup['args'][1:])
finally:
diff --git a/src/sbin/bcfg2-build-reports b/src/sbin/bcfg2-build-reports
deleted file mode 100755
index 27e7c2475..000000000
--- a/src/sbin/bcfg2-build-reports
+++ /dev/null
@@ -1,306 +0,0 @@
-#!/usr/bin/env python
-
-"""
-bcfg2-build-reports generates & distributes reports of statistic
-information for Bcfg2."""
-
-import copy
-import getopt
-import re
-import os
-import socket
-import sys
-from time import asctime, strptime
-from lxml.etree import XML, XSLT, parse, Element, ElementTree, SubElement, tostring, XMLSyntaxError
-# Compatibility imports
-from Bcfg2.Compat import ConfigParser
-
-def generatereport(rspec, nrpt):
- """
- generatereport creates and returns an ElementTree representation
- of a report adhering to the XML spec for intermediate reports.
- """
- reportspec = copy.deepcopy(rspec)
- nodereprt = copy.deepcopy(nrpt)
-
- reportgood = reportspec.get("good", default = 'Y')
- reportmodified = reportspec.get("modified", default = 'Y')
- current_date = asctime()[:10]
-
- """Build regex of all the nodes we are reporting about."""
- pattern = re.compile( '|'.join([item.get("name") for item in reportspec.findall('Machine')]))
-
- for node in nodereprt.findall('Node'):
- if not (node.findall("Statistics") and pattern.match(node.get('name'))):
- # Don't know enough about node.
- nodereprt.remove(node)
- continue
-
- # Reduce to most recent Statistics entry.
- statisticslist = node.findall('Statistics')
- # This line actually sorts from most recent to oldest.
- statisticslist.sort(lambda y, x: cmp(strptime(x.get("time")), strptime(y.get("time"))))
- stats = statisticslist[0]
-
- [node.remove(item) for item in node.findall('Statistics')]
-
- # Add a good tag if node is good and we wnat to report such.
- if reportgood == 'Y' and stats.get('state') == 'clean':
- SubElement(stats,"Good")
-
- [stats.remove(item) for item in stats.findall("Bad") + stats.findall("Modified") if \
- item.getchildren() == []]
- [stats.remove(item) for item in stats.findall("Modified") if reportmodified == 'N']
-
- # Test for staleness -if stale add Stale tag.
- if stats.get("time").find(current_date) == -1:
- SubElement(stats,"Stale")
- node.append(stats)
- return nodereprt
-
-def mail(mailbody, confi):
- """mail mails a previously generated report."""
-
- try:
- mailer = confi.get('statistics', 'sendmailpath')
- except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
- mailer = "/usr/sbin/sendmail"
- # Open a pipe to the mail program and
- # write the data to the pipe.
- pipe = os.popen("%s -t" % mailer, 'w')
- pipe.write(mailbody)
- exitcode = pipe.close()
- if exitcode:
- print("Exit code: %s" % exitcode)
-
-def rss(reportxml, delivery, report):
- """rss appends a new report to the specified rss file
- keeping the last 9 articles.
- """
- # Check and see if rss file exists.
- for destination in delivery.findall('Destination'):
- try:
- fil = open(destination.attrib['address'], 'r')
- olddoc = XML(fil.read())
-
- # Defines the number of recent articles to keep.
- items = olddoc.find("channel").findall("item")[0:9]
- fil.close()
- fil = open(destination.attrib['address'], 'w')
- except (IOError, XMLSyntaxError):
- fil = open(destination.attrib['address'], 'w')
- items = []
-
- rssdata = Element("rss")
- channel = SubElement(rssdata, "channel")
- rssdata.set("version", "2.0")
- chantitle = SubElement(channel, "title")
- chantitle.text = report.attrib['name']
- chanlink = SubElement(channel, "link")
-
- # This can later link to WWW report if one gets published
- # simultaneously?
- chanlink.text = "http://www.mcs.anl.gov/cobalt/bcfg2"
- chandesc = SubElement(channel, "description")
- chandesc.text = "Information regarding the 10 most recent bcfg2 runs."
-
- channel.append(XML(reportxml))
-
- if items != []:
- for item in items:
- channel.append(item)
-
- tree = tostring(rssdata, xml_declaration=False).decode('UTF-8')
- fil.write(tree)
- fil.close()
-
-def www(reportxml, delivery):
- """www outputs report to."""
-
- # This can later link to WWW report if one gets published
- # simultaneously?
- for destination in delivery.findall('Destination'):
- fil = open(destination.attrib['address'], 'w')
-
- fil.write(reportxml)
- fil.close()
-
-def fileout(reportxml, delivery):
- """Outputs to plain text file."""
- for destination in delivery.findall('Destination'):
- fil = open(destination.attrib['address'], 'w')
-
- fil.write(reportxml)
- fil.close()
-
-def pretty_print(element, level=0):
- """Produce a pretty-printed text representation of element."""
- if element.text:
- fmt = "%s<%%s %%s>%%s</%%s>" % (level*" ")
- data = (element.tag, (" ".join(["%s='%s'" % keyval for keyval in list(element.attrib.items())])),
- element.text, element.tag)
- if element._children:
- fmt = "%s<%%s %%s>\n" % (level*" ",) + (len(element._children) * "%s") + "%s</%%s>\n" % (level*" ")
- data = (element.tag, ) + (" ".join(["%s='%s'" % keyval for keyval in list(element.attrib.items())]),)
- data += tuple([pretty_print(entry, level+2) for entry in element._children]) + (element.tag, )
- else:
- fmt = "%s<%%s %%s/>\n" % (level * " ")
- data = (element.tag, " ".join(["%s='%s'" % keyval for keyval in list(element.attrib.items())]))
- return fmt % data
-
-
-if __name__ == '__main__':
- all=False
- if '-C' in sys.argv:
- cfpath = sys.argv[sys.argv.index('-C') + 1]
- else:
- cfpath = '/etc/bcfg2.conf'
- c = ConfigParser.ConfigParser()
- c.read([cfpath])
- configpath = "%s/etc/report-configuration.xml" % c.get('server', 'repository')
- statpath = "%s/etc/statistics.xml" % c.get('server', 'repository')
- clientsdatapath = "%s/Metadata/clients.xml" % c.get('server', 'repository')
- try:
- prefix = c.get('server', 'prefix')
- except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
- prefix = '/usr'
-
- transformpath = "/%s/share/bcfg2/xsl-transforms/" % (prefix)
- #websrcspath = "/usr/share/bcfg2/web-rprt-srcs/"
-
- try:
- opts, args = getopt.getopt(sys.argv[1:], "C:hAc:Ns:", ["help", "all", "config=", "stats="])
- except getopt.GetoptError:
- mesg = sys.exc_info()[1]
- # Print help information and exit:
- print("%s\nUsage:\nbcfg2-build-reports [-h][-A (include ALL clients)] [-c <configuration-file>] [-s <statistics-file>]" % (mesg))
- raise SystemExit(2)
- for o, a in opts:
- if o in ("-h", "--help"):
- print("Usage:\nbcfg2-build-reports [-h] [-c <configuration-file>] [-s <statistics-file>]")
- raise SystemExit
- if o in ("-A", "--all"):
- all=True
- if o in ("-c", "--config"):
- configpath = a
- if o in ("-s", "--stats"):
- statpath = a
-
-
- """Reads data & config files."""
- try:
- statsdata = XML(open(statpath).read())
- except (IOError, XMLSyntaxError):
- print("bcfg2-build-reports: Failed to parse %s"%(statpath))
- raise SystemExit(1)
- try:
- configdata = XML(open(configpath).read())
- except (IOError, XMLSyntaxError):
- print("bcfg2-build-reports: Failed to parse %s"%(configpath))
- raise SystemExit(1)
- try:
- clientsdata = XML(open(clientsdatapath).read())
- except (IOError, XMLSyntaxError):
- print("bcfg2-build-reports: Failed to parse %s"%(clientsdatapath))
- raise SystemExit(1)
-
- # Merge data from three sources.
- nodereport = Element("Report", attrib={"time" : asctime()})
- # Should all of the other info in Metadata be appended?
- # What about all of the package stuff for other types of reports?
- for client in clientsdata.findall("Client"):
- nodel = Element("Node", attrib={"name" : client.get("name")})
- nodel.append(client)
- for nod in statsdata.findall("Node"):
- if client.get('name').find(nod.get('name')) == 0:
- for statel in nod.findall("Statistics"):
- nodel.append(statel)
- nodereport.append(nodel)
-
- if all:
- for nod in statsdata.findall("Node"):
- for client in clientsdata.findall("Client"):
- if client.get('name').find(nod.get('name')) == 0:
- break
- else:
- nodel = Element("Node", attrib={"name" : nod.get("name")})
- client = Element("Client", attrib={"name" : nod.get("name"), "profile" : "default"})
- nodel.append(client)
- for statel in nod.findall("Statistics"):
- nodel.append(statel)
- nodereport.append(nodel)
-
-
- for reprt in configdata.findall('Report'):
- nodereport.set("name", reprt.get("name", default="BCFG Report"))
-
- if reprt.get('refresh-time') != None:
- nodereport.set("refresh-time", reprt.get("refresh-time", default="600"))
-
- procnodereport = generatereport(reprt, nodereport)
-
- for deliv in reprt.findall('Delivery'):
- # Is a deepcopy of procnodereport necessary?
-
- delivtype = deliv.get('type', default='nodes-digest')
- deliverymechanism = deliv.get('mechanism', default='www')
-
- # Apply XSLT, different ones based on report type, and options
- if deliverymechanism == 'null-operator': # Special Cases
- fileout(tostring(ElementTree(procnodereport).getroot(), xml_declaration=False).decode('UTF-8'), deliv)
- break
- transform = delivtype + '-' + deliverymechanism + '.xsl'
-
- try: # Make sure valid stylesheet is selected.
- os.stat(transformpath + transform)
- except:
- print("bcfg2-build-reports: Invalid report type or delivery mechanism.\n Can't find: "\
- + transformpath + transform)
- raise SystemExit(1)
-
- try: # Try to parse stylesheet.
- stylesheet = XSLT(parse(transformpath + transform))
- except:
- print("bcfg2-build-reports: invalid XSLT transform file.")
- raise SystemExit(1)
-
- if deliverymechanism == 'mail':
- if delivtype == 'nodes-individual':
- reportdata = copy.deepcopy(procnodereport)
- for noden in reportdata.findall("Node"):
- [reportdata.remove(y) for y in reportdata.findall("Node")]
- reportdata.append(noden)
- result = stylesheet.apply(ElementTree(reportdata))
- outputstring = stylesheet.tostring(result)
-
- if not outputstring == None:
- toastring = ''
- for desti in deliv.findall("Destination"):
- toastring = "%s%s " % \
- (toastring, desti.get('address'))
- # Prepend To: and From:
- outputstring = "To: %s\nFrom: root@%s\n%s"% \
- (toastring, socket.getfqdn(), outputstring)
- mail(outputstring, c) #call function to send
-
- else:
- reportdata = copy.deepcopy(procnodereport)
-
- result = stylesheet.apply(ElementTree(reportdata))
- outputstring = stylesheet.tostring(result)
-
- if not outputstring == None:
- toastring = ''
- for desti in deliv.findall("Destination"):
- toastring = "%s%s " % \
- (toastring, desti.get('address'))
- # Prepend To: and From:
- outputstring = "To: %s\nFrom: root@%s\n%s"% \
- (toastring, socket.getfqdn(), outputstring)
- mail(outputstring, c) #call function to send
- else:
- outputstring = tostring(stylesheet.apply(ElementTree(procnodereport)).getroot(), xml_declaration=False).decode('UTF-8')
- if deliverymechanism == 'rss':
- rss(outputstring, deliv, reprt)
- else: # Must be deliverymechanism == 'www':
- www(outputstring, deliv)
diff --git a/src/sbin/bcfg2-crypt b/src/sbin/bcfg2-crypt
index eae316da5..f7deba90c 100755
--- a/src/sbin/bcfg2-crypt
+++ b/src/sbin/bcfg2-crypt
@@ -12,7 +12,7 @@ import Bcfg2.Options
from Bcfg2.Server import XMLParser
from Bcfg2.Compat import input # pylint: disable=W0622
try:
- import Bcfg2.Encryption
+ import Bcfg2.Server.Encryption
except ImportError:
print("Could not import %s. Is M2Crypto installed?" % sys.exc_info()[1])
raise SystemExit(1)
@@ -27,8 +27,8 @@ class EncryptionChunkingError(Exception):
class Encryptor(object):
""" Generic encryptor for all files """
- def __init__(self, setup):
- self.setup = setup
+ def __init__(self):
+ self.setup = Bcfg2.Options.get_option_parser()
self.passphrase = None
self.pname = None
self.logger = logging.getLogger(self.__class__.__name__)
@@ -55,8 +55,8 @@ class Encryptor(object):
def set_passphrase(self):
""" set the passphrase for the current file """
- if (not self.setup.cfp.has_section(Bcfg2.Encryption.CFG_SECTION) or
- len(Bcfg2.Encryption.get_passphrases(self.setup)) == 0):
+ if (not self.setup.cfp.has_section(Bcfg2.Server.Encryption.CFG_SECTION)
+ or len(Bcfg2.Server.Encryption.get_passphrases()) == 0):
self.logger.error("No passphrases available in %s" %
self.setup['configfile'])
return False
@@ -70,10 +70,10 @@ class Encryptor(object):
self.pname = self.setup['passphrase']
if self.pname:
- if self.setup.cfp.has_option(Bcfg2.Encryption.CFG_SECTION,
+ if self.setup.cfp.has_option(Bcfg2.Server.Encryption.CFG_SECTION,
self.pname):
self.passphrase = \
- self.setup.cfp.get(Bcfg2.Encryption.CFG_SECTION,
+ self.setup.cfp.get(Bcfg2.Server.Encryption.CFG_SECTION,
self.pname)
self.logger.debug("Using passphrase %s specified on command "
"line" % self.pname)
@@ -83,7 +83,7 @@ class Encryptor(object):
(self.pname, self.setup['configfile']))
return False
else:
- pnames = Bcfg2.Encryption.get_passphrases(self.setup)
+ pnames = Bcfg2.Server.Encryption.get_passphrases()
if len(pnames) == 1:
self.pname = pnames.keys()[0]
self.passphrase = pnames[self.pname]
@@ -127,9 +127,7 @@ class Encryptor(object):
# pylint: disable=W0613
def _encrypt(self, plaintext, passphrase, name=None):
""" encrypt a single chunk of a file """
- return Bcfg2.Encryption.ssl_encrypt(
- plaintext, passphrase,
- Bcfg2.Encryption.get_algorithm(self.setup))
+ return Bcfg2.Server.Encryption.ssl_encrypt(plaintext, passphrase)
# pylint: enable=W0613
def decrypt(self, fname):
@@ -150,7 +148,7 @@ class Encryptor(object):
passphrase, pname = self.get_passphrase(chunk)
try:
plaintext.append(self._decrypt(chunk, passphrase))
- except Bcfg2.Encryption.EVPError:
+ except Bcfg2.Server.Encryption.EVPError:
self.logger.info("Could not decrypt %s with the "
"specified passphrase" % fname)
continue
@@ -162,12 +160,12 @@ class Encryptor(object):
except TypeError:
pchunk = None
for pname, passphrase in \
- Bcfg2.Encryption.get_passphrases(self.setup).items():
+ Bcfg2.Server.Encryption.get_passphrases().items():
self.logger.debug("Trying passphrase %s" % pname)
try:
pchunk = self._decrypt(chunk, passphrase)
break
- except Bcfg2.Encryption.EVPError:
+ except Bcfg2.Server.Encryption.EVPError:
pass
except:
err = sys.exc_info()[1]
@@ -196,9 +194,7 @@ class Encryptor(object):
def _decrypt(self, crypted, passphrase):
""" decrypt a single chunk """
- return Bcfg2.Encryption.ssl_decrypt(
- crypted, passphrase,
- Bcfg2.Encryption.get_algorithm(self.setup))
+ return Bcfg2.Server.Encryption.ssl_decrypt(crypted, passphrase)
def write_encrypted(self, fname, data=None):
""" write encrypted data to disk """
@@ -243,10 +239,11 @@ class Encryptor(object):
self.logger.info("No passphrase given on command line or "
"found in file")
return False
- elif self.setup.cfp.has_option(Bcfg2.Encryption.CFG_SECTION,
+ elif self.setup.cfp.has_option(Bcfg2.Server.Encryption.CFG_SECTION,
pname):
- passphrase = self.setup.cfp.get(Bcfg2.Encryption.CFG_SECTION,
- pname)
+ passphrase = self.setup.cfp.get(
+ Bcfg2.Server.Encryption.CFG_SECTION,
+ pname)
else:
self.logger.error("Could not find passphrase %s in %s" %
(pname, self.setup['configfile']))
@@ -287,10 +284,9 @@ class PropertiesEncryptor(Encryptor):
if name is None:
name = "true"
if plaintext.text and plaintext.text.strip():
- plaintext.text = Bcfg2.Encryption.ssl_encrypt(
- plaintext.text,
- passphrase,
- Bcfg2.Encryption.get_algorithm(self.setup)).strip()
+ plaintext.text = \
+ Bcfg2.Server.Encryption.ssl_encrypt(plaintext.text,
+ passphrase).strip()
plaintext.set("encrypted", name)
return plaintext
@@ -358,10 +354,8 @@ class PropertiesEncryptor(Encryptor):
if not crypted.text or not crypted.text.strip():
self.logger.warning("Skipping empty element %s" % crypted.tag)
return crypted
- decrypted = Bcfg2.Encryption.ssl_decrypt(
- crypted.text,
- passphrase,
- Bcfg2.Encryption.get_algorithm(self.setup)).strip()
+ decrypted = Bcfg2.Server.Encryption.ssl_decrypt(crypted.text,
+ passphrase).strip()
try:
crypted.text = decrypted.encode('ascii', 'xmlcharrefreplace')
except UnicodeDecodeError:
@@ -379,10 +373,10 @@ def main(): # pylint: disable=R0912,R0915
optinfo = dict(interactive=Bcfg2.Options.INTERACTIVE)
optinfo.update(Bcfg2.Options.CRYPT_OPTIONS)
optinfo.update(Bcfg2.Options.CLI_COMMON_OPTIONS)
- setup = Bcfg2.Options.OptionParser(optinfo)
+ setup = Bcfg2.Options.load_option_parser(optinfo)
setup.hm = " bcfg2-crypt [options] <filename>\nOptions:\n%s" % \
setup.buildHelpMessage()
- setup.parse(sys.argv[1:])
+ setup.parse()
if not setup['args']:
print(setup.hm)
diff --git a/src/sbin/bcfg2-info b/src/sbin/bcfg2-info
index 391902e44..ad35bbeeb 100755
--- a/src/sbin/bcfg2-info
+++ b/src/sbin/bcfg2-info
@@ -115,9 +115,9 @@ def load_interpreters():
class InfoCore(cmd.Cmd, Bcfg2.Server.Core.BaseCore):
"""Main class for bcfg2-info."""
- def __init__(self, setup):
+ def __init__(self):
cmd.Cmd.__init__(self)
- Bcfg2.Server.Core.BaseCore.__init__(self, setup=setup)
+ Bcfg2.Server.Core.BaseCore.__init__(self)
self.prompt = '> '
self.cont = True
self.fam.handle_events_in_interval(4)
@@ -281,9 +281,8 @@ Bcfg2 client itself.""")
posix = Bcfg2.Client.Tools.POSIX.POSIX(MockLog(),
self.setup,
client_config)
- states = dict()
- posix.Inventory(states)
- posix.Install(list(states.keys()), states)
+ states = posix.Inventory()
+ posix.Install(list(states.keys()))
else:
print('Error: Incorrect number of parameters.')
self.help_builddir()
@@ -776,12 +775,12 @@ def main():
sys.exit(0)
elif setup['profile'] and HAS_PROFILE:
prof = profile.Profile()
- loop = prof.runcall(InfoCore, setup)
+ loop = prof.runcall(InfoCore)
display_trace(prof)
else:
if setup['profile']:
print("Profiling functionality not available.")
- loop = InfoCore(setup)
+ loop = InfoCore()
loop.run(setup['args'])
diff --git a/src/sbin/bcfg2-lint b/src/sbin/bcfg2-lint
index 430c4c54f..4f81df89c 100755
--- a/src/sbin/bcfg2-lint
+++ b/src/sbin/bcfg2-lint
@@ -13,37 +13,36 @@ import Bcfg2.Server.Lint
LOGGER = logging.getLogger('bcfg2-lint')
-def run_serverless_plugins(plugins, setup=None, errorhandler=None, files=None):
+def run_serverless_plugins(plugins, errorhandler=None, files=None):
""" Run serverless plugins """
LOGGER.debug("Running serverless plugins")
for plugin_name, plugin in list(plugins.items()):
- run_plugin(plugin, plugin_name, errorhandler=errorhandler,
- setup=setup, files=files)
+ run_plugin(plugin, plugin_name, errorhandler=errorhandler, files=files)
-def run_server_plugins(plugins, setup=None, errorhandler=None, files=None):
+def run_server_plugins(plugins, errorhandler=None, files=None):
""" run plugins that require a running server to run """
- core = load_server(setup)
+ core = load_server()
try:
LOGGER.debug("Running server plugins")
for plugin_name, plugin in list(plugins.items()):
run_plugin(plugin, plugin_name, args=[core],
- errorhandler=errorhandler, setup=setup, files=files)
+ errorhandler=errorhandler, files=files)
finally:
core.shutdown()
-def run_plugin(plugin, plugin_name, setup=None, errorhandler=None,
- args=None, files=None):
+def run_plugin(plugin, plugin_name, errorhandler=None, args=None, files=None):
""" run a single plugin, server-ful or serverless. """
LOGGER.debug(" Running %s" % plugin_name)
if args is None:
args = []
if errorhandler is None:
- errorhandler = get_errorhandler(setup)
+ errorhandler = get_errorhandler()
- if setup is not None and setup.cfp.has_section(plugin_name):
+ setup = Bcfg2.Options.get_option_parser()
+ if setup.cfp.has_section(plugin_name):
arg = setup
for key, val in setup.cfp.items(plugin_name):
arg[key] = val
@@ -55,8 +54,9 @@ def run_plugin(plugin, plugin_name, setup=None, errorhandler=None,
return plugin(*args, **dict(files=files, errorhandler=errorhandler)).Run()
-def get_errorhandler(setup):
+def get_errorhandler():
""" get a Bcfg2.Server.Lint.ErrorHandler object """
+ setup = Bcfg2.Options.get_option_parser()
if setup.cfp.has_section("errors"):
conf = dict(setup.cfp.items("errors"))
else:
@@ -64,9 +64,9 @@ def get_errorhandler(setup):
return Bcfg2.Server.Lint.ErrorHandler(config=conf)
-def load_server(setup):
+def load_server():
""" load server """
- core = Bcfg2.Server.Core.BaseCore(setup)
+ core = Bcfg2.Server.Core.BaseCore()
core.fam.handle_events_in_interval(4)
return core
@@ -83,8 +83,9 @@ def load_plugin(module, obj_name=None):
return getattr(mod, obj_name)
-def load_plugins(setup):
+def load_plugins():
""" get list of plugins to run """
+ setup = Bcfg2.Options.get_option_parser()
if setup['args']:
plugin_list = setup['args']
elif "bcfg2-repo-validate" in sys.argv[0]:
@@ -146,7 +147,7 @@ def main():
lint_plugins=Bcfg2.Options.LINT_PLUGINS)
optinfo.update(Bcfg2.Options.CLI_COMMON_OPTIONS)
optinfo.update(Bcfg2.Options.SERVER_COMMON_OPTIONS)
- setup = Bcfg2.Options.OptionParser(optinfo)
+ setup = Bcfg2.Options.load_option_parser(optinfo)
setup.parse(sys.argv[1:])
log_args = dict(to_syslog=setup['syslog'], to_console=logging.WARNING)
@@ -162,9 +163,8 @@ def main():
else:
files = None
- (serverlessplugins, serverplugins) = load_plugins(setup)
-
- errorhandler = get_errorhandler(setup)
+ (serverlessplugins, serverplugins) = load_plugins()
+ errorhandler = get_errorhandler()
if setup['showerrors']:
for plugin in serverplugins.values() + serverlessplugins.values():
@@ -176,7 +176,7 @@ def main():
raise SystemExit(0)
run_serverless_plugins(serverlessplugins, errorhandler=errorhandler,
- setup=setup, files=files)
+ files=files)
if serverplugins:
if errorhandler.errors:
@@ -192,7 +192,7 @@ def main():
"plugins")
else:
run_server_plugins(serverplugins, errorhandler=errorhandler,
- setup=setup, files=files)
+ files=files)
if errorhandler.errors or errorhandler.warnings or setup['verbose']:
print("%d errors" % errorhandler.errors)
diff --git a/src/sbin/bcfg2-report-collector b/src/sbin/bcfg2-report-collector
index a0ee2259a..403775251 100755
--- a/src/sbin/bcfg2-report-collector
+++ b/src/sbin/bcfg2-report-collector
@@ -20,8 +20,8 @@ def main():
)
optinfo.update(Bcfg2.Options.CLI_COMMON_OPTIONS)
optinfo.update(Bcfg2.Options.REPORTING_COMMON_OPTIONS)
- setup = Bcfg2.Options.OptionParser(optinfo)
- setup.parse(sys.argv[1:])
+ setup = Bcfg2.Options.load_option_parser(optinfo)
+ setup.parse()
# run collector
try:
diff --git a/src/sbin/bcfg2-server b/src/sbin/bcfg2-server
index cdca71e74..33ee327fc 100755
--- a/src/sbin/bcfg2-server
+++ b/src/sbin/bcfg2-server
@@ -17,7 +17,7 @@ def main():
optinfo.update(Bcfg2.Options.CLI_COMMON_OPTIONS)
optinfo.update(Bcfg2.Options.SERVER_COMMON_OPTIONS)
optinfo.update(Bcfg2.Options.DAEMON_COMMON_OPTIONS)
- setup = Bcfg2.Options.OptionParser(optinfo)
+ setup = Bcfg2.Options.load_option_parser(optinfo)
setup.parse(sys.argv[1:])
# check whether the specified bcfg2.conf exists
if not os.path.exists(setup['configfile']):
@@ -38,7 +38,7 @@ def main():
from Bcfg2.Server.BuiltinCore import Core
try:
- core = Core(setup)
+ core = Core()
core.run()
except CoreInitError:
msg = sys.exc_info()[1]
diff --git a/src/sbin/bcfg2-test b/src/sbin/bcfg2-test
index 6eaf0cc33..510bb898b 100755
--- a/src/sbin/bcfg2-test
+++ b/src/sbin/bcfg2-test
@@ -194,7 +194,7 @@ def parse_args():
optinfo = dict(Bcfg2.Options.TEST_COMMON_OPTIONS)
optinfo.update(Bcfg2.Options.CLI_COMMON_OPTIONS)
optinfo.update(Bcfg2.Options.SERVER_COMMON_OPTIONS)
- setup = Bcfg2.Options.OptionParser(optinfo)
+ setup = Bcfg2.Options.load_option_parser(optinfo)
setup.hm = \
"bcfg2-test [options] [client] [client] [...]\nOptions:\n %s" % \
setup.buildHelpMessage()