1. Move the welcome message template string to a constant at the top of the module
2. Fix the usage of multi_log to log to only one of the places (for now) 3. Update comment about multi-log and why write_file isn't used in this case
This commit is contained in:
parent
3cee0d84e9
commit
2d96020385
@ -45,6 +45,10 @@ from cloudinit.settings import (PER_INSTANCE, PER_ALWAYS, PER_ONCE,
|
|||||||
CLOUD_CONFIG)
|
CLOUD_CONFIG)
|
||||||
|
|
||||||
|
|
||||||
|
# Pretty little welcome message template
|
||||||
|
WELCOME_MSG_TPL = ("Cloud-init v. {{version}} running '{{action}}' at "
|
||||||
|
"{{timestamp}}. Up {{uptime}} seconds.")
|
||||||
|
|
||||||
# Module section template
|
# Module section template
|
||||||
MOD_SECTION_TPL = "cloud_%s_modules"
|
MOD_SECTION_TPL = "cloud_%s_modules"
|
||||||
|
|
||||||
@ -56,6 +60,7 @@ QUERY_DATA_TYPES = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
# Frequency shortname to full name
|
# Frequency shortname to full name
|
||||||
|
# (so users don't have to remember the full name...)
|
||||||
FREQ_SHORT_NAMES = {
|
FREQ_SHORT_NAMES = {
|
||||||
'instance': PER_INSTANCE,
|
'instance': PER_INSTANCE,
|
||||||
'always': PER_ALWAYS,
|
'always': PER_ALWAYS,
|
||||||
@ -78,15 +83,15 @@ def print_exc(msg=''):
|
|||||||
|
|
||||||
|
|
||||||
def welcome(action):
|
def welcome(action):
|
||||||
msg = ("Cloud-init v. {{version}} running '{{action}}' at "
|
|
||||||
"{{timestamp}}. Up {{uptime}} seconds.")
|
|
||||||
tpl_params = {
|
tpl_params = {
|
||||||
'version': version.version_string(),
|
'version': version.version_string(),
|
||||||
'uptime': util.uptime(),
|
'uptime': util.uptime(),
|
||||||
'timestamp': util.time_rfc2822(),
|
'timestamp': util.time_rfc2822(),
|
||||||
'action': action,
|
'action': action,
|
||||||
}
|
}
|
||||||
util.multi_log("%s\n" % (templater.render_string(msg, tpl_params)))
|
tpl_msg = templater.render_string(WELCOME_MSG_TPL, tpl_params)
|
||||||
|
util.multi_log("%s\n" % (tpl_msg),
|
||||||
|
console=False, stderr=True)
|
||||||
|
|
||||||
|
|
||||||
def extract_fns(args):
|
def extract_fns(args):
|
||||||
|
@ -55,7 +55,8 @@ def handle(_name, cfg, cloud, log, args):
|
|||||||
'timestamp': ts,
|
'timestamp': ts,
|
||||||
'version': cver,
|
'version': cver,
|
||||||
}
|
}
|
||||||
util.multi_log("%s\n" % (templater.render_string(msg_in, subs)))
|
util.multi_log("%s\n" % (templater.render_string(msg_in, subs)),
|
||||||
|
console=False, stderr=True)
|
||||||
except Exception:
|
except Exception:
|
||||||
util.logexc(log, "Failed to render final message template")
|
util.logexc(log, "Failed to render final message template")
|
||||||
|
|
||||||
|
@ -46,7 +46,8 @@ def handle(name, cfg, _cloud, log, _args):
|
|||||||
cmd.append(','.join(fp_blacklist))
|
cmd.append(','.join(fp_blacklist))
|
||||||
cmd.append(','.join(key_blacklist))
|
cmd.append(','.join(key_blacklist))
|
||||||
(stdout, _stderr) = util.subp(cmd)
|
(stdout, _stderr) = util.subp(cmd)
|
||||||
util.multi_log("%s\n" % (stdout.strip()), stderr=False)
|
util.multi_log("%s\n" % (stdout.strip()),
|
||||||
|
stderr=False, console=True)
|
||||||
except:
|
except:
|
||||||
log.warn("Writing keys to the system console failed!")
|
log.warn("Writing keys to the system console failed!")
|
||||||
raise
|
raise
|
||||||
|
@ -275,15 +275,18 @@ def find_modules(root_dir):
|
|||||||
return entries
|
return entries
|
||||||
|
|
||||||
|
|
||||||
def multi_log(text, console=True, stderr=True, log=None):
|
def multi_log(text, console=True, stderr=True,
|
||||||
|
log=None, log_level=logging.DEBUG):
|
||||||
if stderr:
|
if stderr:
|
||||||
sys.stderr.write(text)
|
sys.stderr.write(text)
|
||||||
if console:
|
if console:
|
||||||
|
# Don't use the write_file since
|
||||||
|
# this might be 'sensitive' info (not debug worthy?)
|
||||||
with open('/dev/console', 'wb') as wfh:
|
with open('/dev/console', 'wb') as wfh:
|
||||||
wfh.write(text)
|
wfh.write(text)
|
||||||
wfh.flush()
|
wfh.flush()
|
||||||
if log:
|
if log:
|
||||||
log.debug(text)
|
log.log(log_level, text)
|
||||||
|
|
||||||
|
|
||||||
def is_ipv4(instr):
|
def is_ipv4(instr):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user