%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c@@s~dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZddlZddlZddlZddlZddlZddlZddlmZddlmZddlmZd	gZiZid
d6d
d6d
d
6Zd�ZdZ ej!e"�Z#d�Z$d�Z%d�Z&d�Z'ie$d6e'd6e%d6e%d6e&d6e&d6e&d6Z(dee)d�Z*d�Z+e,d�Z-d�Z.e,d �Z/e,d!�Z0e,ed"�Z1ed#�Z2d$�Z3e,d%�Z4d&�Z5d'dd(dd)�Z7ed*�Z8d+d,d-�Z9de,e,ed.�Z:d/�Z;e*Z<dS(0u
Return/control aspects of the grains data

Grains set or altered with this module are stored in the 'grains'
file on the minions. By default, this file is located at: ``/etc/salt/grains``

.. Note::

   This does **NOT** override any grains set in the minion config file.
i(tabsolute_importtprint_functiontunicode_literalsN(treduce(tsix(tDEFAULT_TARGET_DELIM(t
SaltException(trangeu*unesteduitemsuitemusetvalcC@s
tjt�S(N(tcollectionstdefaultdictt
_infinitedict(((s7/usr/lib/python2.7/site-packages/salt/modules/grains.pyt<lambda>0su/NonExistentValueMagicNumberSpK3hnufdHfeBUXCfqVKcC@sAt|�}ttj|d��}dj|| d||�S(u*Replaces the last 1/4 of a string with X'sg�?u{0}{1}uX(tlentinttmathtfloortformat(tinstrtlengthtindex((s7/usr/lib/python2.7/site-packages/salt/modules/grains.pyt_serial_sanitizer7scC@sdS(NuMINION.DOMAINNAME((tx((s7/usr/lib/python2.7/site-packages/salt/modules/grains.pyR>scC@sdS(NuMINION((R((s7/usr/lib/python2.7/site-packages/salt/modules/grains.pyR?scC@sdS(Nu
DOMAINNAME((R((s7/usr/lib/python2.7/site-packages/salt/modules/grains.pyR@suserialnumberudomainufqdnuiduhostu	localhostunodenameucC@sU|tkrt}n$tjjjtjjjt��}tjjj||||�S(u�
    Attempt to retrieve the named value from grains, if the named value is not
    available return the passed default. The default return is an empty string.

    The value can also represent a value in a nested dict using a ":" delimiter
    for the dict. This means that if a dict in grains looks like this::

        {'pkg': {'apache': 'httpd'}}

    To retrieve the value associated with the apache key in the pkg dict this
    key can be passed::

        pkg:apache


    :param delimiter:
        Specify an alternate delimiter to use when traversing a nested dict.
        This is useful for when the desired key contains a colon. See CLI
        example below for usage.

        .. versionadded:: 2014.7.0

    :param ordered:
        Outputs an ordered dict if applicable (default: True)

        .. versionadded:: 2016.11.0

    CLI Example:

    .. code-block:: bash

        salt '*' grains.get pkg:apache
        salt '*' grains.get abc::def|ghi delimiter='|'
    (	tTruet
__grains__tsalttutilstjsontloadstdumpstdatattraverse_dict_and_list(tkeytdefaultt	delimitertorderedtgrains((s7/usr/lib/python2.7/site-packages/salt/modules/grains.pytgetPs#	$cC@stjjjt|t�tk	S(ud
    Determine whether a key exists in the grains dictionary.

    Given a grains dictionary that contains the following structure::

        {'pkg': {'apache': 'httpd'}}

    One would determine if the apache key in the pkg dict exists by::

        pkg:apache

    CLI Example:

    .. code-block:: bash

        salt '*' grains.has_value pkg:apache
    (RRRRRtKeyError(R((s7/usr/lib/python2.7/site-packages/salt/modules/grains.pyt	has_value~scC@sptjjj|�rhtt�}x@tjt�D]/\}}||kr1|||�||<q1q1W|StSdS(u�
    Return all of the minion's grains

    CLI Example:

    .. code-block:: bash

        salt '*' grains.items

    Sanitized CLI Example:

    .. code-block:: bash

        salt '*' grains.items sanitize=True
    N(	RRRtis_truetdictRRt	iteritemst_SANITIZERS(tsanitizetoutRtfunc((s7/usr/lib/python2.7/site-packages/salt/modules/grains.pytitems�scO@s�i}|jdd�}|jdt�}y7x0|D](}tjjjt|||�||<q4WWntk
rtnXtjjj|jd��r�xCt	j
t�D]/\}}||kr�|||�||<q�q�Wn|S(u
    Return one or more grains

    CLI Example:

    .. code-block:: bash

        salt '*' grains.item os
        salt '*' grains.item os osrelease oscodename

    Sanitized CLI Example:

    .. code-block:: bash

        salt '*' grains.item host sanitize=True
    udefaultuu	delimiterusanitize(R$RRRRRRR%R'RR)R*(targstkwargstretR R!targR-((s7/usr/lib/python2.7/site-packages/salt/modules/grains.pytitem�s"

c	
C@s�|}t|tj�s'td��ni}tjjtd�r�tj	j
j�r�tjjtjj
td�dtdd�}q�tjjtjj
td�d�}n�tjjtd�rtj	j
j�r�tjjtddtdd�}q�tjjtdd�}nitj	j
j�r]tjjtjj
td�dtdd�}n%tjjtjj
td�d�}tjj|�rtj	jj|d��I}ytj	jj|�}Wn&tj	jjk
r�}dj|�SXWdQXt|t�si}qnxxtj|�D]g\}}|dkru|tkru||kr\||=n|tkr�t|=q�q"|||<|t|<q"WyAtj	jj|d	��#}tj	jj||d
t�WdQXWn'ttfk
r�tj d|�nXtjjtdd
�}y#tj	jj!|d	��WdQXWn'ttfk
r]tj d|�nXtj"dt�s~t#d�n|S(u"
    Set new grains values in the grains config file

    destructive
        If an operation results in a key being removed, delete the key, too.
        Defaults to False.

    CLI Example:

    .. code-block:: bash

        salt '*' grains.setvals "{'key1': 'val1', 'key2': 'val2'}"
    u$setvals grains must be a dictionary.u	conf_fileuproxy.duidugrainsurbu(Unable to read existing grains file: {0}Nuw+tdefault_flow_styleu8Unable to write to grains file at %s. Check permissions.ucachedirumodule_refreshu4Unable to write to cache file %s. Check permissions.ulocalusaltutil.refresh_grains($t
isinstanceRtMappingRtostpathtisfilet__opts__RRtplatformtis_proxytjointdirnametisdirtfilestfopentyamlt	safe_loadt	YAMLErrorRR(RR)tNoneRRt	safe_dumptFalsetIOErrortOSErrortlogterrortflopenR$t__salt__(	R#tdestructivet
new_grainstgfntfp_texcRtvaltfn_((s7/usr/lib/python2.7/site-packages/salt/modules/grains.pytsetvals�s�							


&
cC@sti||6|�S(u�
    Set a grains value in the grains config file

    key
        The grain key to be set.

    val
        The value to set the grain key to.

    destructive
        If an operation results in a key being removed, delete the key, too.
        Defaults to False.

    CLI Example:

    .. code-block:: bash

        salt '*' grains.setval key val
        salt '*' grains.setval key "{'sub-key': 'val', 'sub-key2': 'val2'}"
    (RU(RRSRN((s7/usr/lib/python2.7/site-packages/salt/modules/grains.pytsetval9scC@s6t|g|�}|rHt|t�sH|dkr9gn|g}qHnt|t�sddj|�S||kr�dj||�St|t�r�x+|D]}|j|�q�Wn
|j|�xi||kr(|j|d�\}}t|t�|�}t|t�r|j	i||6�n|}q�Wt
||�S(u�
    .. versionadded:: 0.17.0

    Append a value to a list in the grains config file. If the grain doesn't
    exist, the grain key is added and the value is appended to the new grain
    as a list item.

    key
        The grain key to be appended to

    val
        The value to append to the grain key

    convert
        If convert is True, convert non-list contents into a list.
        If convert is False and the grain contains non-list contents, an error
        is given. Defaults to False.

    delimiter
        The key can be a nested dict key. Use this parameter to
        specify the delimiter you use, instead of the default ``:``.
        You can now append values to a list in nested dictionary grains. If the
        list doesn't exist at this level, it will be created.

        .. versionadded:: 2014.7.6

    CLI Example:

    .. code-block:: bash

        salt '*' grains.append key val
    uThe key {0} is not a valid listu'The val {0} was already in the list {1}iN(R$R5tlistRERtappendtrsplitR
R(tupdateRV(RRStconvertR!R#R3trestt_grain((s7/usr/lib/python2.7/site-packages/salt/modules/grains.pyRXQs&!!



cC@s�t|g|�}t|t�s.dj|�S||krJdj||�S|j|�xf||kr�|j|d�\}}t|d|�}t|t�r�|ji||6�n|}qZWt	||�S(uF
    .. versionadded:: 0.17.0

    Remove a value from a list in the grains config file

    key
        The grain key to remove.

    val
        The value to remove.

    delimiter
        The key can be a nested dict key. Use this parameter to
        specify the delimiter you use, instead of the default ``:``.
        You can now append values to a list in nested dictionary grains. If the
        list doesn't exist at this level, it will be created.

        .. versionadded:: 2015.8.2

    CLI Example:

    .. code-block:: bash

        salt '*' grains.remove key val
    uThe key {0} is not a valid listu#The val {0} was not in the list {1}iN(
R$R5RWRtremoveRYRER(RZRV(RRSR!R#R\R]((s7/usr/lib/python2.7/site-packages/salt/modules/grains.pyR^�s


cC@st|ddt�dS(u
    .. versionadded:: 2017.7.0

    Remove a grain completely from the grain system, this will remove the
    grain key and value

    key
        The grain key from which to delete the value.

    CLI Example:

    .. code-block:: bash

        salt '*' grains.delkey key
    RNN(RVRER(R((s7/usr/lib/python2.7/site-packages/salt/modules/grains.pytdelkey�scC@st|dd|�dS(u�
    .. versionadded:: 0.17.0

    Delete a grain value from the grains config file. This will just set the
    grain value to ``None``. To completely remove the grain, run ``grains.delkey``
    or pass ``destructive=True`` to ``grains.delval``.

    key
        The grain key from which to delete the value.

    destructive
        Delete the key, too. Defaults to False.

    CLI Example:

    .. code-block:: bash

        salt '*' grains.delval key
    RNN(RVRE(RRN((s7/usr/lib/python2.7/site-packages/salt/modules/grains.pytdelval�scC@s
tt�S(uw
    Return a list of all available grains

    CLI Example:

    .. code-block:: bash

        salt '*' grains.ls
    (tsortedR(((s7/usr/lib/python2.7/site-packages/salt/modules/grains.pytls�s
u	os_familyudefaultc
C@s4tjjjd|d|dtd|d|d|�S(u�
    .. versionadded:: 0.17.0

    Look up the given grain in a given dictionary for the current OS and return
    the result

    Although this may occasionally be useful at the CLI, the primary intent of
    this function is for use in Jinja to make short work of creating lookup
    tables for OS-specific data. For example:

    .. code-block:: jinja

        {% set apache = salt['grains.filter_by']({
            'Debian': {'pkg': 'apache2', 'srv': 'apache2'},
            'RedHat': {'pkg': 'httpd', 'srv': 'httpd'},
        }, default='Debian') %}

        myapache:
          pkg.installed:
            - name: {{ apache.pkg }}
          service.running:
            - name: {{ apache.srv }}

    Values in the lookup table may be overridden by values in Pillar. An
    example Pillar to override values in the example above could be as follows:

    .. code-block:: yaml

        apache:
          lookup:
            pkg: apache_13
            srv: apache

    The call to ``filter_by()`` would be modified as follows to reference those
    Pillar values:

    .. code-block:: jinja

        {% set apache = salt['grains.filter_by']({
            ...
        }, merge=salt['pillar.get']('apache:lookup')) %}


    :param lookup_dict: A dictionary, keyed by a grain, containing a value or
        values relevant to systems matching that grain. For example, a key
        could be the grain for an OS and the value could the name of a package
        on that particular OS.

        .. versionchanged:: 2016.11.0

            The dictionary key could be a globbing pattern. The function will
            return the corresponding ``lookup_dict`` value where grain value
            matches the pattern. For example:

            .. code-block:: bash

                # this will render 'got some salt' if Minion ID begins from 'salt'
                salt '*' grains.filter_by '{salt*: got some salt, default: salt is not here}' id

    :param grain: The name of a grain to match with the current system's
        grains. For example, the value of the "os_family" grain for the current
        system could be used to pull values from the ``lookup_dict``
        dictionary.

        .. versionchanged:: 2016.11.0

            The grain value could be a list. The function will return the
            ``lookup_dict`` value for a first found item in the list matching
            one of the ``lookup_dict`` keys.

    :param merge: A dictionary to merge with the results of the grain selection
        from ``lookup_dict``. This allows Pillar to override the values in the
        ``lookup_dict``. This could be useful, for example, to override the
        values for non-standard package names such as when using a different
        Python version from the default Python version provided by the OS
        (e.g., ``python26-mysql`` instead of ``python-mysql``).

    :param default: default lookup_dict's key used if the grain does not exists
        or if the grain value has no match on lookup_dict.  If unspecified
        the value is "default".

        .. versionadded:: 2014.1.0

    :param base: A lookup_dict key to use for a base dictionary.  The
        grain-selected ``lookup_dict`` is merged over this and then finally
        the ``merge`` dictionary is merged.  This allows common values for
        each case to be collected in the base and overridden by the grain
        selection dictionary and the merge dictionary.  Default is unset.

        .. versionadded:: 2015.5.0

    CLI Example:

    .. code-block:: bash

        salt '*' grains.filter_by '{Debian: Debheads rule, RedHat: I love my hat}'
        # this one will render {D: {E: I, G: H}, J: K}
        salt '*' grains.filter_by '{A: B, C: {D: {E: F, G: H}}}' 'xxx' '{D: {E: I}, J: K}' 'C'
        # next one renders {A: {B: G}, D: J}
        salt '*' grains.filter_by '{default: {A: {B: C}, D: E}, F: {A: {B: G}}, H: {D: I}}' 'xxx' '{D: J}' 'F' 'default'
        # next same as above when default='H' instead of 'F' renders {A: {B: C}, D: J}
    tlookup_dicttlookupttraversetmergeR tbase(RRRt	filter_byR(RctgrainRfR Rg((s7/usr/lib/python2.7/site-packages/salt/modules/grains.pyRh�sgcC@sCt�}|j|�}ttj|d |�}|||d<|S(u�
    Given a lookup string in the form of 'foo:bar:baz" return a nested
    dictionary of the appropriate depth with the final segment as a value.

    >>> _dict_from_path('foo:bar:baz', 'somevalue')
    {"foo": {"bar": {"baz": "somevalue"}}
    i����(R
RYRtoperatortgetitem(R8RSR!tnested_dicttkeyst	lastplace((s7/usr/lib/python2.7/site-packages/salt/modules/grains.pyt_dict_from_path[s
	iu2abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)c	C@s�t|d�}|dkr�djgt|�D]}tj�j|�^q.�}t|kr�|jtd�\}}t|t	��}t
||�}|j|�t||�q�t||�nt|�S(u�
    Perform a one-time generation of a hash and write it to the local grains.
    If that grain has already been set return the value instead.

    This is useful for generating passwords or keys that are specific to a
    single minion that don't need to be stored somewhere centrally.

    State Example:

    .. code-block:: yaml

        some_mysql_user:
          mysql_user:
            - present
            - host: localhost
            - password: {{ salt['grains.get_or_set_hash']('mysql:some_mysql_user') }}

    CLI Example:

    .. code-block:: bash

        salt '*' grains.get_or_set_hash 'django:SECRET_KEY' 50

    .. warning::

        This function could return strings which may contain characters which are reserved
        as directives by the YAML parser, such as strings beginning with ``%``. To avoid
        issues when using the output of this function in an SLS file containing YAML+Jinja,
        surround the call with single quotes.
    uiN(
R$RER=RtrandomtSystemRandomtchoiceRtsplitR
RoRZRV(	tnameRtcharsR1t_RStrootR\tcurr((s7/usr/lib/python2.7/site-packages/salt/modules/grains.pytget_or_set_hashks!7
cC@seidd6id6td6}d}t|t�r9d}nt|t�rQd}nt�}t|||�}|}	d}
||kr�d
}
n0t|t�r�d}
nt|t�r�d}
n|
d
k	r�||kr�|d
k	s�|tk	r�d|d<|S|d
k	r}|r}|
dkr;dj|�|d<t|d<|S|dkrt|
d
k	rtd	j|�|d<t|d<|S|}	n|}	x�||kr|j	|d
�\}}t|i|�}t|t�r|	d
kr|r||j
�kr|j|�qq|ji|	|6�n�t|t�r�t}xxt
|�D]j\}
}||krmi|	|6||
<t}q;t|t�r;||kr;|ji|	|6�t}q;q;W|s|ji|	|6�qnI||ks�|r�i|	|6}n'dj|||�|d<t|d<|S|}	q�Wt||	d|�}t|t�rM||d<n||d<t|d<|S(un
    Set a key to an arbitrary value. It is used like setval but works
    with nested keys.

    This function is conservative. It will only overwrite an entry if
    its value and the given one are not a list or a dict. The ``force``
    parameter is used to allow overwriting in all cases.

    .. versionadded:: 2015.8.0

    :param force: Force writing over existing entry if given or existing
                  values are list or dict. Defaults to False.
    :param destructive: If an operation results in a key being removed,
                  delete the key, too. Defaults to False.
    :param delimiter:
        Specify an alternate delimiter to use when traversing a nested dict,
        the default being ``:``

    CLI Example:

    .. code-block:: bash

        salt '*' grains.set 'apps:myApp:port' 2209
        salt '*' grains.set 'apps:myApp' '{port: 2209}'
    uucommentuchangesuresultusimpleucomplexuGrain is already setuLThe key '{0}' exists but is a dict or a list. Use 'force=True' to overwrite.u\The key '{0}' exists and the given value is a dict or a list. Use 'force=True' to overwrite.iulThe key '{0}' value is '{1}', which is different from the provided key '{2}'. Use 'force=True' to overwrite.RNN(RR5R(RWtobjectR$RERRGRYRmtpopRZt	enumerateRXRV(RRStforceRNR!R1t_new_value_typet
_non_existentt_existing_valuet_valuet_existing_value_typeR\t
_list_updatedt_indext_itemt_setval_ret((s7/usr/lib/python2.7/site-packages/salt/modules/grains.pytset�s�

						




		





cC@s"tj|�tjt|��kS(u+
    Used to make sure the minion's grain key/value matches.

    Returns ``True`` if matches otherwise ``False``.

    .. versionadded:: 2017.7.0

    CLI Example:

    .. code-block:: bash

        salt '*' grains.equals fqdn <expected_fqdn>
        salt '*' grains.equals systemd:version 219
    (Rt	text_typeR$(Rtvalue((s7/usr/lib/python2.7/site-packages/salt/modules/grains.pytequalss(=t__doc__t
__future__RRRR7RptloggingRjRRt	functoolsRtsalt.extRtsalt.utils.compatRtsalt.utils.datatsalt.utils.filestsalt.utils.jsontsalt.utils.platformtsalt.utils.yamlt
salt.defaultsRtsalt.exceptionsRtsalt.ext.six.movesRt__proxyenabled__Rt
__outputter__R
t_non_existent_keyt	getLoggert__name__RJRt_FQDN_SANITIZERt_HOSTNAME_SANITIZERt_DOMAINNAME_SANITIZERR*RR$R&RGR.R3RURVRXR^R_R`RbRERhRoRyR�R�tfetch(((s7/usr/lib/python2.7/site-packages/salt/modules/grains.pyt<module>sx	
					
.		&c9+		
o1u	

Zerion Mini Shell 1.0