diff options
Diffstat (limited to 'cloudinit/config/cc_mounts.py')
-rw-r--r-- | cloudinit/config/cc_mounts.py | 86 |
1 files changed, 50 insertions, 36 deletions
diff --git a/cloudinit/config/cc_mounts.py b/cloudinit/config/cc_mounts.py index 452c9e83..5b630f8b 100644 --- a/cloudinit/config/cc_mounts.py +++ b/cloudinit/config/cc_mounts.py @@ -1,22 +1,10 @@ -# vi: ts=4 expandtab -# -# Copyright (C) 2009-2010 Canonical Ltd. -# Copyright (C) 2012 Hewlett-Packard Development Company, L.P. -# -# Author: Scott Moser <scott.moser@canonical.com> -# Author: Juerg Haefliger <juerg.haefliger@hp.com> -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 3, as -# published by the Free Software Foundation. +# Copyright (C) 2009-2010 Canonical Ltd. +# Copyright (C) 2012 Hewlett-Packard Development Company, L.P. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# Author: Scott Moser <scott.moser@canonical.com> +# Author: Juerg Haefliger <juerg.haefliger@hp.com> # -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# This file is part of cloud-init. See LICENSE file for license information. """ Mounts @@ -42,6 +30,14 @@ values. It defaults to:: mount_default_fields: [none, none, "auto", "defaults,nobootwait", "0", "2"] +On a systemd booted system that default is the mostly equivalent:: + + mount_default_fields: [none, none, "auto", + "defaults,nofail,x-systemd.requires=cloud-init.service", "0", "2"] + +Note that `nobootwait` is an upstart specific boot option that somewhat +equates to the more standard `nofail`. + Swap files can be configured by setting the path to the swap file to create with ``filename``, the size of the swap file with ``size`` maximum size of the swap file if using an ``size: auto`` with ``maxsize``. By default no @@ -58,8 +54,8 @@ swap file is created. mounts: - [ /dev/ephemeral0, /mnt, auto, "defaults,noexec" ] - [ sdc, /opt/data ] - - [ xvdh, /opt/data, "auto", "defaults,nobootwait", "0", "0" ] - mount_default_fields: [None, None, "auto", "nefaults,nobootwait", "0", "2"] + - [ xvdh, /opt/data, "auto", "defaults,nofail", "0", "0" ] + mount_default_fields: [None, None, "auto", "defaults,nofail", "0", "2"] swap: filename: <file> size: <"auto"/size in bytes> @@ -327,6 +323,8 @@ def handle(_name, cfg, cloud, log, _args): if "mounts" in cfg: cfgmnt = cfg["mounts"] + LOG.debug("mounts configuration is %s", cfgmnt) + for i in range(len(cfgmnt)): # skip something that wasn't a list if not isinstance(cfgmnt[i], list): @@ -423,37 +421,53 @@ def handle(_name, cfg, cloud, log, _args): cc_lines.append('\t'.join(line)) fstab_lines = [] + removed = [] for line in util.load_file(FSTAB_PATH).splitlines(): try: toks = WS.split(line) if toks[3].find(comment) != -1: + removed.append(line) continue except Exception: pass fstab_lines.append(line) + for d in dirs: + try: + util.ensure_dir(d) + except Exception: + util.logexc(log, "Failed to make '%s' config-mount", d) + + sadds = [WS.sub(" ", n) for n in cc_lines] + sdrops = [WS.sub(" ", n) for n in removed] + + sops = (["- " + drop for drop in sdrops if drop not in sadds] + + ["+ " + add for add in sadds if add not in sdrops]) + fstab_lines.extend(cc_lines) contents = "%s\n" % ('\n'.join(fstab_lines)) util.write_file(FSTAB_PATH, contents) + activate_cmds = [] if needswap: - try: - util.subp(("swapon", "-a")) - except Exception: - util.logexc(log, "Activating swap via 'swapon -a' failed") + activate_cmds.append(["swapon", "-a"]) - for d in dirs: + if len(sops) == 0: + log.debug("No changes to /etc/fstab made.") + else: + log.debug("Changes to fstab: %s", sops) + activate_cmds.append(["mount", "-a"]) + if uses_systemd: + activate_cmds.append(["systemctl", "daemon-reload"]) + + fmt = "Activating swap and mounts with: %s" + for cmd in activate_cmds: + fmt = "Activate mounts: %s:" + ' '.join(cmd) try: - util.ensure_dir(d) - except Exception: - util.logexc(log, "Failed to make '%s' config-mount", d) + util.subp(cmd) + log.debug(fmt, "PASS") + except util.ProcessExecutionError: + log.warn(fmt, "FAIL") + util.logexc(log, fmt, "FAIL") - activate_cmd = ["mount", "-a"] - if uses_systemd: - activate_cmd = ["systemctl", "daemon-reload"] - fmt = "Activate mounts: %s:" + ' '.join(activate_cmd) - try: - util.subp(activate_cmd) - LOG.debug(fmt, "PASS") - except util.ProcessExecutionError: - util.logexc(log, fmt, "FAIL") +# vi: ts=4 expandtab |