summaryrefslogtreecommitdiff
path: root/cloudinit/DataSourceOVF.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2011-01-25 03:24:37 -0500
committerScott Moser <smoser@ubuntu.com>2011-01-25 03:24:37 -0500
commit1fda22c4bb4dbda92fa3cce179934cd75cbdd48e (patch)
treea833ded5655517d301e1fa2404b50f0e96315077 /cloudinit/DataSourceOVF.py
parent9fe2d933f374a581a661e5f8b138c0904f8f8a56 (diff)
downloadvyos-cloud-init-1fda22c4bb4dbda92fa3cce179934cd75cbdd48e.tar.gz
vyos-cloud-init-1fda22c4bb4dbda92fa3cce179934cd75cbdd48e.zip
add initial ovf data source class
Diffstat (limited to 'cloudinit/DataSourceOVF.py')
-rw-r--r--cloudinit/DataSourceOVF.py58
1 files changed, 52 insertions, 6 deletions
diff --git a/cloudinit/DataSourceOVF.py b/cloudinit/DataSourceOVF.py
index b76d2ea8..10b8ea57 100644
--- a/cloudinit/DataSourceOVF.py
+++ b/cloudinit/DataSourceOVF.py
@@ -28,8 +28,48 @@ from xml.dom import minidom
from xml.dom import Node
class DataSourceOVF(DataSource.DataSource):
- pass
+ seed = None
+ seeddir = cloudinit.seeddir + '/ovf'
+
+ def __init__(self):
+ pass
+
+ def __str__(self):
+ mstr="DataSourceOVF"
+ mstr = mstr + " [seed=%s]" % self.seed
+ return(mstr)
+
+ def get_data(self):
+ (seedfile, contents) = get_ovf_env(seeddir)
+ if seedfile:
+ # found a seed dir
+ self.seed = "%s/%s" % (dirname,seedfile)
+ ret = read_ovf_environment(contents)
+ # self.user_data=ret['user-data']
+ # self.meta_data=ret['meta-data']
+ return(True)
+
+ (dev, fname, contents) = find_ovf_env()
+ if not dev:
+ return(False)
+
+ ret = read_ovf_environment(contents)
+ # self.user_data=ret['user-data']
+ # self.meta_data=ret['meta-data']
+ return(True)
+
+
+# this will return a dict with some content
+# meta-data, user-data
+def read_ovf_environment(contents):
+ # this should basically shove into python objects
+ # the values we read from ovf environment
+ self.metadata = md;
+ self.userdata_raw = ud
+
+# returns tuple of filename (in 'dirname', and the contents of the file)
+# on "not found", returns 'None' for filename and False for contents
def get_ovf_env(dirname):
env_names = ("ovf-env.xml", "ovf_env.xml", "OVF_ENV.XML", "OVF-ENV.XML" )
for fname in env_names:
@@ -142,11 +182,17 @@ def getProperties(environString):
propElems = findChild(propSections[0], lambda n: n.localName == "Property")
for elem in propElems:
- key, val = ( None, None )
- for attr in elem.attributes.values():
- if attr.namespaceURI == envNsURI:
- if attr.localName == "key" : key = attr.value
- if attr.localName == "value": val = attr.value
+ key = elem.attributes.getNamedItemNS(envNsURI,"key").value
+ val = elem.attributes.getNamedItemNS(envNsURI,"value").value
props[key] = val
return(props)
+
+if __name__ == "__main__":
+ import sys
+ envStr = open(sys.argv[1]).read()
+ props = getProperties(envStr)
+ import pprint
+ pprint.pprint(props)
+
+ read_ovf_environment