summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Plugin.py
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2011-10-27 08:49:09 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2011-10-27 08:49:09 -0400
commitfff865e8f428f93c7718b9932552ea0261a95500 (patch)
treef2a2d5db8b46b37c17292b5828f6ae4f81c66cec /src/lib/Server/Plugin.py
parente2261d351c8f11a9cef4b47b6db9774761b4dd5b (diff)
downloadbcfg2-fff865e8f428f93c7718b9932552ea0261a95500.tar.gz
bcfg2-fff865e8f428f93c7718b9932552ea0261a95500.tar.bz2
bcfg2-fff865e8f428f93c7718b9932552ea0261a95500.zip
Add a number of features to SSHbase:
* Support for group-specific host keys * Support for fully static host- and group-specific ssh_known_hosts * (Support for totally generic host keys and ssh_known_hosts, too, but that's pretty useless.) * Support for info.xml, info, and :info files; only info.xml is likely to be useful, with the <Path> directive
Diffstat (limited to 'src/lib/Server/Plugin.py')
-rw-r--r--src/lib/Server/Plugin.py39
1 files changed, 22 insertions, 17 deletions
diff --git a/src/lib/Server/Plugin.py b/src/lib/Server/Plugin.py
index c09a37ed8..190a205e6 100644
--- a/src/lib/Server/Plugin.py
+++ b/src/lib/Server/Plugin.py
@@ -934,9 +934,29 @@ class EntrySet:
self.specific = re.compile(pattern)
def get_matching(self, metadata):
- return [item for item in list(self.entries.values()) \
+ return [item for item in list(self.entries.values())
if item.specific.matches(metadata)]
+ def best_matching(self, metadata):
+ """ Return the appropriate interpreted template from the set of
+ available templates. """
+ matching = self.get_matching(metadata)
+
+ hspec = [ent for ent in matching if ent.specific.hostname]
+ if hspec:
+ return hspec[0]
+
+ gspec = [ent for ent in matching if ent.specific.group]
+ if gspec:
+ gspec.sort(self.group_sortfunc)
+ return gspec[-1]
+
+ aspec = [ent for ent in matching if ent.specific.all]
+ if aspec:
+ return aspec[0]
+
+ raise PluginExecutionError
+
def handle_event(self, event):
"""Handle FAM events for the TemplateSet."""
action = event.code2str()
@@ -1042,22 +1062,7 @@ class EntrySet:
def bind_entry(self, entry, metadata):
"""Return the appropriate interpreted template from the set of available templates."""
self.bind_info_to_entry(entry, metadata)
- matching = self.get_matching(metadata)
-
- hspec = [ent for ent in matching if ent.specific.hostname]
- if hspec:
- return hspec[0].bind_entry(entry, metadata)
-
- gspec = [ent for ent in matching if ent.specific.group]
- if gspec:
- gspec.sort(self.group_sortfunc)
- return gspec[-1].bind_entry(entry, metadata)
-
- aspec = [ent for ent in matching if ent.specific.all]
- if aspec:
- return aspec[0].bind_entry(entry, metadata)
-
- raise PluginExecutionError
+ return self.best_matching(metadata).bind_entry(entry, metadata)
class GroupSpool(Plugin, Generator):