Current File : //lib/python2.7/site-packages/cloudinit/config/cc_write_files.pyo |
�
oB�]c @ s� d Z d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l m Z e Z
d Z d Z d Z
e j e � Z d � Z d
� Z d � Z d � Z d
� Z d S( 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( t log( t PER_INSTANCE( t utils root:rooti� s
text/plainc C s: | j d � } | s) | j d | � d St | | � d S( Nt write_filessE Skipping module named %s, no/empty 'write_files' key in configuration( t gett debugR ( t namet cfgt _cloudR t _argst files( ( sC /usr/lib/python2.7/site-packages/cloudinit/config/cc_write_files.pyt handleL s c C s� | s d } n | j � j � } | d
k r4 d g S| d k rJ d d g S| d k r] d g S| ry t j d | t � n t g S( Nt t gzt gzips application/x-gzips gz+base64s gzip+base64s gz+b64s gzip+b64s application/base64t b64t base64s% Unknown encoding type %s, assuming %s( R
R ( s gz+base64s gzip+base64s gz+b64s gzip+b64( R s base64( t lowert stript LOGt warningt UNKNOWN_ENC( t
encoding_type( ( sC /usr/lib/python2.7/site-packages/cloudinit/config/cc_write_files.pyt canonicalize_extractionU s
c C s% | s
d Sxt | � D]\ } } | j d � } | sU t j d | d | � q n t j j | � } t | j d � � } t | j d d � | � } t j
| j d t � � \ } } t | j d � t
� } t j | d � r� d
n d }
t j | | d |
d
| �t j | | | � q Wd S( Nt paths3 No path provided to write for entry %s in module %si t encodingt contentR t ownert permissionst appendt abt wbt omodet mode( t enumerateR R R t osR t abspathR t extract_contentsR t extract_usergroupt
DEFAULT_OWNERt decode_permst
DEFAULT_PERMSt get_cfg_option_boolt
write_filet chownbyname( R R
t it f_infoR t extractionst contentst ut gt permsR ( ( sC /usr/lib/python2.7/site-packages/cloudinit/config/cc_write_files.pyR i s !c C s� | d k r | Sy: t | t j t f � r6 t | � St t | � d � SWn t t f k
r� g } xN | | f D]@ } y | j d | � Wqs t k
r� | j d | � qs Xqs Wt
j d | � | SXd S( Ni s %os %rs0 Undecodable permissions %s, returning default %s( t Nonet
isinstancet sixt
integer_typest floatt intt strt TypeErrort
ValueErrorR R R ( t permt defaultt repst r( ( sC /usr/lib/python2.7/site-packages/cloudinit/config/cc_write_files.pyR( } s
c C sr | } xe | D]] } | d k r= t j | d t d t �} q
| d k r[ t j | � } q
| t k r
q
q
W| S( Ns application/x-gzipt quiett decodes application/base64( R t decomp_gzipt FalseR t b64decodeR ( R0 t extraction_typest resultt t( ( sC /usr/lib/python2.7/site-packages/cloudinit/config/cc_write_files.pyR% � s
( t __doc__R R# R6 t cloudinitR t loggingt cloudinit.settingsR R t frequencyR'