o
    w7e                  
   @   s   U d Z ddl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 ee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 dedede
deddf
ddZdS )z:Bootcmd: run arbitrary commands early in the boot process.    N)dedent)subp
temp_utilsutil)Cloud)Config)
MetaSchemaget_meta_doc)
PER_ALWAYSall
cc_bootcmd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titledescriptiondistrosexamples	frequencyactivate_by_schema_keysmetar   cfgcloudargsreturnc           
      C   s  d|vrt d|  d S tjdde}zt|d }|t| |  W n t	y> } z
t
t dt|  d }~ww z tj }| }|rQt||d< d|jg}	tj|	|dd	 W n t	yn   t
t d
|   w W d    d S 1 szw   Y  d S )Nr   z;Skipping module named %s, no 'bootcmd' key in configurationz.sh)suffixzFailed to shellify bootcmd: %sINSTANCE_IDz/bin/shF)envcapturezFailed to run bootcmd module %s)LOGdebugr   ExtendedTemporaryFiler   shellifywriteencode_textflush	Exceptionlogexcstrosenvironcopyget_instance_idr   r   )
r   r   r   r   tmpfcontenter   iidcmd r3   =/usr/lib/python3/dist-packages/cloudinit/config/cc_bootcmd.pyhandleD   s8   

"r5   )__doc__loggingr*   textwrapr   	cloudinitr   r   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   r	   cloudinit.settingsr
   	getLogger__name__r    r   r   r   __annotations__r)   listr5   r3   r3   r3   r4   <module>   s8   	
	%"