summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorEduardo Otubo <otubo@redhat.com>2020-08-18 23:12:02 +0200
committerGitHub <noreply@github.com>2020-08-18 15:12:02 -0600
commitb749548a9eb43b34cce64f8688107645411abc8c (patch)
tree9e8d5c68d9c027f4d6008cd3c755cafda913887b /cloudinit/util.py
parenta4b6b96f30bdd994ab535b222cf4b4bf09f20668 (diff)
downloadvyos-cloud-init-b749548a9eb43b34cce64f8688107645411abc8c.tar.gz
vyos-cloud-init-b749548a9eb43b34cce64f8688107645411abc8c.zip
Detect kernel version before swap file creation (#428)
According to man page `man 8 swapon', "Preallocated swap files are supported on XFS since Linux 4.18". This patch checks for kernel version before attepting to create swapfile, using dd for XFS only on kernel versions <= 4.18 or btrfs. Add new func util.kernel_version which returns a tuple of ints (major, minor) Signed-off-by: Eduardo Otubo otubo@redhat.com
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 624c560d..edd37039 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -68,6 +68,10 @@ CONTAINER_TESTS = (['systemd-detect-virt', '--quiet', '--container'],
['lxc-is-container'])
+def kernel_version():
+ return tuple(map(int, os.uname().release.split('.')[:2]))
+
+
@lru_cache()
def get_dpkg_architecture(target=None):
"""Return the sanitized string output by `dpkg --print-architecture`.