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
This commit is contained in:
parent
73f2e2b35f
commit
7dc87eed28
@ -45,16 +45,12 @@ class DataSourceEc2(DataSource.DataSource):
|
|||||||
return("DataSourceEc2")
|
return("DataSourceEc2")
|
||||||
|
|
||||||
def get_data(self):
|
def get_data(self):
|
||||||
try:
|
seedret={ }
|
||||||
(md,ud) = util.read_seeded(self.cachedir + "/")
|
if util.read_optional_seed(seedret,base=self.cachedir + "/"):
|
||||||
self.userdata_raw = ud
|
self.userdata_raw = seedret['user-data']
|
||||||
self.metadata = md
|
self.metadata = seedret['meta-data']
|
||||||
cloudinit.log.debug("using seeded ec2 cache data in %s" % self.cachedir)
|
cloudinit.log.debug("using seeded ec2 data in %s" % self.cachedir)
|
||||||
return True
|
return True
|
||||||
except OSError, e:
|
|
||||||
if e.errno != errno.ENOENT:
|
|
||||||
cloudinit.log.warn("unexpected error from preseeded data")
|
|
||||||
raise
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not self.wait_for_metadata_service():
|
if not self.wait_for_metadata_service():
|
||||||
|
@ -48,30 +48,30 @@ class DataSourceNoCloud(DataSource.DataSource):
|
|||||||
"instance-id" : "nocloud"
|
"instance-id" : "nocloud"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
found = False
|
||||||
md = { }
|
md = { }
|
||||||
ud = ""
|
ud = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# parse the kernel command line, getting data passed in
|
# 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:
|
except:
|
||||||
util.logexc(cloudinit.log,util.WARN)
|
util.logexc(cloudinit.log,util.WARN)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# check to see if the seeddir has data.
|
# check to see if the seeddir has data.
|
||||||
try:
|
seedret={ }
|
||||||
(seeddir_md,ud) = util.read_seeded(self.seeddir + "/")
|
if util.read_optional_seed(seedret,base=self.seeddir + "/"):
|
||||||
self.metadata = md
|
md = util.mergedict(md,seedret['meta-data'])
|
||||||
md = util.mergedict(md,seeddir_md)
|
ud = seedret['user-data']
|
||||||
|
found = True
|
||||||
cloudinit.log.debug("using seeded cache data in %s" % self.seeddir)
|
cloudinit.log.debug("using seeded cache data in %s" % self.seeddir)
|
||||||
except OSError, e:
|
return True
|
||||||
if e.errno != errno.ENOENT:
|
|
||||||
util.logexc(cloudinit.log,util.WARN)
|
|
||||||
raise
|
|
||||||
|
|
||||||
# there was no indication on kernel cmdline or data
|
# there was no indication on kernel cmdline or data
|
||||||
# in the seeddir suggesting this handler should be used.
|
# in the seeddir suggesting this handler should be used.
|
||||||
if md is None:
|
if not found:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# the special argument "seedfrom" indicates we should
|
# the special argument "seedfrom" indicates we should
|
||||||
@ -102,10 +102,11 @@ class DataSourceNoCloud(DataSource.DataSource):
|
|||||||
self.userdata_raw = ud
|
self.userdata_raw = ud
|
||||||
return True
|
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:
|
# example cmdline:
|
||||||
# root=LABEL=uec-rootfs ro ds=nocloud
|
# 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 cmdline is None:
|
||||||
if 'DEBUG_PROC_CMDLINE' in os.environ:
|
if 'DEBUG_PROC_CMDLINE' in os.environ:
|
||||||
cmdline = os.environ["DEBUG_PROC_CMDLINE"]
|
cmdline = os.environ["DEBUG_PROC_CMDLINE"]
|
||||||
@ -116,7 +117,7 @@ def parse_cmdline_data(ds_id,cmdline=None):
|
|||||||
cmdline = " %s " % cmdline.lower()
|
cmdline = " %s " % cmdline.lower()
|
||||||
|
|
||||||
if not ( " %s " % ds_id in cmdline or " %s;" % ds_id in cmdline ):
|
if not ( " %s " % ds_id in cmdline or " %s;" % ds_id in cmdline ):
|
||||||
return None
|
return False
|
||||||
|
|
||||||
argline=""
|
argline=""
|
||||||
# cmdline can contain:
|
# cmdline can contain:
|
||||||
@ -134,7 +135,6 @@ def parse_cmdline_data(ds_id,cmdline=None):
|
|||||||
|
|
||||||
# short2long mapping to save cmdline typing
|
# short2long mapping to save cmdline typing
|
||||||
s2l = { "h" : "local-hostname", "i" : "instance-id", "s" : "seedfrom" }
|
s2l = { "h" : "local-hostname", "i" : "instance-id", "s" : "seedfrom" }
|
||||||
cfg = { }
|
|
||||||
for item in kvpairs:
|
for item in kvpairs:
|
||||||
try:
|
try:
|
||||||
(k,v) = item.split("=",1)
|
(k,v) = item.split("=",1)
|
||||||
@ -142,9 +142,9 @@ def parse_cmdline_data(ds_id,cmdline=None):
|
|||||||
k=item
|
k=item
|
||||||
v=None
|
v=None
|
||||||
if k in s2l: k=s2l[k]
|
if k in s2l: k=s2l[k]
|
||||||
cfg[k]=v
|
fill[k]=v
|
||||||
|
|
||||||
return(cfg)
|
return(True)
|
||||||
|
|
||||||
class DataSourceNoCloudNet(DataSourceNoCloud):
|
class DataSourceNoCloudNet(DataSourceNoCloud):
|
||||||
cmdline_id = "ds=nocloud-net"
|
cmdline_id = "ds=nocloud-net"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user