From 1a6ad2805f5b12ed111f7a3a6adb127f2cbcef8e Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Thu, 17 Jan 2013 11:01:41 -0500 Subject: FAM: split loading a new FileMonitor from fetching an existing one --- src/lib/Bcfg2/Server/Core.py | 20 +++++++++----------- src/lib/Bcfg2/Server/FileMonitor/__init__.py | 22 ++++++++++++++++++---- 2 files changed, 27 insertions(+), 15 deletions(-) (limited to 'src/lib/Bcfg2') diff --git a/src/lib/Bcfg2/Server/Core.py b/src/lib/Bcfg2/Server/Core.py index 0bc77afff..c7797a711 100644 --- a/src/lib/Bcfg2/Server/Core.py +++ b/src/lib/Bcfg2/Server/Core.py @@ -17,7 +17,7 @@ import Bcfg2.Statistics import Bcfg2.Server.FileMonitor from itertools import chain from Bcfg2.Cache import Cache -from Bcfg2.Options import get_option_parser +from Bcfg2.Options import get_option_parser, SERVER_FAM_IGNORE from Bcfg2.Compat import xmlrpclib # pylint: disable=W0622 from Bcfg2.Server.Plugin import PluginInitError, PluginExecutionError, \ track_statistics @@ -120,18 +120,16 @@ class BaseCore(object): #: A :class:`logging.Logger` object for use by the core self.logger = logging.getLogger('bcfg2-server') - try: - filemonitor = \ - Bcfg2.Server.FileMonitor.available[self.setup['filemonitor']] - except KeyError: + if 'ignore' not in self.setup: + self.setup.add_option('ignore', SERVER_FAM_IGNORE) + self.setup.reparse() + famargs = dict(filemonitor=self.setup['filemonitor'], + debug=self.setup['debug'], + ignore=self.setup['ignore']) + if self.setup['filemonitor'] not in Bcfg2.Server.FileMonitor.available: self.logger.error("File monitor driver %s not available; " "forcing to default" % self.setup['filemonitor']) - filemonitor = Bcfg2.Server.FileMonitor.available['default'] - famargs = dict(ignore=[], debug=False) - if 'ignore' in self.setup: - famargs['ignore'] = self.setup['ignore'] - if 'debug' in self.setup: - famargs['debug'] = self.setup['debug'] + famargs['filemonitor'] = 'default' try: #: The :class:`Bcfg2.Server.FileMonitor.FileMonitor` diff --git a/src/lib/Bcfg2/Server/FileMonitor/__init__.py b/src/lib/Bcfg2/Server/FileMonitor/__init__.py index 37a2a8763..d77f21b93 100644 --- a/src/lib/Bcfg2/Server/FileMonitor/__init__.py +++ b/src/lib/Bcfg2/Server/FileMonitor/__init__.py @@ -315,10 +315,11 @@ class FileMonitor(Debuggable): #: should not be used directly, but retrieved via :func:`get_fam`. _FAM = None -def get_fam(filemonitor='default', ignore=None, debug=False): - """ Get a filemonitor object. If :attr:`_FAM` already exists, - that will be used; if not, a new filemonitor object will be - created. + +def load_fam(filemonitor='default', ignore=None, debug=False): + """ Load a new :class:`Bcfg2.Server.FileMonitor.FileMonitor` + object, caching it in :attr:`_FAM` for later retrieval via + :func:`get_fam`. :param filemonitor: Which filemonitor backend to use :type filemonitor: string @@ -336,6 +337,19 @@ def get_fam(filemonitor='default', ignore=None, debug=False): return _FAM +def get_fam(): + """ Get an already-created + :class:`Bcfg2.Server.FileMonitor.FileMonitor` object. If + :attr:`_FAM` has not been populated, then a new default + FileMonitor will be created. + + :returns: :class:`Bcfg2.Server.FileMonitor.FileMonitor` + """ + if _FAM is None: + return load_fam('default') + return _FAM + + #: A dict of all available FAM backends. Keys are the human-readable #: names of the backends, which are used in bcfg2.conf to select a #: backend; values are the backend classes. In addition, the -- cgit v1.2.3-1-g7c22