summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/Bcfg2')
-rw-r--r--src/lib/Bcfg2/Server/BuiltinCore.py3
-rw-r--r--src/lib/Bcfg2/Server/Core.py7
-rw-r--r--src/lib/Bcfg2/Server/FileMonitor/Gamin.py24
-rw-r--r--src/lib/Bcfg2/Server/FileMonitor/Inotify.py4
4 files changed, 29 insertions, 9 deletions
diff --git a/src/lib/Bcfg2/Server/BuiltinCore.py b/src/lib/Bcfg2/Server/BuiltinCore.py
index 4e15f85d4..a90ed1079 100644
--- a/src/lib/Bcfg2/Server/BuiltinCore.py
+++ b/src/lib/Bcfg2/Server/BuiltinCore.py
@@ -12,13 +12,14 @@ from Bcfg2.SSLServer import XMLRPCServer
logger = logging.getLogger()
+
class NoExposedMethod (Exception):
"""There is no method exposed with the given name."""
class Core(BaseCore):
name = 'bcfg2-server'
-
+
def __init__(self, setup):
BaseCore.__init__(self, setup)
self.server = None
diff --git a/src/lib/Bcfg2/Server/Core.py b/src/lib/Bcfg2/Server/Core.py
index cc6cf13a8..3fe52c4e9 100644
--- a/src/lib/Bcfg2/Server/Core.py
+++ b/src/lib/Bcfg2/Server/Core.py
@@ -27,10 +27,12 @@ except:
os.environ['DJANGO_SETTINGS_MODULE'] = 'Bcfg2.settings'
+
def exposed(func):
func.exposed = True
return func
+
class track_statistics(object):
""" decorator that tracks execution time for the given
function """
@@ -53,6 +55,7 @@ class track_statistics(object):
return inner
+
def sort_xml(node, key=None):
for child in node:
sort_xml(child, key)
@@ -99,7 +102,7 @@ class BaseCore(object):
fm = Bcfg2.Server.FileMonitor.available[setup['filemonitor']]
except KeyError:
self.logger.error("File monitor driver %s not available; "
- "forcing to default" % filemonitor)
+ "forcing to default" % setup['filemonitor'])
fm = Bcfg2.Server.FileMonitor.available['default']
famargs = dict(ignore=[], debug=False)
if 'ignore' in setup:
@@ -489,7 +492,7 @@ class BaseCore(object):
def _daemonize(self):
""" daemonize the server """
- raise NotImplementedError
+ raise NotImplementedError
def _run(self):
""" start up the server; this method should return immediately """
diff --git a/src/lib/Bcfg2/Server/FileMonitor/Gamin.py b/src/lib/Bcfg2/Server/FileMonitor/Gamin.py
index 60f80c9c3..8a72fc0eb 100644
--- a/src/lib/Bcfg2/Server/FileMonitor/Gamin.py
+++ b/src/lib/Bcfg2/Server/FileMonitor/Gamin.py
@@ -9,6 +9,7 @@ from Bcfg2.Server.FileMonitor import Event, FileMonitor
logger = logging.getLogger(__name__)
+
class GaminEvent(Event):
"""
This class provides an event analogous to
@@ -23,13 +24,22 @@ class GaminEvent(Event):
if code in self.action_map:
self.action = self.action_map[code]
+
class Gamin(FileMonitor):
__priority__ = 10
def __init__(self, ignore=None, debug=False):
FileMonitor.__init__(self, ignore=ignore, debug=debug)
- self.mon = WatchMonitor()
+ self.mon = None
self.counter = 0
+ self.add_q = []
+
+ def start(self):
+ FileMonitor.start(self)
+ self.mon = WatchMonitor()
+ for monitor in self.add_q:
+ self.AddMonitor(*monitor)
+ self.add_q = []
def fileno(self):
return self.mon.get_fd()
@@ -38,10 +48,16 @@ class Gamin(FileMonitor):
"""queue up the event for later handling"""
self.events.append(GaminEvent(request_id, path, action))
- def AddMonitor(self, path, obj):
+ def AddMonitor(self, path, obj, handle=None):
"""Add a monitor to path, installing a callback to obj."""
- handle = self.counter
- self.counter += 1
+ if handle is None:
+ handle = self.counter
+ self.counter += 1
+
+ if not self.started:
+ self.add_q.append((path, obj, handle))
+ return handle
+
mode = os.stat(path)[stat.ST_MODE]
# Flush queued gamin events
diff --git a/src/lib/Bcfg2/Server/FileMonitor/Inotify.py b/src/lib/Bcfg2/Server/FileMonitor/Inotify.py
index 60e26587e..6a8fd0201 100644
--- a/src/lib/Bcfg2/Server/FileMonitor/Inotify.py
+++ b/src/lib/Bcfg2/Server/FileMonitor/Inotify.py
@@ -3,7 +3,6 @@
import os
import sys
import logging
-import operator
import pyinotify
from Bcfg2.Compat import reduce
from Bcfg2.Server.FileMonitor import Event
@@ -11,6 +10,7 @@ from Bcfg2.Server.FileMonitor.Pseudo import Pseudo
logger = logging.getLogger(__name__)
+
class Inotify(Pseudo, pyinotify.ProcessEvent):
__priority__ = 1
action_map = {pyinotify.IN_CREATE: 'created',
@@ -22,6 +22,7 @@ class Inotify(Pseudo, pyinotify.ProcessEvent):
def __init__(self, ignore=None, debug=False):
Pseudo.__init__(self, ignore=ignore, debug=debug)
+ pyinotify.ProcessEvent(self)
self.event_filter = dict()
self.watches_by_path = dict()
# these are created in start() after the server is done forking
@@ -53,7 +54,6 @@ class Inotify(Pseudo, pyinotify.ProcessEvent):
try:
watch = self.wm.watches[ievent.wd]
except KeyError:
- err = sys.exc_info()[1]
logger.error("Error handling event for %s: Watch %s not found" %
(ievent.pathname, ievent.wd))
return