diff options
author | Csaba Henk <csaba@gluster.com> | 2011-04-18 17:25:28 +0000 |
---|---|---|
committer | Anand Avati <avati@gluster.com> | 2011-04-19 02:30:32 -0700 |
commit | 369f66ea51506315545501ab3fd4fe87d011a0e5 (patch) | |
tree | 3834045a8095b58e3a110e025e4e7ae8d7a941f4 /xlators/features/marker/utils/syncdaemon/configinterface.py | |
parent | 5a0d15682fb62d768ce088b5d9c9aad974a1460c (diff) |
syncdaemon: implement template substitutions for config values
So, for example, a log file setting of
/var/log/${mastervol}/${eSlave}.log
will be substituted with the volume name of the master and the
canonicalized-escaped name of the slave for each master-slave pair.
As template expanders, beyond the various forms and derivatives
of master and slave, the following are also available:
- gsyncd tunables (set in command line or in config)
- for regexp sections, regexp group captures can be accessed
via "match<i>_<n>", where i=1,2 corresponds to the i-th peer-rx
in the section title and n=1,... to the n-th capture.
This will enable us to have a static configuration (not having to
add new entries on each gsyncd start).
Signed-off-by: Csaba Henk <csaba@lowlife.hu>
Signed-off-by: Anand Avati <avati@gluster.com>
BUG: 2785 (gsyncd logs on slave side go to /dev/null)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2785
Diffstat (limited to 'xlators/features/marker/utils/syncdaemon/configinterface.py')
-rw-r--r-- | xlators/features/marker/utils/syncdaemon/configinterface.py | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/xlators/features/marker/utils/syncdaemon/configinterface.py b/xlators/features/marker/utils/syncdaemon/configinterface.py index fce45a2bb..a170b2236 100644 --- a/xlators/features/marker/utils/syncdaemon/configinterface.py +++ b/xlators/features/marker/utils/syncdaemon/configinterface.py @@ -4,6 +4,7 @@ except ImportError: # py 3 import configparser as ConfigParser import re +from string import Template from syncdutils import escape, unescape, norm, update_file @@ -13,6 +14,22 @@ config_version = 2.0 re_type = type(re.compile('')) + +class MultiDict(object): + + def __init__(self, *dd): + self.dicts = dd + + def __getitem__(self, key): + val = None + for d in self.dicts: + if d.get(key): + val = d[key] + if not val: + raise KeyError(key) + return val + + class GConffile(object): def _normconfig(self): @@ -26,9 +43,10 @@ class GConffile(object): s2[k] = v self.config._sections[n] = s2 - def __init__(self, path, peers): + def __init__(self, path, peers, *dd): self.peers = peers self.path = path + self.auxdicts = dd self.config = ConfigParser.RawConfigParser() self.config.read(path) self._normconfig() @@ -89,27 +107,37 @@ class GConffile(object): ss.sort(scmp) return ss - def update_to(self, dct): + def update_to(self, dct, allow_unresolved=False): if not self.peers: raise RuntimeError('no peers given, cannot select matching options') - def update_from_sect(sect): - dct.update(self.config._sections[sect]) + def update_from_sect(sect, mud): + for k, v in self.config._sections[sect].items(): + if k == '__name__': + continue + if allow_unresolved: + dct[k] = Template(v).safe_substitute(mud) + else: + dct[k] = Template(v).substitute(mud) for sect in self.ord_sections(): sp = self.parse_section(sect) if isinstance(sp[0], re_type) and len(sp) == len(self.peers): match = True + mad = {} for i in range(len(sp)): - if not sp[i].search(self.peers[i]): + m = sp[i].search(self.peers[i]) + if not m: match = False break + for j in range(len(m.groups())): + mad['match%d_%d' % (i+1, j+1)] = m.groups()[j] if match: - update_from_sect(sect) + update_from_sect(sect, MultiDict(dct, mad, *self.auxdicts)) if self.config.has_section(self.section()): - update_from_sect(self.section()) + update_from_sect(self.section(), MultiDict(dct, mad, *self.auxdicts)) def get(self, opt=None): d = {} - self.update_to(d) + self.update_to(d, allow_unresolved = True) if opt: opt = norm(opt) v = d.get(opt) |