summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2017-05-16 13:43:55 -0400
committerScott Moser <smoser@brickies.net>2017-05-16 15:34:21 -0400
commit4bcc947301bedc5ebf430cfaf6e4597bfb174aa7 (patch)
tree166aacb426f156147d5e8f7cc693c1b99e8c3861 /cloudinit/util.py
parent9d437489b8ce1f8cd9d34cd9ff4994ca18bd2d78 (diff)
downloadvyos-cloud-init-4bcc947301bedc5ebf430cfaf6e4597bfb174aa7.tar.gz
vyos-cloud-init-4bcc947301bedc5ebf430cfaf6e4597bfb174aa7.zip
Improve detection of snappy to include os-release and kernel cmdline.
Recent core snap images (edge channel revision 1886) do not contain the previously known files used to detect that a system is ubuntu core. The changes here are to look in 2 additional locations to determine if a system is snappy. LP: #1689944
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 27a98330..67ff7ba3 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -24,6 +24,7 @@ import platform
import pwd
import random
import re
+import shlex
import shutil
import socket
import stat
@@ -75,6 +76,7 @@ CONTAINER_TESTS = (['systemd-detect-virt', '--quiet', '--container'],
PROC_CMDLINE = None
_LSB_RELEASE = {}
+PY26 = sys.version_info[0:2] == (2, 6)
def get_architecture(target=None):
@@ -2424,6 +2426,18 @@ def system_is_snappy():
# channel.ini is configparser loadable.
# snappy will move to using /etc/system-image/config.d/*.ini
# this is certainly not a perfect test, but good enough for now.
+ orpath = "/etc/os-release"
+ try:
+ orinfo = load_shell_content(load_file(orpath, quiet=True))
+ if orinfo.get('ID', '').lower() == "ubuntu-core":
+ return True
+ except ValueError as e:
+ LOG.warning("Unexpected error loading '%s': %s", orpath, e)
+
+ cmdline = get_cmdline()
+ if 'snap_core=' in cmdline:
+ return True
+
content = load_file("/etc/system-image/channel.ini", quiet=True)
if 'ubuntu-core' in content.lower():
return True
@@ -2470,4 +2484,27 @@ def rootdev_from_cmdline(cmdline):
return "/dev/" + found
+def load_shell_content(content, add_empty=False, empty_val=None):
+ """Given shell like syntax (key=value\nkey2=value2\n) in content
+ return the data in dictionary form. If 'add_empty' is True
+ then add entries in to the returned dictionary for 'VAR='
+ variables. Set their value to empty_val."""
+
+ def _shlex_split(blob):
+ if PY26 and isinstance(blob, six.text_type):
+ # Older versions don't support unicode input
+ blob = blob.encode("utf8")
+ return shlex.split(blob)
+
+ data = {}
+ for line in _shlex_split(content):
+ key, value = line.split("=", 1)
+ if not value:
+ value = empty_val
+ if add_empty or value:
+ data[key] = value
+
+ return data
+
+
# vi: ts=4 expandtab