summaryrefslogtreecommitdiffstats
path: root/src/lib/Server
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2004-08-31 14:41:40 +0000
committerNarayan Desai <desai@mcs.anl.gov>2004-08-31 14:41:40 +0000
commit104a1bc8a0f0989cf1beab87c85e19af16062f3f (patch)
tree254e1a6555b1d7412b627e8d27e77a232cb41776 /src/lib/Server
parent018623be19fbfa1ca319b3f9893855550b3d8bc5 (diff)
downloadbcfg2-104a1bc8a0f0989cf1beab87c85e19af16062f3f.tar.gz
bcfg2-104a1bc8a0f0989cf1beab87c85e19af16062f3f.tar.bz2
bcfg2-104a1bc8a0f0989cf1beab87c85e19af16062f3f.zip
it mainly works now
(Logical change 1.45) git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@269 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server')
-rw-r--r--src/lib/Server/Generators/servicemgr.py47
1 files changed, 43 insertions, 4 deletions
diff --git a/src/lib/Server/Generators/servicemgr.py b/src/lib/Server/Generators/servicemgr.py
index dfee9f224..d2c2a937f 100644
--- a/src/lib/Server/Generators/servicemgr.py
+++ b/src/lib/Server/Generators/servicemgr.py
@@ -3,7 +3,47 @@
from Bcfg2.Server.Generator import Generator, SingleXMLFileBacked
class ServiceList(SingleXMLFileBacked):
- pass
+ def Index(self):
+ SingleXMLFileBacked.Index(self)
+ 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)
+ return useful[-1][1]
+
+ 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])]
class servicemgr(Generator):
'''This is a generator that handles service assignments'''
@@ -12,9 +52,8 @@ class servicemgr(Generator):
__author__ = 'bcfg-dev@mcs.anl.gov'
def __setup__(self):
- self.__provides__ = {'Service':{'sshd':self.GetService}}
- #self.datafile = ServiceList("%s/packages.xml"%(self.data))
- pass
+ self.srvinfo = ServiceList("%s/packages.xml"%(self.data))
+ self.__provides__ = self.srvinfo.__provides__
def GetService(self,entry,metadata):
# for now sshd is on