Current File : //lib/python2.7/site-packages/cloudinit/config/cc_write_files.pyc
�
oB�]c@s�dZddlZddlZddlZddlmZddlmZddlm	Z	eZ
dZdZdZ
eje�Zd	�Zd
�Zd�Zd�Zd
�ZdS(sW
Write Files
-----------
**Summary:** write arbitrary files

Write out arbitrary content to files, optionally setting permissions. Content
can be specified in plain text or binary. Data encoded with either base64 or
binary gzip data can be specified and will be decoded before being written.

.. note::
    if multiline data is provided, care should be taken to ensure that it
    follows yaml formatting standards. to specify binary data, use the yaml
    option ``!!binary``

.. note::
    Do not write files under /tmp during boot because of a race with
    systemd-tmpfiles-clean that can cause temp files to get cleaned during
    the early boot process. Use /run/somedir instead to avoid race LP:1707222.

**Internal name:** ``cc_write_files``

**Module frequency:** per instance

**Supported distros:** all

**Config keys**::

    write_files:
        - encoding: b64
          content: CiMgVGhpcyBmaWxlIGNvbnRyb2xzIHRoZSBzdGF0ZSBvZiBTRUxpbnV4...
          owner: root:root
          path: /etc/sysconfig/selinux
          permissions: '0644'
        - content: |
            # My new /etc/sysconfig/samba file

            SMDBOPTIONS="-D"
          path: /etc/sysconfig/samba
        - content: !!binary |
            f0VMRgIBAQAAAAAAAAAAAAIAPgABAAAAwARAAAAAAABAAAAAAAAAAJAVAAAAAA
            AEAAHgAdAAYAAAAFAAAAQAAAAAAAAABAAEAAAAAAAEAAQAAAAAAAwAEAAAAAAA
            AAAAAAAAAwAAAAQAAAAAAgAAAAAAAAACQAAAAAAAAAJAAAAAAAAcAAAAAAAAAB
            ...
          path: /bin/arch
          permissions: '0555'
        - content: |
            15 * * * * root ship_logs
          path: /etc/crontab
          append: true
i����N(tlog(tPER_INSTANCE(tutils	root:rooti�s
text/plaincCs:|jd�}|s)|jd|�dSt||�dS(Ntwrite_filessESkipping module named %s, no/empty 'write_files' key in configuration(tgettdebugR(tnametcfgt_cloudRt_argstfiles((sC/usr/lib/python2.7/site-packages/cloudinit/config/cc_write_files.pythandleLs	cCs�|sd}n|j�j�}|d
kr4dgS|dkrJd	dgS|dkr]d	gS|rytjd|t�ntgS(Nttgztgzipsapplication/x-gzips	gz+base64sgzip+base64sgz+b64sgzip+b64sapplication/base64tb64tbase64s%Unknown encoding type %s, assuming %s(R
R(s	gz+base64sgzip+base64sgz+b64sgzip+b64(Rsbase64(tlowertstriptLOGtwarningtUNKNOWN_ENC(t
encoding_type((sC/usr/lib/python2.7/site-packages/cloudinit/config/cc_write_files.pytcanonicalize_extractionUs	
	
cCs%|s
dSxt|�D]\}}|jd�}|sUtjd|d|�qntjj|�}t|jd��}t|jdd�|�}t	j
|jdt��\}}t|jd�t
�}	t	j|d	�r�d
nd}
t	j||d|
d
|	�t	j|||�qWdS(Ntpaths3No path provided to write for entry %s in module %sitencodingtcontentRtownertpermissionstappendtabtwbtomodetmode(t	enumerateRRRtosRtabspathRtextract_contentsRtextract_usergroupt
DEFAULT_OWNERtdecode_permst
DEFAULT_PERMStget_cfg_option_boolt
write_filetchownbyname(RR
titf_infoRtextractionstcontentstutgtpermsR ((sC/usr/lib/python2.7/site-packages/cloudinit/config/cc_write_files.pyRis 	!cCs�|dkr|Sy:t|tjtf�r6t|�Stt|�d�SWnttfk
r�g}xN||fD]@}y|j	d|�Wqstk
r�|j	d|�qsXqsWt
jd|�|SXdS(Nis%os%rs0Undecodable permissions %s, returning default %s(tNonet
isinstancetsixt
integer_typestfloattinttstrt	TypeErrort
ValueErrorRRR(tpermtdefaulttrepstr((sC/usr/lib/python2.7/site-packages/cloudinit/config/cc_write_files.pyR(}s 


cCsr|}xe|D]]}|dkr=tj|dtdt�}q
|dkr[tj|�}q
|tkr
q
q
W|S(Nsapplication/x-gziptquiettdecodesapplication/base64(Rtdecomp_gziptFalseRt	b64decodeR(R0textraction_typestresulttt((sC/usr/lib/python2.7/site-packages/cloudinit/config/cc_write_files.pyR%�s
(t__doc__RR#R6t	cloudinitRtloggingtcloudinit.settingsRRt	frequencyR'R)Rt	getLoggert__name__RRRRR(R%(((sC/usr/lib/python2.7/site-packages/cloudinit/config/cc_write_files.pyt<module>8s