summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2012-07-11 17:00:21 -0400
committerScott Moser <smoser@ubuntu.com>2012-07-11 17:00:21 -0400
commite90670e879cdd102e91f6b4c1909992ceb89fc7e (patch)
tree7feecaaff16fa3c33a632392d8832636fa17f0f6 /cloudinit/util.py
parent3ad885991d355d1a97c7b197e471369d676715fa (diff)
parent50a5728db977ec11f3448c473a396995ea29319e (diff)
downloadvyos-cloud-init-e90670e879cdd102e91f6b4c1909992ceb89fc7e.tar.gz
vyos-cloud-init-e90670e879cdd102e91f6b4c1909992ceb89fc7e.zip
add write-files module for "injecting" files (LP: #1012854)
This implements file writing via cloud-config. It also * adjusts other code to have user/group parsing in util instead of in stages.py, * renames decomp_str to decomp_gzip since it is more meaningful when named that (as thats all it can decompress). LP: #1012854
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py29
1 files changed, 26 insertions, 3 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index e7a2ebcd..aaad2fb0 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -159,6 +159,10 @@ class MountFailedError(Exception):
pass
+class DecompressionError(Exception):
+ pass
+
+
def ExtendedTemporaryFile(**kwargs):
fh = tempfile.NamedTemporaryFile(**kwargs)
# Replace its unlink with a quiet version
@@ -256,13 +260,32 @@ def clean_filename(fn):
return fn
-def decomp_str(data):
+def decomp_gzip(data, quiet=True):
try:
buf = StringIO(str(data))
with contextlib.closing(gzip.GzipFile(None, "rb", 1, buf)) as gh:
return gh.read()
- except:
- return data
+ except Exception as e:
+ if quiet:
+ return data
+ else:
+ raise DecompressionError(str(e))
+
+
+def extract_usergroup(ug_pair):
+ if not ug_pair:
+ return (None, None)
+ ug_parted = ug_pair.split(':', 1)
+ u = ug_parted[0].strip()
+ if len(ug_parted) == 2:
+ g = ug_parted[1].strip()
+ else:
+ g = None
+ if not u or u == "-1" or u.lower() == "none":
+ u = None
+ if not g or g == "-1" or g.lower() == "none":
+ g = None
+ return (u, g)
def find_modules(root_dir):