summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Metadata.py
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2004-10-07 03:22:28 +0000
committerNarayan Desai <desai@mcs.anl.gov>2004-10-07 03:22:28 +0000
commit1106b939ce92a1280e1b8819b357c6294683248e (patch)
treefa13f74310a238542a2f761f6e21a949656e4a0f /src/lib/Server/Metadata.py
parent75fedb1347cfead23b2929c467446aea992c771a (diff)
downloadbcfg2-1106b939ce92a1280e1b8819b357c6294683248e.tar.gz
bcfg2-1106b939ce92a1280e1b8819b357c6294683248e.tar.bz2
bcfg2-1106b939ce92a1280e1b8819b357c6294683248e.zip
switch to profile based metadata
- change data structures - setup default profile support w/writeback (Logical change 1.76) git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@374 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Metadata.py')
-rw-r--r--src/lib/Server/Metadata.py49
1 files changed, 37 insertions, 12 deletions
diff --git a/src/lib/Server/Metadata.py b/src/lib/Server/Metadata.py
index 6b81e73c2..31769e40e 100644
--- a/src/lib/Server/Metadata.py
+++ b/src/lib/Server/Metadata.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
-from elementtree.ElementTree import XML
+from elementtree.ElementTree import XML, tostring, SubElement
from time import localtime, mktime
from Generator import SingleXMLFileBacked
@@ -82,19 +82,44 @@ class Metadata(object):
return False
return True
+class Profile(object):
+ def __init__(self, xml):
+ self.classes = map(lambda x:x.attrib['name'], xml.findall("Class"))
+ self.attributes = map(lambda x:"%s.%s"%(x.attrib['scope'],x.attrib['name']), xml.findall("Attribute"))
+
class MetadataStore(SingleXMLFileBacked):
def Index(self):
+ self.element = XML(self.data)
+ self.defaults = {}
self.clients = {}
+ self.profiles = {}
self.classes = {}
- self.element = XML(self.data)
+ for p in self.element.findall("Profile"):
+ self.profiles[p.attrib['name']] = Profile(p)
+ for c in self.element.findall("Client"):
+ self.clients[c.attrib['name']] = (c.attrib['image'], c.attrib['profile'])
for c in self.element.findall("Class"):
- self.classes[c.attrib['name']] = map(lambda x:x.attrib['name'], c.findall(".//Bundle"))
- for client in self.element.findall('Client'):
- attributes = map(lambda x:"%s.%s"%(x.attrib['scope'],x.attrib['name']),
- client.findall(".//Attribute"))
- classes = map(lambda x:x.attrib['name'], client.findall(".//Class"))
- bundles = reduce(lambda x,y:x+y, map(lambda z:self.classes.get(z,[]), classes),[])
- for b in bundles:
- if bundles.count(b) > 1: bundles.remove(b)
- self.clients[client.attrib['name']] = Metadata(False, client.attrib['image'], classes,
- bundles, attributes, client.attrib['name'])
+ self.classes[c.attrib['name']] = map(lambda x:x.attrib['name'], c.findall("Bundle"))
+ for (k,v) in self.element.attrib.iteritems():
+ if k[:8] == 'default_':
+ self.defaults[k[8:]] = v
+
+ def FetchMetadata(self,client):
+ if self.clients.has_key(client):
+ (image,profile) = self.clients[client]
+ else:
+ # default profile stuff goes here
+ (image,profile) = (self.defaults['image'], self.defaults['profile'])
+ SubElement(self.element, "Client", name=client, profile=profile, image=image)
+ self.WriteBack()
+ p = self.profiles[profile]
+ # should we uniq here? V
+ bundles = reduce(lambda x,y:x+y, map(self.classes.get, p.classes))
+ return Metadata(False, image, p.classes, bundles, p.attributes, client)
+
+ def WriteBack(self):
+ # write changes to file back to fs
+ f = open(self.name, 'w')
+ f.write(tostring(self.element))
+ f.close()
+