From 522d1758b824a69fa196cee412532d6cefcd9a62 Mon Sep 17 00:00:00 2001 From: Narayan Desai Date: Thu, 15 Jan 2009 03:40:46 +0000 Subject: Uniqify probe returns so that a client only gets the most specific version, and map it to the probe basename (ie probe getmacs.H_hostname returns as getmacs) git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5026 ce84e21b-d406-0410-9b95-82705330c041 --- src/lib/Server/Plugins/Probes.py | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/lib/Server/Plugins/Probes.py b/src/lib/Server/Plugins/Probes.py index 7b82183ea..6c7590da0 100644 --- a/src/lib/Server/Plugins/Probes.py +++ b/src/lib/Server/Plugins/Probes.py @@ -1,6 +1,7 @@ import Bcfg2.Server.Plugin, lxml.etree, re -probe_matcher = re.compile("(?P\S+)(.(?P[GH])_\S+)?") +specific_probe_matcher = re.compile("(.*/)?(?P\S+)(.(?P[GH])_\S+)") +probe_matcher = re.compile("(.*/)?(?P\S+)") class ProbeSet(Bcfg2.Server.Plugin.EntrySet): ignore = re.compile("^(\.#.*|.*~|\\..*\\.(tmp|sw[px])|probed\\.xml)$") @@ -19,22 +20,18 @@ class ProbeSet(Bcfg2.Server.Plugin.EntrySet): def get_probe_data(self, metadata): ret = [] + build = dict() candidates = self.get_matching(metadata) - temp = {} - for cand in candidates: - if cand.specific.all: - if cand.name not in temp: - temp[cand.name] = (cand, 0) - continue - mdata = probe_matcher.match(cand.name).groupdict() - if mdata['basename'] in temp: - if mdata['mode'] > temp[mdata['basename']][1]: - temp[mdata['basename']] = (cand, mdata['mode']) - else: - temp[mdata['basename']] = (cand, mdata['mode']) - - for (name, data) in temp.iteritems(): - entry, prio = data + candidates.sort(lambda x,y: cmp(x.specific, y.specific)) + for entry in candidates: + rem = specific_probe_matcher.match(entry.name) + if not rem: + rem = probe_matcher.match(entry.name) + pname = rem.group('basename') + if pname not in build: + build[pname] = entry + + for (name, entry) in build.iteritems(): probe = lxml.etree.Element('probe') probe.set('name', name.split('/')[-1]) probe.set('source', self.plugin_name) -- cgit v1.2.3-1-g7c22