o
    w7e                  
   @   s   U d Z ddlZddlmZ ddlmZmZmZ ddlm	Z	 ddl
mZ ddlmZmZ ddlmZ dd	lmZ d
ZeZdddeegeedgg dZeed< eeZeeZ dZdedede	deddf
ddZdS )z@Final Message: Output final message when cloud-init has finished    N)dedent)	templaterutilversion)Cloud)Config)
MetaSchemaget_meta_doc)ALL_DISTROS)
PER_ALWAYSa  This 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.
cc_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
            )idnametitledescriptiondistros	frequencyexamplesactivate_by_schema_keysmetazy## template: jinja
Cloud-init v. {{version}} finished at {{timestamp}}. Datasource {{datasource}}.  Up {{uptime}} secondsr   cfgcloudargsreturnc                 C   s,  d}t |dkrt|d }nt|dd}| }|st}t }t }t	 }z)|||t|j
d}|tdd | D  tjdt|| dd	td
 W n tyb   ttd Y nw |jj}	zd|||f }
tj|	|
dd W n ty   ttd|	 Y nw |j
jrtd d S d S )N r   final_message)uptime	timestampr   
datasourcec                 S   s   g | ]
\}}|  |fqS  )upper).0kvr   r   C/usr/lib/python3/dist-packages/cloudinit/config/cc_final_message.py
<listcomp>\   s    zhandle.<locals>.<listcomp>z%s
FT)consolestderrlogz'Failed to render final message templatez%s - %s - v. %s
)ensure_dir_existsz%Failed to write boot finished file %szUsed fallback datasource)lenstrr   get_cfg_option_strstripFINAL_MESSAGE_DEFr   time_rfc2822r   version_stringr   updatedictitems	multi_logr   render_stringLOG	Exceptionlogexcpathsboot_finished
write_fileis_disconnectedwarning)r   r   r   r   msg_inr   tscversubsboot_fin_fncontentsr   r   r$   handleF   sH   
rD   )__doc__loggingtextwrapr   	cloudinitr   r   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   r	   cloudinit.distrosr
   cloudinit.settingsr   MODULE_DESCRIPTIONr   r   __annotations__	getLogger__name__r6   r.   r+   listrD   r   r   r   r$   <module>   s8   
"