Your IP : 216.73.217.13


Current Path : /lib/python3/dist-packages/cloudinit/cmd/devel/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/cloudinit/cmd/devel/__pycache__/render.cpython-38.pyc

U

�Ad�@s�dZddlZddlZddlZddlmZddlmZmZddl	m
Z
mZmZdZ
e�e
�Zddd�Zdd
d�Zdd
�Zedkr�e�ee
e�����dS)z,Debug jinja template rendering of user-data.�N)�log)�addLogHandlerCLI�read_cfg_paths)�JinjaLoadError�
NotJinjaError�render_jinja_payload_from_fileZrendercCsL|stjttd�}|jdtdd�|jddtdd�|jdd	d
ddd
�|S)aBuild or extend and arg parser for jinja render utility.

    @param parser: Optional existing ArgumentParser instance representing the
        subcommand which will be extended to support the args of this utility.

    @returns: ArgumentParser with proper argument configuration.
    )�progZdescription�	user_dataz$Path to the user-data file to render)�type�helpz-iz--instance-datazXOptional path to instance-data.json file. Defaults to /run/cloud-init/instance-data.jsonz-dz--debug�
store_trueFz+Add verbose messages during template render)�action�defaultr)�argparse�ArgumentParser�NAME�__doc__�add_argument�str)�parser�r�</usr/lib/python3/dist-packages/cloudinit/cmd/devel/render.py�
get_parsers*��	�rFc
CsPtt|rtjntj�|r |}nNt�}t��}|�d�}|dkrj|�d�}tj	�
|�snt�d||�|}n|}tj	�
|�s�t�d|�dSz t
|��}|��}W5QRXWn"tk
r�t�d|�YdSXzt||||r�dnd	d
�}	Wn>ttfk
�r(}
zt�dt|
��WY�dSd}
~
XYnX|	�s@t�d
|�dStj�|	�dS)z�Render the provided user-data template file using instance-data values.

    Also setup CLI log handlers to report to stderr since this is a development
    utility which should be run by a human on the CLI.

    @return 0 on success, 1 on failure.
    �
instance_datarZinstance_data_sensitivez4Missing root-readable %s. Using redacted %s instead.z#Missing instance-data.json file: %s�zMissing user-data file: %sTF)ZpayloadZ
payload_fnZinstance_data_file�debugz5Cannot render from instance data due to exception: %sNz#Unable to render user-data file: %s)r�LOGr�DEBUGZWARNINGr�os�getuidZget_runpath�path�existsZwarning�error�open�read�IOErrorrrr�repr�sys�stdout�write)Zuser_data_pathZinstance_data_pathrZinstance_data_fn�pathsZuidZredacted_data_fn�streamr	Zrendered_payload�errr�render_template8sV

�

�
�r-cCst|j|j|j�S)N)r-r	rr)�_name�argsrrr�handle_argsnsr0�__main__)N)NF)rrrr'Z	cloudinitrZcloudinit.cmd.develrrZ!cloudinit.handlers.jinja_templaterrrrZ	getLoggerrrr-r0�__name__�exit�
parse_argsrrrr�<module>s

 
6