
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
\¼meŽ  ã            	   @   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jeƒZeeƒZ dZeee	eddœ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.
Z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ÚdescriptionZdistrosÚ	frequencyZexamplesZactivate_by_schema_keyszy## template: jinja
Cloud-init v. {{version}} finished at {{timestamp}}. Datasource {{datasource}}.  Up {{uptime}} seconds)r   ÚcfgÚcloudÚargsÚreturnc             C   s0  d}t |ƒdkrt|d ƒ}ntj|ddƒ}|jƒ }|s<t}tjƒ }tjƒ }tj	ƒ }yR|||t|j
ƒdœ}|jtdd„ |jƒ D ƒƒƒ tjdtj||ƒ dd	td
� W n  tk
rÆ   tjtdƒ Y nX |jj}	y"d|||f }
tj|	|
dd� W n$ tk
�r   tjtd|	ƒ Y nX |j
j�r,tjdƒ d S )NÚ r   Zfinal_message)ÚuptimeZ	timestampr   Ú
datasourcec             S   s   g | ]\}}|j ƒ |f‘qS © )Úupper)Ú.0ÚkÚvr   r   ú&/usr/lib/python3.6/cc_final_message.pyú
<listcomp>\   s    zhandle.<locals>.<listcomp>z%s
FT)ZconsoleÚstderrÚlogz'Failed to render final message templatez%s - %s - v. %s
)Zensure_dir_existsz%Failed to write boot finished file %szUsed fallback datasource)ÚlenÚstrr   Zget_cfg_option_strÚstripÚFINAL_MESSAGE_DEFr   Ztime_rfc2822r   Zversion_stringr   ÚupdateÚdictÚitemsZ	multi_logr   Zrender_stringÚLOGÚ	ExceptionZlogexcÚpathsZboot_finishedZ
write_fileZis_disconnectedZwarning)r   r   r   r   Zmsg_inr   ZtsZcverZsubsZboot_fin_fnÚcontentsr   r   r   ÚhandleF   s>    
r,   )Ú__doc__ZloggingÚtextwrapr   Z	cloudinitr   r   r   Zcloudinit.cloudr   Zcloudinit.configr   Zcloudinit.config.schemar   r	   Zcloudinit.distrosr
   Zcloudinit.settingsr   ZMODULE_DESCRIPTIONr   ÚmetaZ	getLoggerÚ__name__r(   r$   r"   Úlistr,   r   r   r   r   Ú<module>   s.   
