U
    Ad|                  	   @   s   U d Z ddlZddlm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 eZd
gZdddedeedgedgdZeed< eeZ eeeeeddddZdS )z:Bootcmd: run arbitrary commands early in the boot process.    N)Logger)dedent)subp
temp_utilsutil)Cloud)Config)
MetaSchemaget_meta_doc)
PER_ALWAYSallZ
cc_bootcmdZBootcmdz0Run arbitrary commands early in the boot processa          This module runs arbitrary commands very early in the boot process,
        only slightly after a boothook would run. This is very similar to a
        boothook, but more user friendly. The environment variable
        ``INSTANCE_ID`` will be set to the current instance id for all run
        commands. Commands can be specified either as lists or strings. For
        invocation details, see ``runcmd``.

        .. note::
            bootcmd should only be used for things that could not be done later
            in the boot process.

        .. note::

          when writing files, do not use /tmp dir as it races with
          systemd-tmpfiles-clean LP: #1707222. Use /run/somedir instead.
    z        bootcmd:
            - echo 192.168.1.130 us.archive.ubuntu.com > /etc/hosts
            - [ cloud-init-per, once, mymkfs, mkfs, /dev/vdb ]
    bootcmd)idnametitleZdescriptiondistrosZexamples	frequencyZactivate_by_schema_keysmeta)r   cfgcloudlogargsreturnc                 C   s   d|kr| d|  d S tjdd}z*t|d }|t| |  W n6 tk
r } zt	|dt
|  W 5 d }~X Y nX z@tj }| }	|	rt
|	|d< d|jg}
tj|
|dd	 W n$ tk
r   t	|d
|   Y nX W 5 Q R X d S )Nr   z;Skipping module named %s, no 'bootcmd' key in configurationz.sh)suffixzFailed to shellify bootcmd: %sZINSTANCE_IDz/bin/shF)envZcapturezFailed to run bootcmd module %s)debugr   ZExtendedTemporaryFiler   ZshellifywriteZencode_textflush	ExceptionZlogexcstrosenvironcopyZget_instance_idr   r   )r   r   r   r   r   ZtmpfZcontenter   Ziidcmd r%   =/usr/lib/python3/dist-packages/cloudinit/config/cc_bootcmd.pyhandleB   s0     

r'   )__doc__r    Zloggingr   textwrapr   Z	cloudinitr   r   r   Zcloudinit.cloudr   Zcloudinit.configr   Zcloudinit.config.schemar	   r
   Zcloudinit.settingsr   r   r   r   __annotations__r   listr'   r%   r%   r%   r&   <module>
   s@   	%    