summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/Plugins/GroupLogic.py
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2013-09-23 10:58:02 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2013-09-23 10:58:02 -0400
commitd1e8d4652a30343d29d482163fa71f93ad03ec4d (patch)
tree788aefc1674dbc4cdcd3e4f98a1cb1b4c8664191 /src/lib/Bcfg2/Server/Plugins/GroupLogic.py
parent8c4fbd1e8429937847adc98a4487b7367a218ce7 (diff)
parent5b2af26603d3ea01378561429179cdd895c42ec0 (diff)
downloadbcfg2-d1e8d4652a30343d29d482163fa71f93ad03ec4d.tar.gz
bcfg2-d1e8d4652a30343d29d482163fa71f93ad03ec4d.tar.bz2
bcfg2-d1e8d4652a30343d29d482163fa71f93ad03ec4d.zip
Merge branch 'maint'
Conflicts: src/lib/Bcfg2/Server/Plugins/GroupLogic.py src/lib/Bcfg2/Server/Plugins/Metadata.py tools/posixusers_baseline.py
Diffstat (limited to 'src/lib/Bcfg2/Server/Plugins/GroupLogic.py')
-rw-r--r--src/lib/Bcfg2/Server/Plugins/GroupLogic.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/lib/Bcfg2/Server/Plugins/GroupLogic.py b/src/lib/Bcfg2/Server/Plugins/GroupLogic.py
index 1da7c8fec..ebcab1a6b 100644
--- a/src/lib/Bcfg2/Server/Plugins/GroupLogic.py
+++ b/src/lib/Bcfg2/Server/Plugins/GroupLogic.py
@@ -3,6 +3,7 @@ template to dynamically set additional groups for clients. """
import os
import lxml.etree
+from threading import local
import Bcfg2.Server.Plugin
from Bcfg2.Server.Plugins.Metadata import MetadataGroup
@@ -30,14 +31,32 @@ class GroupLogic(Bcfg2.Server.Plugin.Plugin,
""" GroupLogic is a connector plugin that lets you use an XML
Genshi template to dynamically set additional groups for
clients. """
+ # perform grouplogic later than other Connector plugins, so it can
+ # use groups set by them
+ sort_order = 1000
def __init__(self, core, datastore):
Bcfg2.Server.Plugin.Plugin.__init__(self, core, datastore)
Bcfg2.Server.Plugin.Connector.__init__(self)
self.config = GroupLogicConfig(os.path.join(self.data, "groups.xml"),
should_monitor=True)
+ self._local = local()
+ # building is a thread-local set that tracks which machines
+ # GroupLogic is getting additional groups for. If a
+ # get_additional_groups() is called twice for a machine before
+ # the first call has completed, the second call returns an
+ # empty list. This is for infinite recursion protection;
+ # without this check, it'd be impossible to use things like
+ # metadata.query.in_group() in GroupLogic, since that requires
+ # building all metadata, which requires running
+ # GroupLogic.get_additional_groups() for all hosts, which
+ # requires building all metadata...
+ self._local.building = set()
def get_additional_groups(self, metadata):
+ if metadata.hostname in self._local.building:
+ return []
+ self._local.building.add(metadata.hostname)
rv = []
for el in self.config.XMLMatch(metadata).findall("Group"):
if el.get("category"):
@@ -45,4 +64,5 @@ class GroupLogic(Bcfg2.Server.Plugin.Plugin,
category=el.get("category")))
else:
rv.append(el.get("name"))
+ self._local.building.discard(metadata.hostname)
return rv