summaryrefslogtreecommitdiffstats
path: root/src/BcfgServer.py
blob: 746c9eb8a367884bc2e326f3b44c2ab3fa685fca (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
36
37
38
39
#!/usr/bin/env python
# $Id: $

from Bcfg2.Core import Core
from Bcfg2.Metadata import Metadata

from sss.restriction import DataSet, Data
from sss.server import Server

class MetadataStore(object):
    def __init__(self):
        self.images = {'topaz':'debian-3.1'}
        self.tags = {'laptop':['topaz']}
        self.bundles = {'global':['ssh'], 'tags':{'laptop':[]}, 'hosts':{}}

    def GetMetadata(self, client):
        tags = [k for (k,v) in self.tags.iteritems() if client in v]
        bundles = self.bundles['global'] + self.bundles['hosts'].get(client,[])
        bundles += reduce(lambda x,y:x+y, map(lambda b:self.bundles.get(b,[]), tags))
        return Metadata(False, self.images[client], bundles, tags, client)

class BcfgServer(Server):
    __implementation__ = 'Bcfg2'
    __component__ = 'bcfg2'
    __dispatch__ = {'get-config':'GetConfig'}
    __statefields__ = ['metadata']
        
    def __setup__(self):
        self.metadata = MetadataStore()
        self.core=Core('/home/desai/data/b2',['bundler'],['sshbase','fstab','myri','cfg'])
        self.__progress__()

    def __progress__(self):
        while self.core.fam.fm.pending():
            self.core.fam.HandleEvent()

if __name__ == '__main__':
    server = BcfgServer()