summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Plugins/GroupPatterns.py
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2009-07-16 03:13:04 +0000
committerNarayan Desai <desai@mcs.anl.gov>2009-07-16 03:13:04 +0000
commitcd39d8fbe8a5cd99396e164687cfc6a86f98dc97 (patch)
treeae141a508044b6357eed722fbe3488cb85cb7da4 /src/lib/Server/Plugins/GroupPatterns.py
parent94b820c0363d07d8b12740168cdd129b5fe4c437 (diff)
downloadbcfg2-cd39d8fbe8a5cd99396e164687cfc6a86f98dc97.tar.gz
bcfg2-cd39d8fbe8a5cd99396e164687cfc6a86f98dc97.tar.bz2
bcfg2-cd39d8fbe8a5cd99396e164687cfc6a86f98dc97.zip
GroupPatterns: support activation of multiple groups from a single pattern
Add support for the addition of multiple new group memberships based on a single pattern (of either type). Alsa add support in the schema. git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5336 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Plugins/GroupPatterns.py')
-rw-r--r--src/lib/Server/Plugins/GroupPatterns.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/lib/Server/Plugins/GroupPatterns.py b/src/lib/Server/Plugins/GroupPatterns.py
index 56195602b..6ff0c7162 100644
--- a/src/lib/Server/Plugins/GroupPatterns.py
+++ b/src/lib/Server/Plugins/GroupPatterns.py
@@ -19,10 +19,10 @@ class PackedDigitRange(object):
class PatternMap(object):
range_finder = '\\[\\[[\d\-,]+\\]\\]'
- def __init__(self, pattern, rangestr, groupname):
+ def __init__(self, pattern, rangestr, groups):
self.pattern = pattern
self.rangestr = rangestr
- self.groupname = groupname
+ self.groups = groups
if pattern != None:
self.re = re.compile(pattern)
self.process = self.process_re
@@ -42,16 +42,19 @@ class PatternMap(object):
for i in range(len(digits)):
if not self.dranges[i].includes(digits[i]):
return None
- return self.groupname
+ return self.groups
def process_re(self, name):
match = self.re.match(name)
if not match:
return None
- ret = self.groupname
+ ret = list()
sub = match.groups()
- for idx in range(len(sub)):
- ret = ret.replace('$%s' % (idx+1), sub[idx])
+ for group in self.groups:
+ newg = group
+ for idx in range(len(sub)):
+ newg = newg.replace('$%s' % (idx+1), sub[idx])
+ ret.append(newg)
return ret
class PatternFile(Bcfg2.Server.Plugin.SingleXMLFileBacked):
@@ -74,8 +77,8 @@ class PatternFile(Bcfg2.Server.Plugin.SingleXMLFileBacked):
pat = entry.find('NamePattern').text
if entry.find('NameRange') is not None:
rng = entry.find('NameRange').text
- grp = entry.find('Group').text
- self.patterns.append(PatternMap(pat, rng, grp))
+ groups = [g.text for g in entry.findall('Group')]
+ self.patterns.append(PatternMap(pat, rng, groups))
except:
Bcfg2.Server.Plugin.logger.error(\
"GroupPatterns: Failed to initialize pattern %s" % \
@@ -86,8 +89,8 @@ class PatternFile(Bcfg2.Server.Plugin.SingleXMLFileBacked):
for pattern in self.patterns:
try:
gn = pattern.process(hostname)
- if gn:
- ret.append(gn)
+ if gn is not None:
+ ret.extend(gn)
except:
Bcfg2.Server.Plugin.logger.error(\
"GroupPatterns: Failed to process pattern %s for %s" % \