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__/host.cpython-310.pyc
o

�N�g�!�@s<dZddlZddlZe�e�Zddd�Zdd�Zd	d
�Z	dS)aU
Management of addresses and names in hosts file
===============================================

The ``/etc/hosts`` file can be managed to contain definitions for specific hosts:

.. code-block:: yaml

    salt-master:
      host.present:
        - ip: 192.168.0.42

Or using the ``names`` directive, you can put several names for the same IP.
(Do not try one name with space-separated values).

.. code-block:: yaml

    server1:
      host.present:
        - ip: 192.168.0.42
        - names:
          - server1
          - florida

.. note::

    Changing the ``names`` in ``host.present`` does not cause an
    update to remove the old entry.

.. code-block:: yaml

    server1:
      host.present:
        - ip:
          - 192.168.0.42
          - 192.168.0.43
          - 192.168.0.44
        - names:
          - server1

You can replace all existing names for a particular IP address:

.. code-block:: yaml

    127.0.1.1:
      host.only:
        - hostnames:
          - foo.example.com
          - foo

Or delete all existing names for an address:

.. code-block:: yaml

    203.0.113.25:
        host.only:
          - hostnames: []

You can also include comments:

.. code-block:: yaml

    server1:
      host.present:
        - ip: 192.168.0.42
        - names:
          - server1
          - florida
        - comment: A very important comment

�N�Fcs��iddd�}t|t�s|g}td��g}t�}t�}t�}|���fdd�|D���r;|���fdd�|D�����D]�\}	}
|	|vrid|
vrh�|
dvrh|r[|�|	�f�q?|�d	g��d
�	�|	��q?d|
vr��|
dvr��r�d|
vr�|
d�kr�|�|	�f�q?�r�d|
vr�|�|	�f�q?|�d��d
|	�d��q?t
jjj
�|	�r�|�|	�f��r�|�|	�f�q?d|d<|�d��d
|	�d��q?|D]M\}	�tdr�d|d<|�d��d
|	�d��n%td|	��r�|�d��d
|	�d��nd|d<|�d��d
|	�d��q�|d�di��|	g����q�|D]M\}	�td�r4|�d|	�d
��d��n'td|	���rI|�d|	�d
��d��nd|d<|�d|	�d
��d���q|d�di��|	g�����q|D]Q\}	�td�r�d|d<|�d��d
|	�d ��n'td!|	���r�|�d"��d
|	�d��nd|d<|�d#��d
|	�d���qn|d�d$i��|	g�����qnd%�|�|d<|S)&a�
    Ensures that the named host is present with the given ip

    name
        The host to assign an ip to

    ip
        The ip addr(s) to apply to the host. Can be a single IP or a list of IP
        addresses.

    comment
        A comment to include for the host entry

        .. versionadded:: 3001

    clean
        Remove any entries which don't match those configured in the ``ip``
        option. Default is ``False``.

        .. versionadded:: 2018.3.4
    Tr��name�changes�result�commentzhosts.list_hostsc�g|]
}|�vr|�f�qS�r	��.0�addr)�	all_hostsrr	�D/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/host.py�
<listcomp>r�zpresent.<locals>.<listcomp>crr	r	r
)r
rr	rrur�aliases�warningsz�Host {0} present for IP address {1}. To get rid of this warning, either run this state with 'clean' set to True to remove {0} from {1}, or add {1} to the 'ip' argument.r�Host � (z) already presentFrzInvalid IP Address for �)�testNz) would be addedzhosts.add_hostzAdded host zFailed to add host rZaddedzComment for zhosts.set_commentzSet comment for host zFailed to add comment for host Z
comment_addedz) would be removed�
hosts.rm_host�
Removed host zFailed to remove host Zremoved�
)�
isinstance�list�__salt__�set�update�items�add�
setdefault�append�format�salt�utils�validate�netZip_addr�__opts__�join)r�iprZclean�ret�commentsZto_add�	to_removeZupdate_commentrZ	host_infor	)r
rrr�presentPs�

���� 
�
"r.cCs�|iddd�}t|t�s|g}g}|D]R}td||�s-d|d<|�d|�d|�d	��qtd
r>|�d|�d|�d��qtd||�r\d
|i|d<d|d<|�d|�d|�d��qd|d<|�d�qd�|�|d<|S)z�
    Ensure that the named host is absent

    name
        The host to remove

    ip
        The ip addr(s) of the host to remove
    Nrrzhosts.has_pairTrrrz) already absentrz) needs to be removedr�hostrrrFzFailed to remove hostrr)rrrr"r(r))rr*r+r,�_ipr	r	r�absent�s$

r1cCs�|iddd�}t|t�r|g}d�td|��}d�dd�|D��}||kr7d|�d	|�d
�|d<d|d
<|StdrKd|�d|�d|�d
�|d<|Std||�|d
<|d
scd�|||�|d<|Sd|�d|�d|�d
�|d<|||d�i|d<|S)a
    Ensure that only the given hostnames are associated with the
    given IP address.

    .. versionadded:: 2016.3.0

    name
        The IP address to associate with the given hostnames.

    hostnames
        Either a single hostname or a list of hostnames to associate
        with the given IP address in the given order.  Any other
        hostname associated with the IP address is removed.  If no
        hostnames are specified, all hostnames associated with the
        given IP address are removed.
    Nrr� zhosts.get_aliascss�|]}|��VqdS)N)�strip)r�xr	r	r�	<genexpr>s�zonly.<locals>.<genexpr>zIP address z already set to "�"rTrrz
Would change z from "z" to "zhosts.set_hostz4hosts.set_host failed to change {} from "{}" to "{}"zsuccessfully changed )�old�newr)r�strr)rr(r#)rZ	hostnamesr+r7r8r	r	r�only�s*
�r:)rF)
�__doc__�loggingZsalt.utils.validate.netr$�	getLogger�__name__�logr.r1r:r	r	r	r�<module>sH

{#