summaryrefslogtreecommitdiff
path: root/cloudinit/DataSourceNoCloud.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2010-08-12 12:02:33 -0400
committerScott Moser <smoser@ubuntu.com>2010-08-12 12:02:33 -0400
commit6ffc9647bb18862dbe1d11b5ca370a006916199b (patch)
treee8bb6ffeb731085b536babef7a43eb60b69d355d /cloudinit/DataSourceNoCloud.py
parent1667516626339f4a7ea91b68696a67c0ea8b7b92 (diff)
downloadvyos-cloud-init-6ffc9647bb18862dbe1d11b5ca370a006916199b.tar.gz
vyos-cloud-init-6ffc9647bb18862dbe1d11b5ca370a006916199b.zip
use read_optional_seed, change 'parse_cmdline_data' to return boolean
using read_optional_seed in DataSourceEc2 and DataSourceNoCloud. change parse_cmdline_data to fill a dictionary that is supplied by caller. It then returns strictly true or false based on whether or not it was specified in cmdline
Diffstat (limited to 'cloudinit/DataSourceNoCloud.py')
-rw-r--r--cloudinit/DataSourceNoCloud.py32
1 files changed, 16 insertions, 16 deletions
diff --git a/cloudinit/DataSourceNoCloud.py b/cloudinit/DataSourceNoCloud.py
index 573f3f43..b20a35e2 100644
--- a/cloudinit/DataSourceNoCloud.py
+++ b/cloudinit/DataSourceNoCloud.py
@@ -48,30 +48,30 @@ class DataSourceNoCloud(DataSource.DataSource):
"instance-id" : "nocloud"
}
+ found = False
md = { }
ud = ""
try:
# parse the kernel command line, getting data passed in
- md = parse_cmdline_data(self.cmdline_id)
+ if parse_cmdline_data(self.cmdline_id, md):
+ found = True
except:
util.logexc(cloudinit.log,util.WARN)
return False
# check to see if the seeddir has data.
- try:
- (seeddir_md,ud) = util.read_seeded(self.seeddir + "/")
- self.metadata = md
- md = util.mergedict(md,seeddir_md)
+ seedret={ }
+ if util.read_optional_seed(seedret,base=self.seeddir + "/"):
+ md = util.mergedict(md,seedret['meta-data'])
+ ud = seedret['user-data']
+ found = True
cloudinit.log.debug("using seeded cache data in %s" % self.seeddir)
- except OSError, e:
- if e.errno != errno.ENOENT:
- util.logexc(cloudinit.log,util.WARN)
- raise
+ return True
# there was no indication on kernel cmdline or data
# in the seeddir suggesting this handler should be used.
- if md is None:
+ if not found:
return False
# the special argument "seedfrom" indicates we should
@@ -102,10 +102,11 @@ class DataSourceNoCloud(DataSource.DataSource):
self.userdata_raw = ud
return True
-# returns a dictionary of key/val or None if cmdline did not have data
+# returns true or false indicating if cmdline indicated
+# that this module should be used
# example cmdline:
# root=LABEL=uec-rootfs ro ds=nocloud
-def parse_cmdline_data(ds_id,cmdline=None):
+def parse_cmdline_data(ds_id,fill,cmdline=None):
if cmdline is None:
if 'DEBUG_PROC_CMDLINE' in os.environ:
cmdline = os.environ["DEBUG_PROC_CMDLINE"]
@@ -116,7 +117,7 @@ def parse_cmdline_data(ds_id,cmdline=None):
cmdline = " %s " % cmdline.lower()
if not ( " %s " % ds_id in cmdline or " %s;" % ds_id in cmdline ):
- return None
+ return False
argline=""
# cmdline can contain:
@@ -134,7 +135,6 @@ def parse_cmdline_data(ds_id,cmdline=None):
# short2long mapping to save cmdline typing
s2l = { "h" : "local-hostname", "i" : "instance-id", "s" : "seedfrom" }
- cfg = { }
for item in kvpairs:
try:
(k,v) = item.split("=",1)
@@ -142,9 +142,9 @@ def parse_cmdline_data(ds_id,cmdline=None):
k=item
v=None
if k in s2l: k=s2l[k]
- cfg[k]=v
+ fill[k]=v
- return(cfg)
+ return(True)
class DataSourceNoCloudNet(DataSourceNoCloud):
cmdline_id = "ds=nocloud-net"