HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/states/__pycache__/grains.cpython-310.pyc
o

�N�g�<�@svdZddlZddlmZefdd�Zddd�Zedfd	d
�Zefdd�Zefd
d�Zdedfdd�Z	defdd�Z
dS)aG
Manage grains on the minion
===========================

This state allows for grains to be set.

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.
�N)�DEFAULT_TARGET_DELIMcCsLt�|t|�}|iddd�}t�}td||�}||ur$d|d<d|d<|S)	z�
    Ensure that a grain is set

    name
        The grain name

    delimiter
        A delimiter different from the default can be provided.

    Check whether a grain exists. Does not attempt to check or set the value.
    TzGrain exists��name�changes�result�comment�
grains.getFrzGrain does not existr)�re�subr�object�__salt__)r�	delimiter�ret�
_non_existent�existing�r�F/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/grains.py�existssrcCs>|pt�}|D]}t|�tkrt||�q|�t|��q|S)a�
    Ensure that a list grain is hashable.

    list_grain
        The list grain that should be hashable

    result
        This function is recursive, so it must be possible to use a
        sublist as parameter to the function. Should not be used by a caller
        outside of the function.

    Make it possible to compare two list grains to each other if the list
    contains complex objects.
    )�set�type�list�
make_hashable�add�	frozenset)Z
list_grainrZsublistrrrr)s
rFcCs�t�|t|�}|iddd�}t�}td||�}||kr"d|d<|StdrPd|d	<||ur>d
|�d�|d<d|i|d
<|Sd
|�d�|d<d||ii|d
<|Std|||d�}|d	duro|d
ikrod|�d|��|d<||d<|S)a�
    Ensure that a grain is set

    .. versionchanged:: 2015.8.2

    name
        The grain name

    value
        The value to set on the grain

    force
        If force is True, the existing grain will be overwritten
        regardless of its existing or provided value type. Defaults to False

        .. versionadded:: 2015.8.2

    delimiter
        A delimiter different from the default can be provided.

        .. versionadded:: 2015.8.2

    It is now capable to set a grain to a complex value (ie. lists and dicts)
    and supports nested grains as well.

    If the grain does not yet exist, a new grain is set to the given value. For
    a nested grain, the necessary keys are created if they don't exist. If
    a given key is an existing value, it will be converted, but an existing value
    different from the given key will fail the state.

    If the grain with the given name exists, its value is updated to the new
    value unless its existing or provided value is complex (list or dict). Use
    `force: True` to overwrite.

    .. code-block:: yaml

      cheese:
        grains.present:
          - value: edam

      nested_grain_with_complex_value:
        grains.present:
          - name: icinga:Apache SSL
          - value:
            - command: check_https
            - params: -H localhost -p 443 -S

      with,a,custom,delimiter:
        grains.present:
          - value: yay
          - delimiter: ','
    T�rrzGrain is already setr�testNr�Grain � is set to be added�newrz is set to be changed�changed�
grains.set)�forcez
Set grain z to r)r	r
rrr�__opts__)r�valuer
r!rrrrrr�presentAs*5�r$cCsRt�|t|�}|iddd�}td|�}|r�t|t�s)d|d<d|�d�|d	<|St|t�r�t|��ttd|���rGd
|�d|��|d	<|S|t�	di�vrst
|��t�	di�|�}|rstt
|��td|��}d
�
||�|d	<dtvr{itd<|tdvr�t
�td|<td|�|�n||vr�d
|�d|��|d	<|Stdr�d|d<d�
||�|d	<d|i|d<|Stdr�d|d<d|�d�|d	<d|i|d<|Std||�}t|t�r�t
|��t
td|���s�d|d<d|�d|��|d	<|Sn|td|td�v�rd|d<d|�d|��|d	<|Sd|�d|��|d	<d|i|d<|S)a[
    .. versionadded:: 2014.1.0

    Ensure the value is present in the list-type grain. Note: If the grain that is
    provided in ``name`` is not present on the system, this new grain will be created
    with the corresponding provided value.

    name
        The grain name.

    value
        The value is present in the list type grain.

    delimiter
        A delimiter different from the default ``:`` can be provided.

        .. versionadded:: 2015.8.2

    The grain should be `list type <http://docs.python.org/2/tutorial/datastructures.html#data-structures>`_

    .. code-block:: yaml

        roles:
          grains.list_present:
            - value: web

    For multiple grains, the syntax looks like:

    .. code-block:: yaml

        roles:
          grains.list_present:
            - value:
              - web
              - dev
    TrrrFrr� is not a valid listr�Value z is already in grain Zpending_grainsz;Removed value {} from update due to context found in "{}".
rNz,Value {1} is set to be appended to grain {0}rrr�
grains.appendzFailed append value z
 to grain )r
