diff options
author | Narayan Desai <desai@mcs.anl.gov> | 2004-09-07 17:54:04 +0000 |
---|---|---|
committer | Narayan Desai <desai@mcs.anl.gov> | 2004-09-07 17:54:04 +0000 |
commit | 4f0b546b2450c5e4883a62205104b5a6a093891e (patch) | |
tree | b66922e62e964ecdd63c1e8eea4bb337a4a4a66b /src/lib | |
parent | 39b15e2f7d2debedcd7dd092fa43c41d0654a804 (diff) | |
download | bcfg2-4f0b546b2450c5e4883a62205104b5a6a093891e.tar.gz bcfg2-4f0b546b2450c5e4883a62205104b5a6a093891e.tar.bz2 bcfg2-4f0b546b2450c5e4883a62205104b5a6a093891e.zip |
update to use ScopedXMLFile class
(Logical change 1.58)
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@321 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Server/Generators/servicemgr.py | 51 |
1 files changed, 3 insertions, 48 deletions
diff --git a/src/lib/Server/Generators/servicemgr.py b/src/lib/Server/Generators/servicemgr.py index 840ce02ba..e4de6df63 100644 --- a/src/lib/Server/Generators/servicemgr.py +++ b/src/lib/Server/Generators/servicemgr.py @@ -1,52 +1,7 @@ #!/usr/bin/env python from elementtree.ElementTree import XML -from Bcfg2.Server.Generator import Generator, SingleXMLFileBacked - -class ServiceList(SingleXMLFileBacked): - def Index(self): - a = XML(self.data) - self.entries = a.getchildren() - self.services = {} - for e in self.entries: - m = (e.tag, e.attrib['name']) - for s in e.findall('Service'): - bs = self.services.get(s.attrib['name'],[]) - bs.append((m,s)) - self.services[s.attrib['name']] = bs - # now we need to build the index to point __provides__ at - self.__provides__ = {'Service':{}} - for s in self.services.keys(): - self.__provides__['Service'][s] = self.GetService - self.services[s].sort(self.Sort) - - def GetService(self, entry, metadata): - s = self.services[entry.attrib['name']] - useful = filter(lambda x:self.MatchMetadata(x[0], metadata), s) - data = useful[-1][1] - entry.attrib.update(data.attrib) - - def MatchMetadata(self, m, metadata): - if m[0] == 'Global': - return True - elif m[0] == 'Image': - if m[1] == metadata.image: - return True - elif m[0] == 'Class': - if m[1] in metadata.classes: - return True - elif m[0] == 'Host': - if m[1] == metadata.hostname: - return True - return False - - def Sort(self, m1, m2): - d = {('Global','Host'):-1,('Global','Image'):-1,("Global",'Class'):-1, - ('Image', 'Global'):1, ('Image', 'Image'):0, ('Image', 'Host'):1, ('Image', 'Class'):-1, - ('Class','Global'):1, ('Class', 'Image'):1, ('Class','Class'):0, ('Class', 'Host'): -1, - ('Host', 'Global'):1, ('Host', 'Image'):1, ('Host','Class'):1, ('Host','Host'):0} - if d.has_key((m1[0][0], m2[0][0])): - return d[(m1[0][0],m2[0][0])] +from Bcfg2.Server.Generator import Generator, ScopedXMLFile class servicemgr(Generator): '''This is a generator that handles service assignments''' @@ -56,8 +11,8 @@ class servicemgr(Generator): def __init__(self, core, datastore): Generator.__init__(self, core, datastore) - self.svrinfo = ServiceList("%s/common/services.xml"%(datastore), self.core.fam) - self.__provides__ = self.svrinfo.__provides__ + self.svc = ScopedXMLFile("%s/common/services.xml"%(datastore), self.core.fam) + self.__provides__ = self.svc.__provides__ |