summaryrefslogtreecommitdiff
path: root/cloudinit/config/cc_mounts.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2014-09-30 16:24:54 -0400
committerScott Moser <smoser@ubuntu.com>2014-09-30 16:24:54 -0400
commit9736b260434af860c6ec81776f4278640f1fa9be (patch)
tree8c88e66b7d84a2bdd2fcda97ef5e19fde5aed431 /cloudinit/config/cc_mounts.py
parent9e645c06677ef146ab5dd36ce6e4be2329a1202b (diff)
downloadvyos-cloud-init-9736b260434af860c6ec81776f4278640f1fa9be.tar.gz
vyos-cloud-init-9736b260434af860c6ec81776f4278640f1fa9be.zip
support human2bytes, separate handling out to method
Diffstat (limited to 'cloudinit/config/cc_mounts.py')
-rw-r--r--cloudinit/config/cc_mounts.py43
1 files changed, 30 insertions, 13 deletions
diff --git a/cloudinit/config/cc_mounts.py b/cloudinit/config/cc_mounts.py
index 7af73c71..b9aa9a12 100644
--- a/cloudinit/config/cc_mounts.py
+++ b/cloudinit/config/cc_mounts.py
@@ -128,6 +128,7 @@ def setup_swapfile(fname, size=None, maxsize=None):
size: the size to create. set to "auto" for recommended
maxsize: the maximum size
"""
+ print("fname: %s, size: %s maxsize: %s" % (fname, size, maxsize))
tdir = os.path.dirname(fname)
if str(size).lower() == "auto":
try:
@@ -161,6 +162,32 @@ def setup_swapfile(fname, size=None, maxsize=None):
return fname, size
+def handle_swapcfg(swapcfg):
+ """handle the swap config, calling setup_swap if necessary.
+ return None or (filename, size)
+ """
+ fname = swapcfg.get('filename', '/swap.img')
+ size = swapcfg.get('size', 0)
+ maxsize = swapcfg.get('maxsize', 0)
+
+ if not (size and fname):
+ LOG.debug("no need to setup swap")
+ return
+
+ try:
+ if isinstance(size, str) and size != "auto":
+ size = util.human2bytes(size)
+ if isinstance(maxsize, str):
+ maxsize = util.human2bytes(maxsize)
+ return setup_swapfile(fname=fname, size=size, maxsize=maxsize)
+
+ except Exception as e:
+ LOG.warn("failed to setup swap: %s", e)
+
+ return None
+
+
+
def handle(_name, cfg, cloud, log, _args):
# fs_spec, fs_file, fs_vfstype, fs_mntops, fs-freq, fs_passno
defvals = [None, None, "auto", "defaults,nobootwait", "0", "2"]
@@ -248,19 +275,9 @@ def handle(_name, cfg, cloud, log, _args):
else:
actlist.append(x)
- swapcfg = cfg.get('swap', {})
- swapfile = swapcfg.get('filename', '/swap.img')
- if swapcfg.get('size') and swapfile:
- try:
- sret = setup_swapfile(fpath=swapfile,
- size=swapcfg.get('size'),
- maxsize=swapcfg.get('maxsize'))
- if sret is not None:
- actlist.append([sret[0], "none", "swap", "sw", "0", "0"])
- except Exception as e:
- log.warn("failed to setup swap: %s", e)
- else:
- log.debug("no swap to setup")
+ swapret = handle_swapcfg(cfg.get('swap'))
+ if swapret:
+ actlist.append([swapret[0], "none", "swap", "sw", "0", "0"])
if len(actlist) == 0:
log.debug("No modifications to fstab needed.")