diff options
author | Scott Moser <smoser@ubuntu.com> | 2016-03-24 15:53:27 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2016-03-24 15:53:27 -0400 |
commit | 1302e3dbf762e1f0a72d7b1682a78e8947a33b76 (patch) | |
tree | dfcaa4ff51940c342d1326bb7f300b37f594f886 /cloudinit/util.py | |
parent | a7053201e892f6401752e17998700d027d23ea89 (diff) | |
parent | 557650728d3c1b1c1bbd29f9292d43133c00cdd4 (diff) | |
download | vyos-cloud-init-1302e3dbf762e1f0a72d7b1682a78e8947a33b76.tar.gz vyos-cloud-init-1302e3dbf762e1f0a72d7b1682a78e8947a33b76.zip |
support reading network config from kernel command line
This adds support for suppling network configuration on the
kernel command line in 2 ways:
a.) kernel command line includes 'network-config=<base64>'
value of that parameter is base64 encoded json (or yaml)
it is taken as network config yaml.
In order to save space on kernel command line, it can be
base64 encoded gzipped json also.
b.) ip= paired with files authored by klibc's ipconfig tool
When network devices are brought up in the initramfs, klibc's
ipconfig tool writes files are named /run/net-<DEVNAME>.conf.
The best documentation available on that tool is
/usr/share/doc/libklibc/README.ipconfig.gz.
Also changes util.get_cmdline() to return the command line of
pid 1 if it is in a container. That is to make it consistent with
The systemd generator, and allow passing a command line to lxd,
as lxd does not mask /proc/cmdline.
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r-- | cloudinit/util.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py index 20916e53..0d21e11b 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -80,6 +80,8 @@ CONTAINER_TESTS = (['systemd-detect-virt', '--quiet', '--container'], ['running-in-container'], ['lxc-is-container']) +PROC_CMDLINE = None + def decode_binary(blob, encoding='utf-8'): # Converts a binary type into a text type using given encoding. @@ -1191,12 +1193,27 @@ def load_file(fname, read_cb=None, quiet=False, decode=True): def get_cmdline(): if 'DEBUG_PROC_CMDLINE' in os.environ: - cmdline = os.environ["DEBUG_PROC_CMDLINE"] + return os.environ["DEBUG_PROC_CMDLINE"] + + global PROC_CMDLINE + if PROC_CMDLINE is not None: + return PROC_CMDLINE + + if is_container(): + try: + contents = load_file("/proc/1/cmdline") + # replace nulls with space and drop trailing null + cmdline = contents.replace("\x00", " ")[:-1] + except Exception as e: + LOG.warn("failed reading /proc/1/cmdline: %s", e) + cmdline = "" else: try: cmdline = load_file("/proc/cmdline").strip() except: cmdline = "" + + PROC_CMDLINE = cmdline return cmdline @@ -1569,7 +1586,7 @@ def uptime(): try: if os.path.exists("/proc/uptime"): method = '/proc/uptime' - contents = load_file("/proc/uptime").strip() + contents = load_file("/proc/uptime") if contents: uptime_str = contents.split()[0] else: |