ó oBú]c@s²dZddlZddlZddlZddlmZddlmZddlm Z eZ dZ dZ 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(Nt write_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+base64s gzip+base64sgz+b64sgzip+b64sapplication/base64tb64tbase64s%Unknown encoding type %s, assuming %s(R R(s gz+base64s gzip+base64sgz+b64sgzip+b64(Rsbase64(tlowertstriptLOGtwarningt UNKNOWN_ENC(t encoding_type((sC/usr/lib/python2.7/site-packages/cloudinit/config/cc_write_files.pytcanonicalize_extractionUs       c Cs%|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 townert permissionstappendtabtwbtomodetmode(t enumerateRRRtosRtabspathRtextract_contentsRtextract_usergroupt DEFAULT_OWNERt decode_permst DEFAULT_PERMStget_cfg_option_boolt write_filet chownbyname( RR titf_infoRt extractionstcontentstutgtpermsR ((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 j d|Œ|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(Rt decomp_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__RR RRR(R%(((sC/usr/lib/python2.7/site-packages/cloudinit/config/cc_write_files.pyt8s