3 \me @sUdZddlZddlmZddlmZmZmZddlm Z ddl m Z ddl m Z mZddlmZdd lmZd ZeZd d d eegeedggdZe ejeZeeZdZee e eddddZdS)z@Final Message: Output final message when cloud-init has finishedN)dedent) templaterutilversion)Cloud)Config) MetaSchema get_meta_doc) ALL_DISTROS) PER_ALWAYSaThis module configures the final message that cloud-init writes. The message is specified as a jinja template with the following variables set: - ``version``: cloud-init version - ``timestamp``: time at cloud-init finish - ``datasource``: cloud-init data source - ``uptime``: system uptime This message is written to the cloud-init log (usually /var/log/cloud-init.log) as well as stderr (which usually redirects to /var/log/cloud-init-output.log). Upon exit, this module writes the system uptime, timestamp, and cloud-init version to ``/var/lib/cloud/instance/boot-finished`` independent of any user data specified for this module. Zcc_final_messagez Final Messagez1Output final message when cloud-init has finishedz final_message: | cloud-init has finished version: $version timestamp: $timestamp datasource: $datasource uptime: $uptime )idnametitle descriptionZdistros frequencyZexamplesZactivate_by_schema_keyszy## template: jinja Cloud-init v. {{version}} finished at {{timestamp}}. Datasource {{datasource}}. Up {{uptime}} seconds)r cfgcloudargsreturnc Cs0d}t|dkrt|d}ntj|dd}|j}|s\szhandle..z%s FT)Zconsolestderrlogz'Failed to render final message templatez%s - %s - v. %s )Zensure_dir_existsz%Failed to write boot finished file %szUsed fallback datasource)lenstrrZget_cfg_option_strstripFINAL_MESSAGE_DEFrZ time_rfc2822rZversion_stringrupdatedictitemsZ multi_logrZ render_stringLOG ExceptionZlogexcpathsZ boot_finishedZ write_fileZis_disconnectedZwarning) r rrrZmsg_inrZtsZcverZsubsZ boot_fin_fncontentsrrrhandleFs>   r,)__doc__ZloggingtextwraprZ cloudinitrrrZcloudinit.cloudrZcloudinit.configrZcloudinit.config.schemarr Zcloudinit.distrosr Zcloudinit.settingsr ZMODULE_DESCRIPTIONrmetaZ getLogger__name__r(r$r"listr,rrrrs.