diff options
author | Narayan Desai <desai@mcs.anl.gov> | 2005-09-07 17:35:15 +0000 |
---|---|---|
committer | Narayan Desai <desai@mcs.anl.gov> | 2005-09-07 17:35:15 +0000 |
commit | 22826c4e0d77e4e272224df12f23cd24ffa408a9 (patch) | |
tree | 57e93e0e6bb17524c8b7cd7a066f9b009735ce75 /src/lib | |
parent | a0e67509e2d4c4b133ae6ff9c3f707ed46b96981 (diff) | |
download | bcfg2-22826c4e0d77e4e272224df12f23cd24ffa408a9.tar.gz bcfg2-22826c4e0d77e4e272224df12f23cd24ffa408a9.tar.bz2 bcfg2-22826c4e0d77e4e272224df12f23cd24ffa408a9.zip |
Change mode to -rw-r--r--
(Logical change 1.300)
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@1216 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Server/Structures/Bundler.py | 121 |
1 files changed, 0 insertions, 121 deletions
diff --git a/src/lib/Server/Structures/Bundler.py b/src/lib/Server/Structures/Bundler.py deleted file mode 100644 index 7eacfcb38..000000000 --- a/src/lib/Server/Structures/Bundler.py +++ /dev/null @@ -1,121 +0,0 @@ -'''This provides bundle clauses with translation functionality''' -__revision__ = '$Revision$' - -from copy import deepcopy -from syslog import LOG_ERR, syslog - -from Bcfg2.Server.Generator import SingleXMLFileBacked, XMLFileBacked, DirectoryBacked -from Bcfg2.Server.Structure import Structure - -from elementtree.ElementTree import Element, XML -from xml.parsers.expat import ExpatError - -class ImageFile(SingleXMLFileBacked): - '''This file contains image -> system mappings''' - def __init__(self, filename, fam): - self.images = {} - SingleXMLFileBacked.__init__(self, filename, fam) - - def Index(self): - '''Build data structures out of the data''' - try: - xdata = XML(self.data) - except ExpatError, err: - syslog(LOG_ERR, "Failed to parse file %s" % (self.name)) - syslog(LOG_ERR, err) - del self.data - return - self.images = {} - for child in xdata.getchildren(): - [name, pkg, service] = [child.get(field) for field in ['name', 'package', 'service']] - for grandchild in child.getchildren(): - self.images[grandchild.get('name')] = (name, pkg, service) - -class Bundle(XMLFileBacked): - '''Bundles are configuration specifications (with image/translation abstraction)''' - - def __init__(self, filename): - self.all = [] - self.attributes = {} - self.systems = {} - XMLFileBacked.__init__(self, filename) - - def Index(self): - '''Build data structures from the source data''' - try: - xdata = XML(self.data) - except ExpatError, err: - syslog(LOG_ERR, "Failed to parse file %s" % (self.name)) - syslog(LOG_ERR, str(err)) - del self.data - return - self.all = [] - self.systems = {} - self.attributes = {} - for entry in xdata.getchildren(): - if entry.tag == 'System': - self.systems[entry.attrib['name']] = entry.getchildren() - elif entry.tag == 'Attribute': - self.attributes[entry.get('name')] = entry.getchildren() - else: - self.all.append(entry) - del self.data - - def BuildBundle(self, metadata, system): - '''Build a bundle for a particular client''' - bundlename = self.name.split('/')[-1] - bundle = Element('Bundle', name=bundlename) - for entry in self.all + self.systems.get(system, []): - bundle.append(deepcopy(entry)) - for attribute in [aname for (scope, aname) in [item.split('.') for item in metadata.attributes] - if scope == bundlename[:-4]]: - for entry in self.attributes.get(attribute, []): - bundle.append(deepcopy(entry)) - return bundle - -class BundleSet(DirectoryBacked): - '''The Bundler handles creation of dependent clauses based on bundle definitions''' - __child__ = Bundle - -class Bundler(Structure): - '''The bundler creates dependent clauses based on the bundle/translation scheme from bcfg1''' - __name__ = 'Bundler' - __version__ = '$Id$' - - def __init__(self, core, datastore): - Structure.__init__(self, core, datastore) - self.imageinfo = ImageFile("%s/etc/imageinfo.xml"%(datastore), self.core.fam) - self.bundles = BundleSet(self.data, self.core.fam) - - def Construct(self, metadata): - '''Build all structures for client (metadata)''' - try: - (system, package, service) = self.GetTransInfo(metadata) - except KeyError: - syslog(LOG_ERR, "Failed to find translation information for image %s" % metadata.image) - return [] - bundleset = [] - for bundlename in metadata.bundles: - if not self.bundles.entries.has_key("%s.xml"%(bundlename)): - syslog(LOG_ERR, "Client %s requested nonexistent bundle %s"%(metadata.hostname, bundlename)) - continue - - bundle = self.bundles.entries["%s.xml" % (bundlename)].BuildBundle(metadata, system) - # now we need to populate service/package types - for entry in bundle.getchildren(): - if entry.tag == 'Package': - entry.attrib['type'] = package - elif entry.tag == 'Service': - entry.attrib['type'] = service - bundleset.append(bundle) - return bundleset - - def GetTransInfo(self, metadata): - '''Get Translation info for metadata.image''' - if self.imageinfo.images.has_key(metadata.image): - return self.imageinfo.images[metadata.image] - else: - raise KeyError, metadata.image - - - |