diff options
author | Andrew Jorgensen <ajorgens@amazon.com> | 2017-06-16 18:17:36 +0000 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2017-07-11 13:33:02 -0400 |
commit | 4330a98161a5c514c7f85a76a58d057c85b00174 (patch) | |
tree | 2abde8be1f6f92db7c337961ed9abb9a95c8d453 /cloudinit | |
parent | a703c6a8b67bb56cb76bec65a67e62d344923ca8 (diff) | |
download | vyos-cloud-init-4330a98161a5c514c7f85a76a58d057c85b00174.tar.gz vyos-cloud-init-4330a98161a5c514c7f85a76a58d057c85b00174.zip |
write_files: Remove log from helper function signatures.
Instead of passing around a 'log' reference to functions, just import
logging and use that. This is the pattern that is now more common in
cloud-init.
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/config/cc_write_files.py | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/cloudinit/config/cc_write_files.py b/cloudinit/config/cc_write_files.py index 1835a31b..54ae3a68 100644 --- a/cloudinit/config/cc_write_files.py +++ b/cloudinit/config/cc_write_files.py @@ -50,6 +50,7 @@ import base64 import os import six +from cloudinit import log as logging from cloudinit.settings import PER_INSTANCE from cloudinit import util @@ -60,6 +61,8 @@ DEFAULT_OWNER = "root:root" DEFAULT_PERMS = 0o644 UNKNOWN_ENC = 'text/plain' +LOG = logging.getLogger(__name__) + def handle(name, cfg, _cloud, log, _args): files = cfg.get('write_files') @@ -67,10 +70,10 @@ def handle(name, cfg, _cloud, log, _args): log.debug(("Skipping module named %s," " no/empty 'write_files' key in configuration"), name) return - write_files(name, files, log) + write_files(name, files) -def canonicalize_extraction(encoding_type, log): +def canonicalize_extraction(encoding_type): if not encoding_type: encoding_type = '' encoding_type = encoding_type.lower().strip() @@ -85,31 +88,31 @@ def canonicalize_extraction(encoding_type, log): if encoding_type in ['b64', 'base64']: return ['application/base64'] if encoding_type: - log.warn("Unknown encoding type %s, assuming %s", - encoding_type, UNKNOWN_ENC) + LOG.warning("Unknown encoding type %s, assuming %s", + encoding_type, UNKNOWN_ENC) return [UNKNOWN_ENC] -def write_files(name, files, log): +def write_files(name, files): if not files: return for (i, f_info) in enumerate(files): path = f_info.get('path') if not path: - log.warn("No path provided to write for entry %s in module %s", - i + 1, name) + LOG.warning("No path provided to write for entry %s in module %s", + i + 1, name) continue path = os.path.abspath(path) - extractions = canonicalize_extraction(f_info.get('encoding'), log) + extractions = canonicalize_extraction(f_info.get('encoding')) contents = extract_contents(f_info.get('content', ''), extractions) (u, g) = util.extract_usergroup(f_info.get('owner', DEFAULT_OWNER)) - perms = decode_perms(f_info.get('permissions'), DEFAULT_PERMS, log) + perms = decode_perms(f_info.get('permissions'), DEFAULT_PERMS) util.write_file(path, contents, mode=perms) util.chownbyname(path, u, g) -def decode_perms(perm, default, log): +def decode_perms(perm, default): if perm is None: return default try: @@ -126,8 +129,8 @@ def decode_perms(perm, default, log): reps.append("%o" % r) except TypeError: reps.append("%r" % r) - log.warning( - "Undecodable permissions {0}, returning default {1}".format(*reps)) + LOG.warning( + "Undecodable permissions %s, returning default %s", *reps) return default |