← Back to team overview

cloud-init-dev team mailing list archive

[Merge] lp:~smoser/cloud-init/lp-1115833 into lp:cloud-init

 

Scott Moser has proposed merging lp:~smoser/cloud-init/lp-1115833 into lp:cloud-init.

Requested reviews:
  cloud init development team (cloud-init-dev)
Related bugs:
  Bug #1115833 in cloud-init: "nocloud should be seed-able from config."
  https://bugs.launchpad.net/cloud-init/+bug/1115833

For more details, see:
https://code.launchpad.net/~smoser/cloud-init/lp-1115833/+merge/146928
-- 
https://code.launchpad.net/~smoser/cloud-init/lp-1115833/+merge/146928
Your team cloud init development team is requested to review the proposed merge of lp:~smoser/cloud-init/lp-1115833 into lp:cloud-init.
=== modified file 'cloudinit/sources/DataSourceNoCloud.py'
--- cloudinit/sources/DataSourceNoCloud.py	2012-06-21 15:38:12 +0000
+++ cloudinit/sources/DataSourceNoCloud.py	2013-02-06 18:39:19 +0000
@@ -77,37 +77,47 @@
             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 = 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")
+
+        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.

=== modified file 'doc/examples/cloud-config-datasources.txt'
--- doc/examples/cloud-config-datasources.txt	2012-08-14 15:40:47 +0000
+++ doc/examples/cloud-config-datasources.txt	2013-02-06 18:39:19 +0000
@@ -31,3 +31,14 @@
     #    <url>/user-data and <url>/meta-data
     # seedfrom: http://my.example.com/i-abcde
     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


Follow ups