%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/pillar/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/pillar/file_tree.pyc

�
���^c	@@sdZddlmZmZmZddlZddlZddlZddlZ	ddl
Z	ddlZ	ddlZ	ddl
Z	ddlZ	ddlZ	ddlZ	ddlmZeje�Zd�Zd�Zeddded�Zdeeeddded�Zd	�ZdS(
uo
The ``file_tree`` external pillar allows values from all files in a directory
tree to be imported as Pillar data.

.. note::

    This is an external pillar and is subject to the :ref:`rules and
    constraints <external-pillars>` governing external pillars.

.. versionadded:: 2015.5.0

In this pillar, data is organized by either Minion ID or Nodegroup name.  To
setup pillar data for a specific Minion, place it in
``<root_dir>/hosts/<minion_id>``.  To setup pillar data for an entire
Nodegroup, place it in ``<root_dir>/nodegroups/<node_group>`` where
``<node_group>`` is the Nodegroup's name.

Example ``file_tree`` Pillar
============================

Master Configuration
--------------------

.. code-block:: yaml

    ext_pillar:
      - file_tree:
          root_dir: /srv/ext_pillar
          follow_dir_links: False
          keep_newline: True

The ``root_dir`` parameter is required and points to the directory where files
for each host are stored. The ``follow_dir_links`` parameter is optional and
defaults to False. If ``follow_dir_links`` is set to True, this external pillar
will follow symbolic links to other directories.

.. warning::
    Be careful when using ``follow_dir_links``, as a recursive symlink chain
    will result in unexpected results.

.. versionchanged:: 2018.3.0
    If ``root_dir`` is a relative path, it will be treated as relative to the
    :conf_master:`pillar_roots` of the environment specified by
    :conf_minion:`pillarenv`. If an environment specifies multiple
    roots, this module will search for files relative to all of them, in order,
    merging the results.

If ``keep_newline`` is set to ``True``, then the pillar values for files ending
in newlines will keep that newline. The default behavior is to remove the
end-of-file newline. ``keep_newline`` should be turned on if the pillar data is
intended to be used to deploy a file using ``contents_pillar`` with a
:py:func:`file.managed <salt.states.file.managed>` state.

.. versionchanged:: 2015.8.4
    The ``raw_data`` parameter has been renamed to ``keep_newline``. In earlier
    releases, ``raw_data`` must be used. Also, this parameter can now be a list
    of globs, allowing for more granular control over which pillar values keep
    their end-of-file newline. The globs match paths relative to the
    directories named for minion IDs and nodegroups underneath the ``root_dir``
    (see the layout examples in the below sections).

    .. code-block:: yaml

        ext_pillar:
          - file_tree:
              root_dir: /path/to/root/directory
              keep_newline:
                - files/testdir/*

.. note::
    In earlier releases, this documentation incorrectly stated that binary
    files would not affected by the ``keep_newline`` configuration.  However,
    this module does not actually distinguish between binary and text files.

.. versionchanged:: 2017.7.0
    Templating/rendering has been added. You can now specify a default render
    pipeline and a black- and whitelist of (dis)allowed renderers.

    ``template`` must be set to ``True`` for templating to happen.

    .. code-block:: yaml

        ext_pillar:
          - file_tree:
            root_dir: /path/to/root/directory
            render_default: jinja|yaml
            renderer_blacklist:
              - gpg
            renderer_whitelist:
              - jinja
              - yaml
            template: True

Assigning Pillar Data to Individual Hosts
-----------------------------------------

To configure pillar data for each host, this external pillar will recursively
iterate over ``root_dir``/hosts/``id`` (where ``id`` is a minion ID), and
compile pillar data with each subdirectory as a dictionary key and each file
as a value.

For example, the following ``root_dir`` tree:

.. code-block:: text

    ./hosts/
    ./hosts/test-host/
    ./hosts/test-host/files/
    ./hosts/test-host/files/testdir/
    ./hosts/test-host/files/testdir/file1.txt
    ./hosts/test-host/files/testdir/file2.txt
    ./hosts/test-host/files/another-testdir/
    ./hosts/test-host/files/another-testdir/symlink-to-file1.txt

will result in the following pillar tree for minion with ID ``test-host``:

.. code-block:: text

    test-host:
        ----------
        apache:
            ----------
            config.d:
                ----------
                00_important.conf:
                    <important_config important_setting="yes" />
                20_bob_extra.conf:
                    <bob_specific_cfg has_freeze_ray="yes" />
        corporate_app:
            ----------
            settings:
                ----------
                common_settings:
                    // This is the main settings file for the corporate
                    // internal web app
                    main_setting: probably
                bob_settings:
                    role: bob

.. note::

    The leaf data in the example shown is the contents of the pillar files.
i(tabsolute_importtprint_functiontunicode_literalsN(tsixcC@stjd|j|j�dS(u.
    Log salt.utils.path.os_walk() error.
    u%s: %sN(tlogterrortfilenametstrerror(terr((s9/usr/lib/python2.7/site-packages/salt/pillar/file_tree.pyt_on_walk_error�scC@s�t|t�r|Stjj||�}x[|D]S}ytj||�rOtSWq0tk
r�tj|tj	|��r�tSq0Xq0Wt
S(u`
    Return a boolean stating whether or not a file's trailing newline should be
    removed. To figure this out, first check if keep_newline is a boolean and
    if so, return its opposite. Otherwise, iterate over keep_newline and check
    if any of the patterns match the file path. If a match is found, return
    False, otherwise return True.
    (t
isinstancetbooltostpathtjointfnmatchtFalset	TypeErrorRt	text_typetTrue(tprefixt	file_nametkeep_newlinet	full_pathtpattern((s9/usr/lib/python2.7/site-packages/salt/pillar/file_tree.pyt_check_newline�s

cC@s�i}tjjtt�}tjj|�}	x�tjjj	|dt
dtd|�D]`\}
}}|}
tjj|
�}tjj||	�}||	krg}|}x2|r�tjj
|�\}}|jd|�q�Wx |r�|
|jd�}
q�Wnx|D]}i|
|<qWx�|D]�}tjj|
|�}tjj|�sftjd|�q#nd}y�tjjj|d��r}|jtd�}x'|r�||7}|jtd�}q�W|jd	�r�t|||�r�|d
 }nWdQXWn/ttfk
r-}tjd||j�q#X|}|t
krtjjd
tjjj|�d|d|d|d|�}ntjj j!|�r�|j"�|
|<q#||
|<q#WqUW|S(u*
    Construct pillar from file tree.
    ttopdowntonerrortfollowlinksiu!file_tree: %s: not a regular fileturbufile_buffer_sizes
i����Nufile_tree: Error reading %s: %sttemplatet	rendererstdefaultt	blacklistt	whitelist(#tsalttloadertrendert__opts__t__salt__RR
tnormpathtutilstos_walkRR	trelpathtsplittinserttpopRtisfileRRtfilestfopentreadtendswithRtIOErrortOSErrorRRtcompile_template_strtstringutilst
to_unicodetstringiotis_readabletgetvalue(ttop_dirtfollow_dir_linksRtrender_defaulttrenderer_blacklisttrenderer_whitelistRtpillarRtnorm_top_dirtdir_patht	dir_namest
file_namestpillar_nodet
norm_dir_pathRt
path_partstheadttailtdir_nameRt	file_pathtcontentstfhrtbuftexctdata((s9/usr/lib/python2.7/site-packages/salt/pillar/file_tree.pyt_construct_pillar�sf
		

	
		!c
C@sl~|stjd�iStjj|�std}
|
d
krStjd�iStjd|
�tdj|
d
�}|d
kr�tjd|
�iSg}x[|D]S}
tjj	tjj
|
|��}||ks�||dkr�|j|�q�q�W|}n	|g}i}xP|D]H}t|||||||||	�	}t
jjj||dd	�}qW|S(ul
    Compile pillar data from the given ``root_dir`` specific to Nodegroup names
    and Minion IDs.

    If a Minion's ID is not found at ``<root_dir>/host/<minion_id>`` or if it
    is not included in any Nodegroups named at
    ``<root_dir>/nodegroups/<node_group>``, no pillar data provided by this
    pillar module will be available for that Minion.

    .. versionchanged:: 2017.7.0
        Templating/rendering has been added. You can now specify a default
        render pipeline and a black- and whitelist of (dis)allowed renderers.

        ``template`` must be set to ``True`` for templating to happen.

        .. code-block:: yaml

            ext_pillar:
              - file_tree:
                root_dir: /path/to/root/directory
                render_default: jinja|yaml
                renderer_blacklist:
                  - gpg
                renderer_whitelist:
                  - jinja
                  - yaml
                template: True

    :param minion_id:
        The ID of the Minion whose pillar data is to be collected

    :param pillar:
        Unused by the ``file_tree`` pillar module

    :param root_dir:
        Filesystem directory used as the root for pillar data (e.g.
        ``/srv/ext_pillar``)

        .. versionchanged:: 2018.3.0
            If ``root_dir`` is a relative path, it will be treated as relative to the
            :conf_master:`pillar_roots` of the environment specified by
            :conf_minion:`pillarenv`. If an environment specifies multiple
            roots, this module will search for files relative to all of them, in order,
            merging the results.

    :param follow_dir_links:
        Follow symbolic links to directories while collecting pillar files.
        Defaults to ``False``.

        .. warning::

            Care should be exercised when enabling this option as it will
            follow links that point outside of ``root_dir``.

        .. warning::

            Symbolic links that lead to infinite recursion are not filtered.

    :param debug:
        Enable debug information at log level ``debug``.  Defaults to
        ``False``.  This option may be useful to help debug errors when setting
        up the ``file_tree`` pillar module.

    :param keep_newline:
        Preserve the end-of-file newline in files.  Defaults to ``False``.
        This option may either be a boolean or a list of file globs (as defined
        by the `Python fnmatch package
        <https://docs.python.org/library/fnmatch.html>`_) for which end-of-file
        newlines are to be kept.

        ``keep_newline`` should be turned on if the pillar data is intended to
        be used to deploy a file using ``contents_pillar`` with a
        :py:func:`file.managed <salt.states.file.managed>` state.

        .. versionchanged:: 2015.8.4
            The ``raw_data`` parameter has been renamed to ``keep_newline``. In
            earlier releases, ``raw_data`` must be used. Also, this parameter
            can now be a list of globs, allowing for more granular control over
            which pillar values keep their end-of-file newline. The globs match
            paths relative to the directories named for Minion IDs and
            Nodegroup namess underneath the ``root_dir``.

            .. code-block:: yaml

                ext_pillar:
                  - file_tree:
                      root_dir: /srv/ext_pillar
                      keep_newline:
                        - apache/config.d/*
                        - corporate_app/settings/*

        .. note::
            In earlier releases, this documentation incorrectly stated that
            binary files would not affected by the ``keep_newline``.  However,
            this module does not actually distinguish between binary and text
            files.


    :param render_default:
        Override Salt's :conf_master:`default global renderer <renderer>` for
        the ``file_tree`` pillar.

        .. code-block:: yaml

            render_default: jinja

    :param renderer_blacklist:
        Disallow renderers for pillar files.

        .. code-block:: yaml

            renderer_blacklist:
              - json

    :param renderer_whitelist:
        Allow renderers for pillar files.

        .. code-block:: yaml

            renderer_whitelist:
              - yaml
              - jinja

    :param template:
        Enable templating of pillar files.  Defaults to ``False``.
    u file_tree: no root_dir specifiedu	pillarenvu8file_tree: root_dir is relative but pillarenv is not setufile_tree: pillarenv = %supillar_rootsuSfile_tree: root_dir is relative but no pillar_roots are specified  for pillarenv %si����tstrategyurecurseN(RRRR
tisabsR&tNonetdebugtgetR(Rtappendt_ext_pillarR#R)t
dictupdatetmerge(t	minion_idRAtroot_dirR=RVRR>R?R@Rt	pillarenvt	env_rootstenv_dirstenv_roottenv_dirtdirst
result_pillartroott
dir_pillar((s9/usr/lib/python2.7/site-packages/salt/pillar/file_tree.pyt
ext_pillarsJ�


	
!		
	
c	
C@s�tjd|�tjj|�s6tjd|�iSt|ttf�s_tjd|�iSi}	tjj	|d�}
tjj
|
�r�ttj
dd��dkr�td}tj|
�}t|�dkr�x�|D]�}
tjj|
�r�|
|kr�tjjjt�}|j||
d�}|d}||kr�tjj	|
tj|
��}tjjj|	t|||||||�dd	�}	q�q�q�Wq�|tkr�tjd
|�q�n|tkr�tjd�ntjj	|d|�}tjj
|�s0|tkr,tjd
||�n|	Stjj|�sVtjd|�|	St|||||||�}tjjj|	|dd	�S(uO
    Compile pillar data for a single root_dir for the specified minion ID
    ufile_tree: reading %su;file_tree: root_dir %s does not exist or is not a directoryusfile_tree: keep_newline must be either True/False or a list of file globs. Skipping this ext_pillar for root_dir %su
nodegroupsiucompounduminionsRSurecurseuEfile_tree: no nodegroups found in file tree directory %s, skipping...u6file_tree: no nodegroups found in master configurationuhostsuGfile_tree: no pillar data for minion %s found in file tree directory %su,file_tree: %s exists, but is not a directory((RRVRR
tisdirRR
RtlistRtexiststlenR&RWtlistdirR#R)tminionst	CkMinionst
check_minionsRRRZR[RRR(R\R]R=RVRR>R?R@Rt
ngroup_pillartnodegroups_dirtmaster_ngroupstext_pillar_dirst	nodegroupt	ckminionst_restmatcht
ngroup_dirthost_dirthost_pillar((s9/usr/lib/python2.7/site-packages/salt/pillar/file_tree.pyRY�s�0

	
		

	(t__doc__t
__future__RRRRtloggingRtsalt.loaderR#tsalt.utils.dictupdatetsalt.utils.filestsalt.utils.minionstsalt.utils.pathtsalt.utils.stringiotsalt.utils.stringutilst
salt.templatetsalt.extRt	getLoggert__name__RR	RRRURRRgRY(((s9/usr/lib/python2.7/site-packages/salt/pillar/file_tree.pyt<module>�s<		E�

Zerion Mini Shell 1.0