summaryrefslogtreecommitdiff
path: root/cloudinit/CloudConfig.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2010-03-04 16:47:17 -0500
committerScott Moser <smoser@ubuntu.com>2010-03-04 16:47:17 -0500
commitee291edfccd67e97f2f8f4129168279e5f0499b3 (patch)
treef52557f65bfd736f43997b8b3a812c63653e5aa7 /cloudinit/CloudConfig.py
parent10d99782809706eb0edbaf5d619c4182d3a26065 (diff)
downloadvyos-cloud-init-ee291edfccd67e97f2f8f4129168279e5f0499b3.tar.gz
vyos-cloud-init-ee291edfccd67e97f2f8f4129168279e5f0499b3.zip
replace 'cloudconfig' entries in fstab rather than appending (LP: #524562)
This marks the comment option of fs_mntops in fstab (man fstab) with cloudconfig for each of the mount options added by cloudconfig. It will search through existing lines, any entry written by cloudconfig will be deleted. LP: #524562
Diffstat (limited to 'cloudinit/CloudConfig.py')
-rw-r--r--cloudinit/CloudConfig.py28
1 files changed, 24 insertions, 4 deletions
diff --git a/cloudinit/CloudConfig.py b/cloudinit/CloudConfig.py
index 9eb2d00b..487e9872 100644
--- a/cloudinit/CloudConfig.py
+++ b/cloudinit/CloudConfig.py
@@ -26,6 +26,8 @@ import os
import glob
import sys
import time
+import re
+import string
per_instance="once-per-instance"
cronpre = "/etc/cron.d/cloudinit"
@@ -344,15 +346,33 @@ class CloudConfig():
if len(actlist) == 0: return
+ comment="comment=cloudconfig"
+ cc_lines = [ ]
needswap = False
dirs = [ ]
-
- fstab=file("/etc/fstab","ab")
- fstab.write("# cloud-config mounts\n")
for line in actlist:
- fstab.write('\t'.join(line) + "\n")
+ # write 'comment' in the fs_mntops, entry, claiming this
+ line[3]="%s,comment=cloudconfig" % line[3]
if line[2] == "swap": needswap = True
if line[1].startswith("/"): dirs.append(line[1])
+ cc_lines.append('\t'.join(line))
+
+ fstab_lines = [ ]
+ fstab=open("/etc/fstab","r+")
+ ws = re.compile("[%s]+" % string.whitespace)
+ for line in fstab.read().splitlines():
+ try:
+ toks = ws.split(line)
+ if toks[3].find(comment) != -1: continue
+ except:
+ pass
+ fstab_lines.append(line)
+
+ fstab_lines.extend(cc_lines)
+
+ fstab.seek(0)
+ fstab.write("%s\n" % '\n'.join(fstab_lines))
+ fstab.truncate()
fstab.close()
if needswap: