diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-11-13 08:54:35 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2012-11-13 08:54:35 -0500 |
commit | c26b0674aa2ef31c7c3f7a0392044382cf6a452f (patch) | |
tree | b049de27577d6fe2400ef52649e6066c700f8c1c /cloudinit/util.py | |
parent | 8d5e1e108b0cdd3af872383da7654bec91355b5f (diff) | |
parent | cd8fbfffdf7ba9ba79d39ee7b4a223d1bd7863b4 (diff) | |
download | vyos-cloud-init-c26b0674aa2ef31c7c3f7a0392044382cf6a452f.tar.gz vyos-cloud-init-c26b0674aa2ef31c7c3f7a0392044382cf6a452f.zip |
Use a set of helper/parsing classes to perform system configuration
Previously file modification of system configuration was done
in a functional and hard to test manner. Now instead this patch
allows for a manner that provides a nice object oriented
interface to those objects as well as makes it possible to test
those parsing entities without having to invoke distro class code.
- Created parsers for:
- /etc/sysconfig
- /etc/hostname
- resolv.conf
- /etc/hosts
Moved duplicated functionality into the root level distro class including:
- apply_hostname
- set_hostname
- *various shared configuration file names/paths*
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r-- | cloudinit/util.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py index 4f5b15ee..ab918433 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -52,6 +52,7 @@ from cloudinit import importer from cloudinit import log as logging from cloudinit import safeyaml from cloudinit import url_helper as uhelp +from cloudinit import version from cloudinit.settings import (CFG_BUILTIN) @@ -272,11 +273,7 @@ def uniq_merge(*lists): # Kickout the empty ones a_list = [a for a in a_list if len(a)] combined_list.extend(a_list) - uniq_list = [] - for i in combined_list: - if i not in uniq_list: - uniq_list.append(i) - return uniq_list + return uniq_list(combined_list) def clean_filename(fn): @@ -989,6 +986,16 @@ def peek_file(fname, max_bytes): return ifh.read(max_bytes) +def uniq_list(in_list): + out_list = [] + for i in in_list: + if i in out_list: + continue + else: + out_list.append(i) + return out_list + + def load_file(fname, read_cb=None, quiet=False): LOG.debug("Reading from %s (quiet=%s)", fname, quiet) ofh = StringIO() @@ -1428,6 +1435,14 @@ def subp(args, data=None, rcs=None, env=None, capture=True, shell=False, return (out, err) +def make_header(comment_char="#", base='created'): + ci_ver = version.version_string() + header = str(comment_char) + header += " %s by cloud-init v. %s" % (base.title(), ci_ver) + header += " on %s" % time_rfc2822() + return header + + def abs_join(*paths): return os.path.abspath(os.path.join(*paths)) |