
"T`                 @   s<  d  Z  d d l Z d d l m Z d d l m Z m Z d d l m Z d d l	 m
 Z
 d d l	 m Z d d l	 m Z e Z d	 g Z d
 d d d d d d e d  d e d e d  g d e d d d d d d d d d d d d d i i d d i g i d d d  d d! d" d# g  i i i	 Z e e  Z  d$ d%   Z d S)&z:Bootcmd: run arbitrary commands early in the boot process.    N)dedent)get_schema_docvalidate_cloudconfig_schema)
PER_ALWAYS)
temp_utils)subp)utilallidZ
cc_bootcmdnameZBootcmdtitlez0Run arbitrary commands early in the boot processZdescriptiona          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.
    distrosZexamplesz        bootcmd:
            - echo 192.168.1.130 us.archive.ubuntu.com > /etc/hosts
            - [ cloud-init-per, once, mymkfs, mkfs, /dev/vdb ]
    	frequencytypeobjectZ
propertiesbootcmdZarrayitemsZoneOfstringZadditionalItemsFZadditionalPropertiesZminItems   Zrequiredc          !   C   sP  d | k r  | j  d |   d  St | t  t j d d  
} y7 t j | d  } | j t j |   | j	   WnA t
 k
 r } z! t j | d t |     WYd  d  } ~ Xn Xy] t j j   } | j   }	 |	 r t |	  | d <d | j g }
 t j |
 d | d	 d
 Wn( t
 k
 rDt j | d |     Yn XWd  QRXd  S)Nr   z;Skipping module named %s, no 'bootcmd' key in configurationsuffixz.shzFailed to shellify bootcmd: %sZINSTANCE_IDz/bin/shenvZcaptureFzFailed to run bootcmd module %s)debugr   schemar   ZExtendedTemporaryFiler   ZshellifywriteZencode_textflush	ExceptionZlogexcstrosenvironcopyZget_instance_idr   r   )r   ZcfgZcloudlogZ_argsZtmpfZcontenter   Ziidcmd r#   =/usr/lib/python3/dist-packages/cloudinit/config/cc_bootcmd.pyhandleP   s.    	r%   )__doc__r   textwrapr   Zcloudinit.config.schemar   r   Zcloudinit.settingsr   Z	cloudinitr   r   r   r   r   r   r%   r#   r#   r#   r$   <module>
   s@   		