summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Plugins
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2005-09-07 17:35:15 +0000
committerNarayan Desai <desai@mcs.anl.gov>2005-09-07 17:35:15 +0000
commitb1f1d62a944fcb5b4d70b760bbd43c1cd9c944a2 (patch)
treea6aa79b64109e1051553b005cf71cafa73406db0 /src/lib/Server/Plugins
parent838ee233cf492b5c407d2a0513c9a61c0c598575 (diff)
downloadbcfg2-b1f1d62a944fcb5b4d70b760bbd43c1cd9c944a2.tar.gz
bcfg2-b1f1d62a944fcb5b4d70b760bbd43c1cd9c944a2.tar.bz2
bcfg2-b1f1d62a944fcb5b4d70b760bbd43c1cd9c944a2.zip
switch to new plugin API
2005/09/06 21:09:08-05:00 anl.gov!desai Rename: src/lib/Server/Structures/Base.py -> src/lib/Server/Plugins/Base.py (Logical change 1.300) git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@1211 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Plugins')
-rw-r--r--src/lib/Server/Plugins/Base.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/lib/Server/Plugins/Base.py b/src/lib/Server/Plugins/Base.py
index e69de29bb..1912c9a7c 100644
--- a/src/lib/Server/Plugins/Base.py
+++ b/src/lib/Server/Plugins/Base.py
@@ -0,0 +1,60 @@
+'''This module sets up a base list of configuration entries'''
+__revision__ = '$Revision$'
+
+from copy import deepcopy
+from syslog import syslog, LOG_ERR
+from Bcfg2.Server.Generator import SingleXMLFileBacked
+from Bcfg2.Server.Plugin import Plugin
+
+from elementtree.ElementTree import Element, XML
+from xml.parsers.expat import ExpatError
+
+class BaseFile(SingleXMLFileBacked):
+ '''The Base file contains unstructured/independent configuration elements'''
+
+ 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")
+ return
+ for entry in xdata.getchildren():
+ self.store[entry.tag][entry.get('name')] = {'all':[], 'Class':{}, 'Image':{}}
+ if entry.tag in ['Image', 'Class']:
+ 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)
+
+ def BuildStructures(self, metadata):
+ '''Build structures for client described by metadata'''
+ ret = Element("Independant", version='2.0')
+ idata = self.store['Image'].get(metadata.image, {'all':[], 'Class':{}})
+ for entry in idata['all']:
+ ret.append(deepcopy(entry))
+ for cls in metadata.classes:
+ for entry in idata['Class'].get(cls, []):
+ ret.append(deepcopy(entry))
+ cdata = self.store['Class'].get(cls, {'all':[], 'Image':{}})
+ for entry in cdata['all']:
+ ret.append(deepcopy(entry))
+ 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.BuildStructure = self.base.BuildStructure