summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2013-02-07 22:14:42 -0500
committerScott Moser <smoser@ubuntu.com>2013-02-07 22:14:42 -0500
commit174bc39e6b2c1cac3f73f67f25fad87cab16fa42 (patch)
treeb4782eae15b11eff4c6746a2e09135cd7f57c8b2 /cloudinit
parentb7689728ead61366f3980272ae8212ba0b0225af (diff)
parenta0f882fdd306ef7b3b90c53d5622eb5a6878cb81 (diff)
downloadvyos-cloud-init-174bc39e6b2c1cac3f73f67f25fad87cab16fa42.tar.gz
vyos-cloud-init-174bc39e6b2c1cac3f73f67f25fad87cab16fa42.zip
DataSourceNoCloud: allow setting user-data and meta-data in config
This allows a single file to declare and activate this data source. This could come from: * cloud-config-url on kernel cmdline * /etc/cloud/cloud.cfg.d * debian preseed of 'cloud-init/local-cloud-config' Also here is * some tests * a small fix to parse_cmdline_data found when writing those tests. LP: #1115833
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/sources/DataSourceNoCloud.py74
1 files changed, 43 insertions, 31 deletions
diff --git a/cloudinit/sources/DataSourceNoCloud.py b/cloudinit/sources/DataSourceNoCloud.py
index bed500a2..097bbc52 100644
--- a/cloudinit/sources/DataSourceNoCloud.py
+++ b/cloudinit/sources/DataSourceNoCloud.py
@@ -77,37 +77,47 @@ class DataSourceNoCloud(sources.DataSource):
found.append("ds_config")
md["seedfrom"] = self.ds_cfg['seedfrom']
- fslist = util.find_devs_with("TYPE=vfat")
- fslist.extend(util.find_devs_with("TYPE=iso9660"))
-
- label_list = util.find_devs_with("LABEL=cidata")
- devlist = list(set(fslist) & set(label_list))
- devlist.sort(reverse=True)
-
- for dev in devlist:
- try:
- LOG.debug("Attempting to use data from %s", dev)
-
- (newmd, newud) = util.mount_cb(dev, util.read_seeded)
- md = util.mergedict(newmd, md)
- ud = newud
-
- # For seed from a device, the default mode is 'net'.
- # that is more likely to be what is desired.
- # If they want dsmode of local, then they must
- # specify that.
- if 'dsmode' not in md:
- md['dsmode'] = "net"
-
- LOG.debug("Using data from %s", dev)
- found.append(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)
+ # if ds_cfg has 'user-data' and 'meta-data'
+ if 'user-data' in self.ds_cfg and 'meta-data' in self.ds_cfg:
+ if self.ds_cfg['user-data']:
+ ud = 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")
+
+ if self.ds_cfg.get('fs_label', "cidata"):
+ fslist = util.find_devs_with("TYPE=vfat")
+ fslist.extend(util.find_devs_with("TYPE=iso9660"))
+
+ label = self.ds_cfg.get('fs_label')
+ label_list = util.find_devs_with("LABEL=%s" % label)
+ devlist = list(set(fslist) & set(label_list))
+ devlist.sort(reverse=True)
+
+ for dev in devlist:
+ try:
+ LOG.debug("Attempting to use data from %s", dev)
+
+ (newmd, newud) = util.mount_cb(dev, util.read_seeded)
+ md = util.mergedict(newmd, md)
+ ud = newud
+
+ # For seed from a device, the default mode is 'net'.
+ # that is more likely to be what is desired. If they want
+ # dsmode of local, then they must specify that.
+ if 'dsmode' not in md:
+ md['dsmode'] = "net"
+
+ LOG.debug("Using data from %s", dev)
+ found.append(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
# in the seeddir suggesting this handler should be used.
@@ -195,6 +205,8 @@ def parse_cmdline_data(ds_id, fill, cmdline=None):
# short2long mapping to save cmdline typing
s2l = {"h": "local-hostname", "i": "instance-id", "s": "seedfrom"}
for item in kvpairs:
+ if item == "":
+ continue
try:
(k, v) = item.split("=", 1)
except: