make config of nocloud datasource able to specify meta-data and user-data
This commit is contained in:
parent
a1efdc8a34
commit
cceaa4db42
@ -77,37 +77,47 @@ class DataSourceNoCloud(sources.DataSource):
|
|||||||
found.append("ds_config")
|
found.append("ds_config")
|
||||||
md["seedfrom"] = self.ds_cfg['seedfrom']
|
md["seedfrom"] = self.ds_cfg['seedfrom']
|
||||||
|
|
||||||
fslist = util.find_devs_with("TYPE=vfat")
|
# if ds_cfg has 'user-data' and 'meta-data'
|
||||||
fslist.extend(util.find_devs_with("TYPE=iso9660"))
|
if 'user-data' in self.ds_cfg and 'meta-data' in self.ds_cfg:
|
||||||
|
if self.ds_cfg['user-data']:
|
||||||
|
ud = util.mergedict(md, self.ds_cfg['user-data'])
|
||||||
|
if self.ds_cfg['meta-data'] is not False:
|
||||||
|
md = util.mergedict(md, self.ds_cfg['meta-data'])
|
||||||
|
if 'ds_config' not in found:
|
||||||
|
found.append("ds_config")
|
||||||
|
|
||||||
label_list = util.find_devs_with("LABEL=cidata")
|
if self.ds_cfg.get('fs_label', "cidata"):
|
||||||
devlist = list(set(fslist) & set(label_list))
|
fslist = util.find_devs_with("TYPE=vfat")
|
||||||
devlist.sort(reverse=True)
|
fslist.extend(util.find_devs_with("TYPE=iso9660"))
|
||||||
|
|
||||||
for dev in devlist:
|
label = self.ds_cfg.get('fs_label')
|
||||||
try:
|
label_list = util.find_devs_with("LABEL=%s" % label)
|
||||||
LOG.debug("Attempting to use data from %s", dev)
|
devlist = list(set(fslist) & set(label_list))
|
||||||
|
devlist.sort(reverse=True)
|
||||||
|
|
||||||
(newmd, newud) = util.mount_cb(dev, util.read_seeded)
|
for dev in devlist:
|
||||||
md = util.mergedict(newmd, md)
|
try:
|
||||||
ud = newud
|
LOG.debug("Attempting to use data from %s", dev)
|
||||||
|
|
||||||
# For seed from a device, the default mode is 'net'.
|
(newmd, newud) = util.mount_cb(dev, util.read_seeded)
|
||||||
# that is more likely to be what is desired.
|
md = util.mergedict(newmd, md)
|
||||||
# If they want dsmode of local, then they must
|
ud = newud
|
||||||
# specify that.
|
|
||||||
if 'dsmode' not in md:
|
|
||||||
md['dsmode'] = "net"
|
|
||||||
|
|
||||||
LOG.debug("Using data from %s", dev)
|
# For seed from a device, the default mode is 'net'.
|
||||||
found.append(dev)
|
# that is more likely to be what is desired. If they want
|
||||||
break
|
# dsmode of local, then they must specify that.
|
||||||
except OSError as e:
|
if 'dsmode' not in md:
|
||||||
if e.errno != errno.ENOENT:
|
md['dsmode'] = "net"
|
||||||
raise
|
|
||||||
except util.MountFailedError:
|
LOG.debug("Using data from %s", dev)
|
||||||
util.logexc(LOG, ("Failed to mount %s"
|
found.append(dev)
|
||||||
" when looking for data"), dev)
|
break
|
||||||
|
except OSError as e:
|
||||||
|
if e.errno != errno.ENOENT:
|
||||||
|
raise
|
||||||
|
except util.MountFailedError:
|
||||||
|
util.logexc(LOG, ("Failed to mount %s"
|
||||||
|
" when looking for data"), dev)
|
||||||
|
|
||||||
# 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.
|
||||||
|
@ -31,3 +31,14 @@ datasource:
|
|||||||
# <url>/user-data and <url>/meta-data
|
# <url>/user-data and <url>/meta-data
|
||||||
# seedfrom: http://my.example.com/i-abcde
|
# seedfrom: http://my.example.com/i-abcde
|
||||||
seedfrom: None
|
seedfrom: None
|
||||||
|
|
||||||
|
# fs_label: the label on filesystems to be searched for NoCloud source
|
||||||
|
fs_label: cidata
|
||||||
|
|
||||||
|
# these are optional, but allow you to basically provide a datasource
|
||||||
|
# right here
|
||||||
|
user-data: |
|
||||||
|
# This is the user-data verbatum
|
||||||
|
meta-data:
|
||||||
|
instance-id: i-87018aed
|
||||||
|
local-hostname: myhost.internal
|
||||||
|
Loading…
x
Reference in New Issue
Block a user