← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~goneri/cloud-init:freebsd_nocloud into cloud-init:master

 

Gonéri Le Bouder has proposed merging ~goneri/cloud-init:freebsd_nocloud into cloud-init:master.

Requested reviews:
  cloud-init commiters (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~goneri/cloud-init/+git/cloud-init/+merge/365630
-- 
Your team cloud-init commiters is requested to review the proposed merge of ~goneri/cloud-init:freebsd_nocloud into cloud-init:master.
diff --git a/cloudinit/sources/DataSourceNoCloud.py b/cloudinit/sources/DataSourceNoCloud.py
index 6860f0c..a101383 100644
--- a/cloudinit/sources/DataSourceNoCloud.py
+++ b/cloudinit/sources/DataSourceNoCloud.py
@@ -35,6 +35,26 @@ class DataSourceNoCloud(sources.DataSource):
         root = sources.DataSource.__str__(self)
         return "%s [seed=%s][dsmode=%s]" % (root, self.seed, self.dsmode)
 
+    def _get_devices(self, label):
+        devlist = []
+        if util.is_FreeBSD():
+            for p in ['/dev/msdosfs/' + label, '/dev/iso9660/' + label]:
+                if os.path.exists(p):
+                    devlist.append(p)
+        else:
+            # Query optical drive to get it in blkid cache for 2.6 kernels
+            util.find_devs_with(path="/dev/sr0")
+            util.find_devs_with(path="/dev/sr1")
+
+            fslist = util.find_devs_with("TYPE=vfat")
+            fslist.extend(util.find_devs_with("TYPE=iso9660"))
+
+            label_list = util.find_devs_with("LABEL=%s" % label)
+            devlist = list(set(fslist) & set(label_list))
+            devlist.sort(reverse=True)
+        return devlist
+
+
     def _get_data(self):
         defaults = {
             "instance-id": "nocloud",
@@ -99,18 +119,7 @@ class DataSourceNoCloud(sources.DataSource):
 
         label = self.ds_cfg.get('fs_label', "cidata")
         if label is not None:
-            # Query optical drive to get it in blkid cache for 2.6 kernels
-            util.find_devs_with(path="/dev/sr0")
-            util.find_devs_with(path="/dev/sr1")
-
-            fslist = util.find_devs_with("TYPE=vfat")
-            fslist.extend(util.find_devs_with("TYPE=iso9660"))
-
-            label_list = util.find_devs_with("LABEL=%s" % label)
-            devlist = list(set(fslist) & set(label_list))
-            devlist.sort(reverse=True)
-
-            for dev in devlist:
+            for dev in self._get_devices(label):
                 try:
                     LOG.debug("Attempting to use data from %s", dev)
 
@@ -118,9 +127,8 @@ class DataSourceNoCloud(sources.DataSource):
                         seeded = util.mount_cb(dev, _pp2d_callback,
                                                pp2d_kwargs)
                     except ValueError:
-                        if dev in label_list:
-                            LOG.warning("device %s with label=%s not a"
-                                        "valid seed.", dev, label)
+                        LOG.warning("device %s with label=%s not a"
+                                    "valid seed.", dev, label)
                         continue
 
                     mydata = _merge_new_seed(mydata, seeded)
diff --git a/config/cloud.cfg.tmpl b/config/cloud.cfg.tmpl
index 25db43e..d3c50dd 100644
--- a/config/cloud.cfg.tmpl
+++ b/config/cloud.cfg.tmpl
@@ -33,7 +33,7 @@ preserve_hostname: false
 {% if variant in ["freebsd"] %}
 # This should not be required, but leave it in place until the real cause of
 # not beeing able to find -any- datasources is resolved.
-datasource_list: ['ConfigDrive', 'Azure', 'OpenStack', 'Ec2']
+datasource_list: ['ConfigDrive', 'Azure', 'OpenStack', 'Ec2', 'NoCloud']
 {% endif %}
 # Example datasource config
 # datasource:

Follow ups