z
Append value )r	r
rr�
isinstancerr�issubset�__context__�getr�intersection�
difference�format�updater")rr#r
r�grainr,Z
new_grainsrrr�list_present�sx%

������
�r1cCsbt�|t|�}|iddd�}g}td|d�}|r�t|t�r�t|t�s&|g}|D]g}||vr:|�d|�d|���q(tdrdd|d	<|�d|�d
|�d��d|d
vrZdgi|d
<|d
d�|�q(||vr�td||�|�d|�d|���d|d
vr�dgi|d
<|d
d�|�q(d�|�|d<|Sd|d	<d|�d�|d<|Sd|�d�|d<|S)a�
    Delete a value from a grain formed as a list.

    .. versionadded:: 2014.1.0

    name
        The grain name.

    value
       The value to delete from the grain list.

    delimiter
        A delimiter different from the default ``:`` can be provided.

        .. versionadded:: 2015.8.2

    The grain should be `list type <http://docs.python.org/2/tutorial/datastructures.html#data-structures>`_

    .. code-block:: yaml

        roles:
          grains.list_absent:
            - value: db

    For multiple grains, the syntax looks like:

    .. code-block:: yaml

        roles:
          grains.list_absent:
            - value:
              - web
              - dev
    TrrrNr&z is absent from grain rrz
 in grain � is set to be deleted�deletedrz
grains.removez was deleted from grain �
rFrr%� does not exist)	r	r
rrr(r�appendr"�join)rr#r
rZcommentsr0�valrrr�list_absent�s>$

��r9cCs�t�}t�|t|�}|iddd�}td||�}|dur^tdr8d|d<|dur6d|�d	�|d
<d|i|d<|Std
|d||d�}|drX|durXd|�d�|d
<d|i|d<||d<|S||ur�tdr�d|d<|dur~d|�d	�|d
<d|i|d<|Sd|�d�|d
<|dd�|d<|Std
|d||d�}|dr�|dur�d|�d�|d
<d|i|d<nd|�d�|d
<|dd�|d<||d<|Sd|�d�|d
<|S)ay
    .. versionadded:: 2014.7.0

    Delete a grain from the grains config file

    name
        The grain name

    destructive
        If destructive is True, delete the entire grain. If
        destructive is False, set the grain's value to None. Defaults to False.

    force
        If force is True, the existing grain will be overwritten
        regardless of its existing or provided value type. Defaults to False

        .. versionadded:: 2015.8.2

    delimiter
        A delimiter different from the default can be provided.

        .. versionadded:: 2015.8.2

    .. versionchanged:: 2015.8.2

    This state now support nested grains and complex values. It is also more
    conservative: if a grain has a value that is a list or a dict, it will
    not be removed unless the `force` parameter is True.

    .. code-block:: yaml

      grain_name:
        grains.absent
    TrrrNrrrr2rr3rr )�destructiver!z was deletedrzValue for grain z is set to be deleted (None))r0r#z was set to Noner5)rr	r
rrr")rr:r
r!rrr0rrr�absent:sN$���r;cCs�t�|t|�}|iddd�}td|d�}|s|tvr�t|t�ra||vr0d|�d|��|d<|Std	rHd|d
<d�||�|d<d|i|d
<|Std||�d|�d|��|d<d|i|d
<|S|dur�td	r}d|d
<d�||�|d<d|i|d
<|S|dur�gn|g}|�	|�td||�d|�d|��|d<d|i|d
<|Sd|d
<d|�d�|d<|Sd|d
<d|�d�|d<|S)a�
    .. versionadded:: 2014.7.0

    Append a value to a list in the grains config file. The grain that is being
    appended to (name) must exist before the new value can be added.

    name
        The grain name

    value
        The value to append

    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
        A delimiter different from the default can be provided.

        .. versionadded:: 2015.8.2

    .. code-block:: yaml

      grain_name:
        grains.append:
          - value: to_be_appended
    TrrrNr&z" is already in the list for grain rrrz)Value {1} in grain {0} is set to be addedZaddedrr'z was added to grain zBGrain {} is set to be converted to list and value {} will be addedz
grains.setvalFrr%r5)
r	r
rrZ
__grains__r(rr"r.r6)rr#�convertr
rr0rrrr6�sP
����
��r6)N)�__doc__r	Z
salt.defaultsrrrr$r1r9r;r6rrrr�<module>s

LhEN