summaryrefslogtreecommitdiff
path: root/cloudinit/config
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2014-01-23 15:17:17 -0500
committerScott Moser <smoser@ubuntu.com>2014-01-23 15:17:17 -0500
commit573ee6d9d641356374ac616f53cb254d4da7c9db (patch)
treee96228256276875c47c5031160bd2f3cbe3b5398 /cloudinit/config
parent1781668dd65737a800c2c8fdbb79c6f1288d3ef2 (diff)
parentc833a84f08019ba4413937f2f1b1f12a4ffe5632 (diff)
downloadvyos-cloud-init-573ee6d9d641356374ac616f53cb254d4da7c9db.tar.gz
vyos-cloud-init-573ee6d9d641356374ac616f53cb254d4da7c9db.zip
merge from trunk
Diffstat (limited to 'cloudinit/config')
-rw-r--r--cloudinit/config/cc_debug.py79
-rw-r--r--cloudinit/config/cc_growpart.py28
-rw-r--r--cloudinit/config/cc_resizefs.py33
-rw-r--r--cloudinit/config/cc_scripts_vendor.py43
4 files changed, 154 insertions, 29 deletions
diff --git a/cloudinit/config/cc_debug.py b/cloudinit/config/cc_debug.py
new file mode 100644
index 00000000..7219b0f8
--- /dev/null
+++ b/cloudinit/config/cc_debug.py
@@ -0,0 +1,79 @@
+# vi: ts=4 expandtab
+#
+# Copyright (C) 2013 Yahoo! Inc.
+#
+# 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.
+#
+# 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from cloudinit import type_utils
+from cloudinit import util
+import copy
+from StringIO import StringIO
+
+
+def _make_header(text):
+ header = StringIO()
+ header.write("-" * 80)
+ header.write("\n")
+ header.write(text.center(80, ' '))
+ header.write("\n")
+ header.write("-" * 80)
+ header.write("\n")
+ return header.getvalue()
+
+
+def handle(name, cfg, cloud, log, args):
+ verbose = util.get_cfg_by_path(cfg, ('debug', 'verbose'), default=True)
+ if args:
+ # if args are provided (from cmdline) then explicitly set verbose
+ out_file = args[0]
+ verbose = True
+ else:
+ out_file = util.get_cfg_by_path(cfg, ('debug', 'output'))
+
+ if not verbose:
+ log.debug(("Skipping module named %s,"
+ " verbose printing disabled"), name)
+ return
+ # Clean out some keys that we just don't care about showing...
+ dump_cfg = copy.deepcopy(cfg)
+ for k in ['log_cfgs']:
+ dump_cfg.pop(k, None)
+ all_keys = list(dump_cfg.keys())
+ for k in all_keys:
+ if k.startswith("_"):
+ dump_cfg.pop(k, None)
+ # Now dump it...
+ to_print = StringIO()
+ to_print.write(_make_header("Config"))
+ to_print.write(util.yaml_dumps(dump_cfg))
+ to_print.write("\n")
+ to_print.write(_make_header("MetaData"))
+ to_print.write(util.yaml_dumps(cloud.datasource.metadata))
+ to_print.write("\n")
+ to_print.write(_make_header("Misc"))
+ to_print.write("Datasource: %s\n" %
+ (type_utils.obj_name(cloud.datasource)))
+ to_print.write("Distro: %s\n" % (type_utils.obj_name(cloud.distro)))
+ to_print.write("Hostname: %s\n" % (cloud.get_hostname(True)))
+ to_print.write("Instance ID: %s\n" % (cloud.get_instance_id()))
+ to_print.write("Locale: %s\n" % (cloud.get_locale()))
+ to_print.write("Launch IDX: %s\n" % (cloud.launch_index))
+ contents = to_print.getvalue()
+ content_to_file = []
+ for line in contents.splitlines():
+ line = "ci-info: %s\n" % (line)
+ content_to_file.append(line)
+ if out_file:
+ util.write_file(out_file, "".join(content_to_file), 0644, "w")
+ else:
+ util.multi_log("".join(content_to_file), console=True, stderr=False)
diff --git a/cloudinit/config/cc_growpart.py b/cloudinit/config/cc_growpart.py
index 29d8b49b..1d3a4412 100644
--- a/cloudinit/config/cc_growpart.py
+++ b/cloudinit/config/cc_growpart.py
@@ -80,30 +80,6 @@ class ResizeFailedException(Exception):
pass
-class ResizeParted(object):
- def available(self):
- myenv = os.environ.copy()
- myenv['LANG'] = 'C'
-
- try:
- (out, _err) = util.subp(["parted", "--help"], env=myenv)
- if re.search(r"COMMAND.*resizepart\s+", out, re.DOTALL):
- return True
-
- except util.ProcessExecutionError:
- pass
- return False
-
- def resize(self, diskdev, partnum, partdev):
- before = get_size(partdev)
- try:
- util.subp(["parted", diskdev, "resizepart", partnum])
- except util.ProcessExecutionError as e:
- raise ResizeFailedException(e)
-
- return (before, get_size(partdev))
-
-
class ResizeGrowPart(object):
def available(self):
myenv = os.environ.copy()
@@ -318,6 +294,4 @@ def handle(_name, cfg, _cloud, log, _args):
else:
log.debug("'%s' %s: %s" % (entry, action, msg))
-# LP: 1212444 FIXME re-order and favor ResizeParted
-#RESIZERS = (('growpart', ResizeGrowPart),)
-RESIZERS = (('growpart', ResizeGrowPart), ('parted', ResizeParted), ('gpart', ResizeGpart))
+RESIZERS = (('growpart', ResizeGrowPart), ('gpart', ResizeGpart))
diff --git a/cloudinit/config/cc_resizefs.py b/cloudinit/config/cc_resizefs.py
index 95bc7a4e..be406034 100644
--- a/cloudinit/config/cc_resizefs.py
+++ b/cloudinit/config/cc_resizefs.py
@@ -56,6 +56,25 @@ RESIZE_FS_PREFIXES_CMDS = [
NOBLOCK = "noblock"
+def rootdev_from_cmdline(cmdline):
+ found = None
+ for tok in cmdline.split():
+ if tok.startswith("root="):
+ found = tok[5:]
+ break
+ if found is None:
+ return None
+
+ if found.startswith("/dev/"):
+ return found
+ if found.startswith("LABEL="):
+ return "/dev/disk/by-label/" + found[len("LABEL="):]
+ if found.startswith("UUID="):
+ return "/dev/disk/by-uuid/" + found[len("UUID="):]
+
+ return "/dev/" + found
+
+
def handle(name, cfg, _cloud, log, args):
if len(args) != 0:
resize_root = args[0]
@@ -83,10 +102,20 @@ def handle(name, cfg, _cloud, log, args):
info = "dev=%s mnt_point=%s path=%s" % (devpth, mount_point, resize_what)
log.debug("resize_info: %s" % info)
+ container = util.is_container()
+
+ if (devpth == "/dev/root" and not os.path.exists(devpth) and
+ not container):
+ devpth = rootdev_from_cmdline(util.get_cmdline())
+ if devpth is None:
+ log.warn("Unable to find device '/dev/root'")
+ return
+ log.debug("Converted /dev/root to '%s' per kernel cmdline", devpth)
+
try:
statret = os.stat(devpth)
except OSError as exc:
- if util.is_container() and exc.errno == errno.ENOENT:
+ if container and exc.errno == errno.ENOENT:
log.debug("Device '%s' did not exist in container. "
"cannot resize: %s" % (devpth, info))
elif exc.errno == errno.ENOENT:
@@ -97,7 +126,7 @@ def handle(name, cfg, _cloud, log, args):
return
if not stat.S_ISBLK(statret.st_mode) and not stat.S_ISCHR(statret.st_mode):
- if util.is_container():
+ if container:
log.debug("device '%s' not a block device in container."
" cannot resize: %s" % (devpth, info))
else:
diff --git a/cloudinit/config/cc_scripts_vendor.py b/cloudinit/config/cc_scripts_vendor.py
new file mode 100644
index 00000000..0c9e504e
--- /dev/null
+++ b/cloudinit/config/cc_scripts_vendor.py
@@ -0,0 +1,43 @@
+# vi: ts=4 expandtab
+#
+# Copyright (C) 2014 Canonical Ltd.
+#
+# Author: Ben Howard <ben.howard@canonical.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.
+#
+# 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import os
+
+from cloudinit import util
+
+from cloudinit.settings import PER_INSTANCE
+
+frequency = PER_INSTANCE
+
+SCRIPT_SUBDIR = 'vendor'
+
+
+def handle(name, cfg, cloud, log, _args):
+ # This is written to by the vendor data handlers
+ # any vendor data shell scripts get placed in runparts_path
+ runparts_path = os.path.join(cloud.get_ipath_cur(), 'scripts',
+ SCRIPT_SUBDIR)
+
+ prefix = util.get_cfg_by_path(cfg, ('vendor_data', 'prefix'), [])
+
+ try:
+ util.runparts(runparts_path, exe_prefix=prefix)
+ except:
+ log.warn("Failed to run module %s (%s in %s)",
+ name, SCRIPT_SUBDIR, runparts_path)
+ raise