3
# Copyright (C) 2011 Canonical Ltd.
4
# Copyright (C) 2012 Hewlett-Packard Development Company, L.P.
6
# Author: Scott Moser <scott.moser@canonical.com>
7
# Author: Juerg Haefliger <juerg.haefliger@hp.com>
9
# This program is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU General Public License version 3, as
11
# published by the Free Software Foundation.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
from cloudinit import templater
22
from cloudinit import util
23
from cloudinit import version
25
from cloudinit.settings import PER_ALWAYS
27
frequency = PER_ALWAYS
29
# Jinja formated default message
31
"## template: jinja\n"
32
"Cloud-init v. {{version}} finished at {{timestamp}}."
33
" Datasource {{datasource}}. Up {{uptime}} seconds"
37
def handle(_name, cfg, cloud, log, args):
43
msg_in = util.get_cfg_option_str(cfg, "final_message", "")
45
msg_in = msg_in.strip()
47
msg_in = FINAL_MESSAGE_DEF
49
uptime = util.uptime()
50
ts = util.time_rfc2822()
51
cver = version.version_string()
57
'datasource': str(cloud.datasource),
59
subs.update(dict([(k.upper(), v) for k, v in subs.items()]))
60
util.multi_log("%s\n" % (templater.render_string(msg_in, subs)),
61
console=False, stderr=True, log=log)
63
util.logexc(log, "Failed to render final message template")
65
boot_fin_fn = cloud.paths.boot_finished
67
contents = "%s - %s - v. %s\n" % (uptime, ts, cver)
68
util.write_file(boot_fin_fn, contents)
70
util.logexc(log, "Failed to write boot finished file %s", boot_fin_fn)
72
if cloud.datasource.is_disconnected:
73
log.warn("Used fallback datasource")