summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Generators/servicemgr.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/Server/Generators/servicemgr.py')
-rw-r--r--src/lib/Server/Generators/servicemgr.py51
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__