3 \�me� � @ s� U d Z ddlZddlmZ ddlmZmZmZ ddlm Z ddl mZ ddlm Z mZ ddlmZ dd lmZ d ZeZddd eegeed�gg d�Ze eje�Zee�Z dZeee edd�dd�ZdS )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. 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 )�id�name�title�descriptionZdistros� frequencyZexamplesZactivate_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 |�dkrt|d �}ntj|dd�}|j� }|s<t}tj� }tj� }tj � }yR|||t|j �d�}|jtdd� |j � D ��� tjdtj||� dd td � W n tk r� tjtd� Y nX |jj} y"d|||f } tj| | dd � W n$ tk �r tjtd| � Y nX |j j�r,tjd� d S )N� r Z final_message)�uptimeZ timestampr � datasourcec S s g | ]\}}|j � |f�qS � )�upper)�.0�k�vr r �&/usr/lib/python3.6/cc_final_message.py� <listcomp>\ s zhandle.<locals>.<listcomp>z%s FT)Zconsole�stderr�logz'Failed to render final message templatez%s - %s - v. %s )Zensure_dir_existsz%Failed to write boot finished file %szUsed fallback datasource)�len�strr Zget_cfg_option_str�strip�FINAL_MESSAGE_DEFr Ztime_rfc2822r Zversion_stringr �update�dict�itemsZ multi_logr Z render_string�LOG� ExceptionZlogexc�pathsZ boot_finishedZ write_fileZis_disconnectedZwarning)r r r r Zmsg_inr ZtsZcverZsubsZboot_fin_fn�contentsr r r �handleF s>