
"·T`q  ã               @   s&  d  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
 Z
 d d l m Z e 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)$zERuncmd: run arbitrary commands at rc.local with output to the consoleé    )Úget_schema_docÚvalidate_cloudconfig_schema)ÚALL_DISTROS)ÚPER_INSTANCE)ÚutilN)ÚdedentÚidZ	cc_runcmdÚnameZRuncmdÚtitlezRun arbitrary commandsZdescriptiona¬          Run arbitrary commands at a rc.local like level with output to the
        console. Each item can be either a list or a string. If the item is a
        list, it will be properly executed as if passed to ``execve()`` (with
        the first arg as the command). If the item is a string, it will be
        written to a file and interpreted
        using ``sh``.

        .. note::

          all commands must be proper yaml, so you have to quote any characters
          yaml would eat (':' can be problematic)

        .. note::

          when writing files, do not use /tmp dir as it races with
          systemd-tmpfiles-clean LP: #1707222. Use /run/somedir instead.
    ÚdistrosZexamplesa          runcmd:
            - [ ls, -l, / ]
            - [ sh, -xc, "echo $(date) ': hello world!'" ]
            - [ sh, -c, echo "=========hello world'=========" ]
            - ls -l /root
            - [ wget, "http://example.org", -O, /tmp/index.html ]
    Z	frequencyÚtypeÚobjectZ
propertiesÚruncmdZarrayÚitemsZoneOfÚstringZadditionalItemsFZadditionalPropertiesZminItemsé   Zrequiredc             C   sª   d | k r  | j  d |  ƒ d  St | t ƒ t j j | j d ƒ d ƒ } | d } y& t j | ƒ } t j	 | | d ƒ Wn( t
 k
 r¥ t j | d | | ƒ Yn Xd  S)Nr   z:Skipping module named %s, no 'runcmd' key in configurationÚscriptsiÀ  z"Failed to shellify %s into file %s)Údebugr   ÚschemaÚosÚpathÚjoinZ	get_ipathr   ZshellifyZ
write_fileÚ	ExceptionZlogexc)r	   ZcfgZcloudÚlogZ_argsZout_fnÚcmdZcontent© r   ú</usr/lib/python3/dist-packages/cloudinit/config/cc_runcmd.pyÚhandleQ   s    	
r   )Ú__doc__Zcloudinit.config.schemar   r   Zcloudinit.distrosr   Zcloudinit.settingsr   Z	cloudinitr   r   Útextwrapr   r   r   r   r   r   r   r   Ú<module>	   s<   			