%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/hosts.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddl	j
jZddlZddl
mZddlmZd�Zd�Zd�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�ZdS(u*
Manage the information in the hosts file
i(tabsolute_importtprint_functiontunicode_literalsN(tsix(trangecC@s=ytdSWn*tk
r8tdd�td<tdSXdS(u7
    Return the path to the appropriate hosts file
    uhosts.__get_hosts_filenameu
config.optionu
hosts.fileN(t__context__tKeyErrort__salt__(((s6/usr/lib/python2.7/site-packages/salt/modules/hosts.pyt__get_hosts_filenames

cC@sVt�}|dkrd}ntjj|�sRtjjj|d��WdQXn|S(uX
    Wrapper of __get_hosts_filename but create host file if it
    does not exist.
    uuwN(	RtNonetostpathtexiststsalttutilstfilestfopen(thfn((s6/usr/lib/python2.7/site-packages/salt/modules/hosts.pyt_get_or_create_hostfile"s			cC@s}ytdSWnjtk
rxd}t�}tj�}y�tjjj|���}x�|D]�}tjj	j
|�j�}|s�qYn|jd�r�|j
dj|�g�j|�|d7}qYnd|kr�||jd� j�}n|j�}|jd�}|j
|g�j|�qYWWdQXWn9ttfk
ri}tjjj||dtj�|SX|td<|SXdS(uG
    Return the hosts found in the hosts file in as an OrderedDict
    uhosts._list_hostsiu#ucomment-{0}iNtignore(RRRtodicttOrderedDictR
RRRtstringutilst
to_unicodetstript
startswitht
setdefaulttformattappendtindextsplittpoptextendtIOErrortOSErrortprocess_read_exceptionterrnotENOENT(tcountRtrettifiletlinetcompstiptexc((s6/usr/lib/python2.7/site-packages/salt/modules/hosts.pyt_list_hosts0s4
	
"
'
cC@s
tt��S(u�
    Return the hosts found in the hosts file in this format::

        {'<ip addr>': ['alias1', 'alias2', ...]}

    CLI Example:

    .. code-block:: bash

        salt '*' hosts.list_hosts
    (tdictR-(((s6/usr/lib/python2.7/site-packages/salt/modules/hosts.pyt
list_hostsSs
cC@s<t�}|sdSx"|D]}|||kr|SqWdS(u�
    Return the ip associated with the named host

    CLI Example:

    .. code-block:: bash

        salt '*' hosts.get_ip <hostname>
    u(R-(thostthoststaddr((s6/usr/lib/python2.7/site-packages/salt/modules/hosts.pytget_ipcs
	
cC@s!t�}||kr||SgS(uB
    Return the list of aliases associated with an ip

    Aliases (host names) are returned in the order in which they
    appear in the hosts file.  If there are no aliases associated with
    the IP, an empty list is returned.

    CLI Example:

    .. code-block:: bash

        salt '*' hosts.get_alias <ip addr>
    (R-(R+R1((s6/usr/lib/python2.7/site-packages/salt/modules/hosts.pyt	get_aliasxs	cC@s4t�}y|||kSWntk
r/tSXdS(u�
    Return true if the alias is set

    CLI Example:

    .. code-block:: bash

        salt '*' hosts.has_pair <ip> <alias>
    N(R-RtFalse(R+taliasR1((s6/usr/lib/python2.7/site-packages/salt/modules/hosts.pythas_pair�s

	
cC@s�t�}t}tjj|�s%tStjdd�tj	j
j|d|tj�}|j
�snd}ntj	jj|d��}|j�}WdQXx�t|�D]�\}}||j
�}	|	s�q�n|	jd�r�q�n|	j�}
|
dtj	j
j|�kr�|s)|||<t}q6d||<q�q�Wtj	j
jtj�}|s�|r�|dj|�r�|dc|7<n|}|j|�ntj	jj|d	��}
|
j|�WdQXtS(
u�
    Set the host entry in the hosts file for the given ip, this will overwrite
    any previous entry for the given ip

    .. versionchanged:: 2016.3.0
        If ``alias`` does not include any host names (it is the empty
        string or contains only whitespace), all entries for the given
        IP address are removed.

    CLI Example:

    .. code-block:: bash

        salt '*' hosts.set_host <ip> <alias>
    uhosts._list_hostsu		turbNt#ii����uwb(RR5R
RtisfileRRR	R
RRtto_bytestlinesepRRRt	readlinest	enumerateRRtTruetendswithRt
writelines(R+R6Rtovrtline_to_addtfp_tlinestindt_ttmplineR*t
linesep_bytesR)tofile((s6/usr/lib/python2.7/site-packages/salt/modules/hosts.pytset_host�s@		
	cC@s�t||�stStjdd�t�}tjjj	|d��}|j
�}WdQXxt|�D]\}}||j�}|s�qfn|j
d�r�qfn|j�}tjjj|�}	tjjj|�}
|d|	krf|dd}x2|dD]&}||
krqn||d7}qW|j�|	krKd	||<qn|tjjjtj�||<qfqfWtjjj	|d
��}
|
j|�WdQXtS(u�
    Remove a host entry from the hosts file

    CLI Example:

    .. code-block:: bash

        salt '*' hosts.rm_host <ip> <alias>
    uhosts._list_hostsurbNR9is		it R8uwb(R7R?RRR	RR
RRRR=R>RRRRR;R
R<RA(R+R6RRDRERFRGRHR*tb_iptb_aliastnewlinetexistingRJ((s6/usr/lib/python2.7/site-packages/salt/modules/hosts.pytrm_host�s6
	
'cC@s�t�}tjj|�stSt||�r2tSt�}tj	dd�t}xrtj|�D]a\}}xRt
t|��D]>}||jd�r�||kr�|j||�t}q�q�WqaW|s�|j|g�j|�nt|�tS(u�
    Add a host to an existing entry, if the entry is not in place then create
    it with the given host

    CLI Example:

    .. code-block:: bash

        salt '*' hosts.add_host <ip> <alias>
    uhosts._list_hostsu#N(RR
RR:R5R7R?R-RRR	Rt	iteritemsRtlenRtinsertRRt_write_hosts(R+R6RR1tinsertedtithtj((s6/usr/lib/python2.7/site-packages/salt/modules/hosts.pytadd_hosts"		
c
C@s�g}xotj|�D]^\}}|rg|jd�rIdj|�}qgdj|dj|��}n|j|�qWt�}tjj	j
|d��Y}xO|D]G}|j�r�|jtjj
j|j�tjtj���q�q�WWdQXdS(Nucommentuu{0}		{1}u uw+(RRRRtjoinRRRR
RRRRtwriteRtto_strt	text_typeR
R<(R1RER+taliasesR)RRJ((s6/usr/lib/python2.7/site-packages/salt/modules/hosts.pyRU%s	
(t__doc__t
__future__RRRR$R
tsalt.utils.filesR
tsalt.utils.odictRRtsalt.utils.stringutilstsalt.extRtsalt.ext.six.movesRRRR-R/R3R4R7RKRQRZRU(((s6/usr/lib/python2.7/site-packages/salt/modules/hosts.pyt<module>s&			#					:	+	#

Zerion Mini Shell 1.0