summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Plugins/Bundler.py
blob: f771d4016a7d9c101797c9ce9a69015237e6f6af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'''This provides bundle clauses with translation functionality'''
__revision__ = '$Revision$'

import copy, lxml.etree, Bcfg2.Server.Plugin

class Bundler(Bcfg2.Server.Plugin.StructurePlugin,
              Bcfg2.Server.Plugin.XMLDirectoryBacked):
    '''The bundler creates dependent clauses based on the bundle/translation scheme from bcfg1'''
    __name__ =  'Bundler'
    __version__ = '$Id$'
    __author__ = 'bcfg-dev@mcs.anl.gov'
    __child__ = Bcfg2.Server.Plugin.StructFile
    
    def __init__(self, core, datastore):
        Bcfg2.Server.Plugin.Plugin.__init__(self, core, datastore)
        try:
            Bcfg2.Server.Plugin.XMLDirectoryBacked.__init__(self, self.data, self.core.fam)
        except OSError:
            self.logger.error("Failed to load Bundle repository")
            raise Bcfg2.Server.Plugin.PluginInitError

    def BuildStructures(self, metadata):
        '''Build all structures for client (metadata)'''
        bundleset = []
        for bundlename in metadata.bundles:
            if not self.entries.has_key("%s.xml"%(bundlename)):
                self.logger.error("Client %s requested nonexistent bundle %s" % \
                                  (metadata.hostname, bundlename))
                continue
            bundle = lxml.etree.Element('Bundle', name=bundlename)
            [bundle.append(copy.deepcopy(item))
             for item in self.entries["%s.xml" % (bundlename)].Match(metadata)]
            bundleset.append(bundle)
        return bundleset