diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-07-10 17:06:45 -0700 |
---|---|---|
committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-07-10 17:06:45 -0700 |
commit | 7b24230437a27779bafa0828e73ab595c5aeb202 (patch) | |
tree | 1e0da0898e4361aefec5ba72dd6e346f008e095e /cloudinit/util.py | |
parent | 86f0d708564ab210f2f58f3e76f94a4af56e360b (diff) | |
download | vyos-cloud-init-7b24230437a27779bafa0828e73ab595c5aeb202.tar.gz vyos-cloud-init-7b24230437a27779bafa0828e73ab595c5aeb202.zip |
Fixes 1012854 by implementing file writing, 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).
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r-- | cloudinit/util.py | 29 |
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): |