diff options
author | Narayan Desai <desai@mcs.anl.gov> | 2005-09-23 21:35:27 +0000 |
---|---|---|
committer | Narayan Desai <desai@mcs.anl.gov> | 2005-09-23 21:35:27 +0000 |
commit | ca4407efff20b72ee31fe98fc4eb42eae4550a9c (patch) | |
tree | 04e1c247f2cd422d6230a31e2ab0c1a99fe3b217 | |
parent | a746556b35938b677ba24fd0ffa91de378ace319 (diff) | |
download | bcfg2-ca4407efff20b72ee31fe98fc4eb42eae4550a9c.tar.gz bcfg2-ca4407efff20b72ee31fe98fc4eb42eae4550a9c.tar.bz2 bcfg2-ca4407efff20b72ee31fe98fc4eb42eae4550a9c.zip |
fix nested stuff
2005/09/23 12:17:04-05:00 anl.gov!desai
make base global declarations work
(Logical change 1.319)
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@1302 ce84e21b-d406-0410-9b95-82705330c041
-rw-r--r-- | src/lib/Server/Plugins/Base.py | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/src/lib/Server/Plugins/Base.py b/src/lib/Server/Plugins/Base.py index c1ebbe0d2..2d47346e9 100644 --- a/src/lib/Server/Plugins/Base.py +++ b/src/lib/Server/Plugins/Base.py @@ -2,37 +2,50 @@ __revision__ = '$Revision$' from copy import deepcopy -from syslog import syslog, LOG_ERR -from Bcfg2.Server.Plugin import Plugin, SingleXMLFileBacked - from elementtree.ElementTree import Element, XML from xml.parsers.expat import ExpatError -class BaseFile(SingleXMLFileBacked): - '''The Base file contains unstructured/independent configuration elements''' +from Bcfg2.Server.Plugin import Plugin, PluginInitError, SingleXMLFileBacked + +class Base(Plugin, SingleXMLFileBacked): + '''This Structure is good for the pile of independent configs needed for most actual systems''' + __name__ = 'Base' + __version__ = '$Id$' + __author__ = 'bcfg-dev@mcs.anl.gov' + '''base creates independent clauses based on client metadata''' + def __init__(self, core, datastore): + Plugin.__init__(self, core, datastore) + self.store = {'all':[], 'Class':{'all':[]}, 'Image':{'all':[]}, 'all':[]} + try: + SingleXMLFileBacked.__init__(self, "%s/etc/base.xml"%(datastore), self.core.fam) + except OSError: + self.LogError("Failed to load base.xml") + raise PluginInitError + def Index(self): '''Store XML data in reasonable structures''' - self.store = {'Class':{'all':[]}, 'Image':{'all':[]}, 'all':[]} try: xdata = XML(self.data) except ExpatError: - syslog(LOG_ERR, "Failed to parse base.xml") + self.LogError("Failed to parse base.xml") return for entry in xdata.getchildren(): - self.store[entry.tag][entry.get('name')] = {'all':[], 'Class':{}, 'Image':{}} if entry.tag in ['Image', 'Class']: + if not self.store[entry.tag].has_key(entry.get('name')): + self.store[entry.tag][entry.get('name')] = {'all':[], 'Class':{}, 'Image':{}} for child in entry.getchildren(): if child.tag in ['Image', 'Class']: self.store[entry.tag][entry.get('name')][child.tag][child.get('name')] = child.getchildren() else: self.store[entry.tag][entry.get('name')]['all'].append(child) else: - self.store[entry.tag]['all'].append(child) + self.store['all'].append(child) def BuildStructures(self, metadata): '''Build structures for client described by metadata''' ret = Element("Independant", version='2.0') + [ret.append(deepcopy(entry)) for entry in self.store['all']] idata = self.store['Image'].get(metadata.image, {'all':[], 'Class':{}}) for entry in idata['all']: ret.append(deepcopy(entry)) @@ -45,15 +58,3 @@ class BaseFile(SingleXMLFileBacked): for entry in cdata['Image'].get(metadata.image, []): ret.append(deepcopy(entry)) return [ret] - -class Base(Plugin): - '''This Structure is good for the pile of independent configs needed for most actual systems''' - __name__ = 'Base' - __version__ = '$Id$' - __author__ = 'bcfg-dev@mcs.anl.gov' - - '''base creates independent clauses based on client metadata''' - def __init__(self, core, datastore): - Plugin.__init__(self, core, datastore) - self.base = BaseFile("%s/etc/base.xml"%(datastore), self.core.fam) - self.BuildStructures = self.base.BuildStructures |