Skip to content

Commit 1fda22c

Browse files
committed
add initial ovf data source class
1 parent 9fe2d93 commit 1fda22c

2 files changed

Lines changed: 56 additions & 8 deletions

File tree

‎cloudinit/DataSourceOVF.py‎

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,48 @@
2828
from xml.dom import Node
2929

3030
class DataSourceOVF(DataSource.DataSource):
31-
pass
31+
seed = None
32+
seeddir = cloudinit.seeddir + '/ovf'
33+
34+
def __init__(self):
35+
pass
36+
37+
def __str__(self):
38+
mstr="DataSourceOVF"
39+
mstr = mstr + " [seed=%s]" % self.seed
40+
return(mstr)
41+
42+
def get_data(self):
43+
(seedfile, contents) = get_ovf_env(seeddir)
44+
if seedfile:
45+
# found a seed dir
46+
self.seed = "%s/%s" % (dirname,seedfile)
47+
ret = read_ovf_environment(contents)
48+
# self.user_data=ret['user-data']
49+
# self.meta_data=ret['meta-data']
50+
return(True)
51+
52+
(dev, fname, contents) = find_ovf_env()
53+
if not dev:
54+
return(False)
55+
56+
ret = read_ovf_environment(contents)
57+
# self.user_data=ret['user-data']
58+
# self.meta_data=ret['meta-data']
59+
return(True)
60+
61+
62+
# this will return a dict with some content
63+
# meta-data, user-data
64+
def read_ovf_environment(contents):
65+
# this should basically shove into python objects
66+
# the values we read from ovf environment
67+
self.metadata = md;
68+
self.userdata_raw = ud
69+
3270

71+
# returns tuple of filename (in 'dirname', and the contents of the file)
72+
# on "not found", returns 'None' for filename and False for contents
3373
def get_ovf_env(dirname):
3474
env_names = ("ovf-env.xml", "ovf_env.xml", "OVF_ENV.XML", "OVF-ENV.XML" )
3575
for fname in env_names:
@@ -142,11 +182,17 @@ def getProperties(environString):
142182
propElems = findChild(propSections[0], lambda n: n.localName == "Property")
143183

144184
for elem in propElems:
145-
key, val = ( None, None )
146-
for attr in elem.attributes.values():
147-
if attr.namespaceURI == envNsURI:
148-
if attr.localName == "key" : key = attr.value
149-
if attr.localName == "value": val = attr.value
185+
key = elem.attributes.getNamedItemNS(envNsURI,"key").value
186+
val = elem.attributes.getNamedItemNS(envNsURI,"value").value
150187
props[key] = val
151188

152189
return(props)
190+
191+
if __name__ == "__main__":
192+
import sys
193+
envStr = open(sys.argv[1]).read()
194+
props = getProperties(envStr)
195+
import pprint
196+
pprint.pprint(props)
197+
198+
read_ovf_environment

‎cloudinit/__init__.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,20 @@ def logging_set_from_cfg(cfg):
103103

104104
import DataSourceEc2
105105
import DataSourceNoCloud
106+
import DataSourceOVF
106107
import UserDataHandler
107108

108109
class CloudInit:
109110
datasource_map = {
110111
"ec2" : DataSourceEc2.DataSourceEc2,
111112
"nocloud" : DataSourceNoCloud.DataSourceNoCloud,
112-
"nocloud-net" : DataSourceNoCloud.DataSourceNoCloudNet
113+
"nocloud-net" : DataSourceNoCloud.DataSourceNoCloudNet,
114+
"ovf" : DataSourceOVF.DataSourceOVF,
113115
}
114116
datasource = None
115117
auto_orders = {
116118
"all": ( "nocloud-net", "ec2" ),
117-
"local" : ( "nocloud", ),
119+
"local" : ( "nocloud", "ovf" ),
118120
}
119121
cfg = None
120122
part_handlers = { }

0 commit comments

Comments
 (0)