← Back to team overview

cloud-init-dev team mailing list archive

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

 

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

Requested reviews:
  cloud init development team (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~smoser/cloud-init/freebsd-configdrive/+merge/235512

support 'mtype' as a list, and fix up freebsd mount types
  
this supports a list of input, and cleans up that list
for the platform specific mount types.  Basically,
 mtype = None
 means 'mount -t auto' or the equivalent for the platform.

and 'iso9660' means "iso type".


-- 
https://code.launchpad.net/~smoser/cloud-init/freebsd-configdrive/+merge/235512
Your team cloud init development team is requested to review the proposed merge of lp:~smoser/cloud-init/freebsd-configdrive into lp:cloud-init.
=== modified file 'cloudinit/sources/DataSourceConfigDrive.py'
--- cloudinit/sources/DataSourceConfigDrive.py	2014-09-11 01:17:40 +0000
+++ cloudinit/sources/DataSourceConfigDrive.py	2014-09-22 18:37:18 +0000
@@ -37,7 +37,9 @@
 VALID_DSMODES = ("local", "net", "pass", "disabled")
 FS_TYPES = ('vfat', 'iso9660')
 LABEL_TYPES = ('config-2',)
-OPTICAL_DEVICES = tuple(('/dev/sr%s' % i for i in range(0, 2)))
+POSSIBLE_MOUNTS = ('sr', 'cd')
+OPTICAL_DEVICES = tuple(('/dev/%s%s' % (z, i) for z in POSSIBLE_MOUNTS
+                  for i in range(0, 2)))
 
 
 class DataSourceConfigDrive(openstack.SourceMixin, sources.DataSource):
@@ -70,7 +72,15 @@
         if not found:
             for dev in find_candidate_devs():
                 try:
-                    results = util.mount_cb(dev, read_config_drive)
+                    # Set mtype if freebsd and turn off sync
+                    if dev.startswith("/dev/cd"):
+                        mtype = "cd9660"
+                        sync = False
+                    else:
+                        mtype = None
+                        sync = True
+                    results = util.mount_cb(dev, read_config_drive, mtype=mtype,
+                                            sync=sync)
                     found = dev
                 except openstack.NonReadable:
                     pass

=== modified file 'cloudinit/sources/DataSourceOVF.py'
--- cloudinit/sources/DataSourceOVF.py	2014-08-26 18:50:11 +0000
+++ cloudinit/sources/DataSourceOVF.py	2014-09-22 18:37:18 +0000
@@ -215,8 +215,7 @@
             continue
 
         try:
-            (fname, contents) = util.mount_cb(fullp,
-                                               get_ovf_env, mtype=mtype)
+            (fname, contents) = util.mount_cb(fullp, get_ovf_env, mtype=mtype)
         except util.MountFailedError:
             LOG.debug("%s not mountable as iso9660" % fullp)
             continue

=== modified file 'cloudinit/util.py'
--- cloudinit/util.py	2014-09-16 00:13:07 +0000
+++ cloudinit/util.py	2014-09-22 18:37:18 +0000
@@ -1297,7 +1297,7 @@
         yield umount
     finally:
         if umount:
-            umount_cmd = ["umount", '-l', umount]
+            umount_cmd = ["umount", umount]
             subp(umount_cmd)
 
 
@@ -1346,37 +1346,69 @@
     Mount the device, call method 'callback' passing the directory
     in which it was mounted, then unmount.  Return whatever 'callback'
     returned.  If data != None, also pass data to callback.
+
+    mtype is a filesystem type.  it may be a list, string (a single fsname)
+    or a list of fsnames.
     """
+
+    if isinstance(mtype, str):
+        mtypes = [mtype]
+    elif isinstance(mtype, (list, tuple)):
+        mtypes = list(mtype)
+    elif mtype is None:
+        mtypes = None
+
+    # clean up 'mtype' input a bit based on platform.
+    platform = platform.system.lower()
+    if platform == "linux":
+        if mtypes is None:
+            mtypes = ["auto"]
+    elif platform.endswith("bsd"):
+        if mtypes is None:
+            mtypes = ['ufs', 'cd9660', 'vfat']
+        for index, mtype in enumerate(mtypes):
+            if mtype == "iso9660":
+                mtypes[index] = "cd9660"
+    else:
+        mtypes = []
+
     mounted = mounts()
     with tempdir() as tmpd:
         umount = False
         if device in mounted:
             mountpoint = mounted[device]['mountpoint']
         else:
-            try:
-                mountcmd = ['mount']
-                mountopts = []
-                if rw:
-                    mountopts.append('rw')
-                else:
-                    mountopts.append('ro')
-                if sync:
-                    # This seems like the safe approach to do
-                    # (ie where this is on by default)
-                    mountopts.append("sync")
-                if mountopts:
-                    mountcmd.extend(["-o", ",".join(mountopts)])
-                if mtype:
-                    mountcmd.extend(['-t', mtype])
-                mountcmd.append(device)
-                mountcmd.append(tmpd)
-                subp(mountcmd)
-                umount = tmpd  # This forces it to be unmounted (when set)
-                mountpoint = tmpd
-            except (IOError, OSError) as exc:
-                raise MountFailedError(("Failed mounting %s "
-                                        "to %s due to: %s") %
+            for mtype in mtypes:
+                mountpoint = None
+                try:
+                    mountcmd = ['mount']
+                    mountopts = []
+                    if rw:
+                        mountopts.append('rw')
+                    else:
+                        mountopts.append('ro')
+                    if sync:
+                        # This seems like the safe approach to do
+                        # (ie where this is on by default)
+                        mountopts.append("sync")
+                    if mountopts:
+                        mountcmd.extend(["-o", ",".join(mountopts)])
+                    if mtype:
+                        mountcmd.extend(['-t', mtype])
+                    mountcmd.append(device)
+                    mountcmd.append(tmpd)
+                    subp(mountcmd)
+                    umount = tmpd  # This forces it to be unmounted (when set)
+                    mountpoint = tmpd
+                    break
+                except (IOError, OSError) as exc:
+                    LOG.debug("Failed mount of '%s' as '%s': %s",
+                              device, mtype, exc)
+                    pass
+            if not mountpoint:
+                raise MountFailedError("Failed mounting %s to %s due to: %s" %
                                        (device, tmpd, exc))
+
         # Be nice and ensure it ends with a slash
         if not mountpoint.endswith("/"):
             mountpoint += "/"

=== added file 'templates/hosts.freebsd.tmpl'
--- templates/hosts.freebsd.tmpl	1970-01-01 00:00:00 +0000
+++ templates/hosts.freebsd.tmpl	2014-09-22 18:37:18 +0000
@@ -0,0 +1,24 @@
+## template:jinja
+{#
+This file /etc/cloud/templates/hosts.freebsd.tmpl is only utilized
+if enabled in cloud-config.  Specifically, in order to enable it
+you need to add the following to config:
+  manage_etc_hosts: True
+-#}
+# Your system has configured 'manage_etc_hosts' as True.
+# As a result, if you wish for changes to this file to persist
+# then you will need to either
+# a.) make changes to the master file in /etc/cloud/templates/hosts.freebsd.tmpl
+# b.) change or remove the value of 'manage_etc_hosts' in
+#     /etc/cloud/cloud.cfg or cloud-config from user-data
+# 
+# The following lines are desirable for IPv4 capable hosts
+127.0.0.1 {{fqdn}} {{hostname}}
+127.0.0.1 localhost.localdomain localhost
+127.0.0.1 localhost4.localdomain4 localhost4
+
+# The following lines are desirable for IPv6 capable hosts
+::1 {{fqdn}} {{hostname}}
+::1 localhost.localdomain localhost
+::1 localhost6.localdomain6 localhost6
+


Follow ups