From d7c2e5beaab5d77b0f1376e83a3efa502de64e52 Mon Sep 17 00:00:00 2001 From: Narayan Desai Date: Wed, 30 Jun 2004 15:03:30 +0000 Subject: (Logical change 1.22) git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@98 ce84e21b-d406-0410-9b95-82705330c041 --- src/Structure.py | 21 +++++++++++++++ src/bundler.py | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) (limited to 'src') diff --git a/src/Structure.py b/src/Structure.py index e69de29bb..c948d326d 100644 --- a/src/Structure.py +++ b/src/Structure.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# $Id: $ + +class Structure(object): + '''The Structure class is used to define patterns of data in host configurations + Structure subtyped classes provide functions that group configurations into dependent + and independent clauses''' + + def __init__(self, core, datastore): + self.data = "%s/%s"%(datastore,self.__name__) + self.core = core + self.__setup__() + + def __setup__(self): + pass + + def Construct(self, metadata, subset): + '''Returns a list of configuration structure chunks for client''' + return [] + + diff --git a/src/bundler.py b/src/bundler.py index e69de29bb..3e0c1e625 100644 --- a/src/bundler.py +++ b/src/bundler.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python +# $Id: $ + +from GeneratorUtils import XMLFileBacked, DirectoryBacked +from Structure import Structure + +from elementtree.ElementTree import Element + +class Bundle(XMLFileBacked): + def __iter__(self): + return iter(self.entries) + +class Translation(XMLFileBacked): + __identifier__ = 'system' + + def Index(self): + XMLFileBacked.Index(self) + self.images = [] + self.trans = {'VPackage':{}, 'VConfig':{}, 'VService':{}, 'VFS':{}} + for entry in self.entries: + if entry.tag == 'Image': + self.images.append(entry.attrib['name'] ) + else: + self.trans[entry.tag][entry.attrib['name']] = entry.getchildren() + +class TranslationSet(DirectoryBacked): + '''TranslationSet is the container for all active translations in the system. It + is coherent cache of a directory.''' + __child__ = Translation + + def __iter__(self): + return self.entries.iteritems() + + def FindTranslation(self, image): + '''Locate a translation by image name. Needed because translations can handle multiple images''' + x = [v for k,v in self if image in v.images] + if len(x) == 1: + return x[0] + else: + raise "Bang" + + def BindTranslation(self, image, ba): + '''Map Bundle elements through the translation layer into concrete elements''' + return map(lambda x:(x.tag, x.attrib), + self.FindTranslation(image).trans[ba.tag][ba.attrib['name']]) + +class BundleSet(DirectoryBacked): + '''The Bundler handles creation of dependent clauses based on bundle definitions''' + __child__ = Bundle + + def __iter__(self): + return self.entries.iteritems() + +class bundler(Structure): + '''The bundler creates dependent clauses based on the bundle/translation scheme from bcfg1''' + def __init__(self, core, datastore): + self.core = core + self.datastore = "%s/bundler/"%(datastore) + self.bundles = BundleSet("%s/bundles"%(self.datastore), self.core.fam) + self.translations = TranslationSet("%s/translations"%(self.datastore), self.core.fam) + # now we build the local repr of the translated bundleset + self.core.fam.AddMonitor("%s/bundles"%(self.datastore), self) + self.core.fam.AddMonitor("%s/translations"%(self.datastore), self) + # check which order events will be delivered in; need bundles/trans updated before self + self.HandleEvent(True) + + def HandleEvent(self,event): + self.built = {} + for image in reduce(lambda x,y:x+y, [v.images for k,v in self.translations],[]): + self.built[image] = {} + for (name,bundle) in self.bundles: + name = name[:-4] + self.built[image][name] = [] + for entry in bundle: + self.built[image][name].extend(self.translations.BindTranslation(image,entry)) + + def Construct(self, metadata): + return map(lambda x:self.built[metadata.image][x], metadata.bundles) + -- cgit v1.2.3-1-g7c22