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

�
���^c@@sDdZddlmZmZmZddlZddlZddlZddlZ	ddl
Z	ddlZ	ddlm
Z
eje�Zd�Zddd�Zdddd�Zddd	�Zddd
�Zd�Zd�Zd
�Zdd�Zdd�Zedd�Zddd�Zedd�Z ded�Z!dS(u|
Compendium of generic DNS utilities.

.. note::

    Some functions in the ``dnsutil`` execution module depend on ``dig``.
i(tabsolute_importtprint_functiontunicode_literalsN(tsixcC@stS(u�
    Generic, should work on any platform (including Windows). Functionality
    which requires dependencies outside of Python do not belong in this module.
    (tTrue(((s8/usr/lib/python2.7/site-packages/salt/modules/dnsutil.pyt__virtual__su
/etc/hostscC@s�|s^y@tjjj|d��"}tjjj|j��}WdQXWq^tk
rZdSXni}xn|j�D]`}|s�qqn|j	d�r�qqn|j
�}|d}|d}|j|g�j|�qqW|S(ur
    Parse /etc/hosts file.

    CLI Example:

    .. code-block:: bash

        salt '*' dnsutil.parse_hosts
    urNuError: hosts data was not foundu#ii(
tsalttutilstfilestfopentstringutilst
to_unicodetreadt	Exceptiont
splitlinest
startswithtsplitt
setdefaulttextend(t	hostsfilethoststfp_t	hostsdicttlinetcompstiptaliases((s8/usr/lib/python2.7/site-packages/salt/modules/dnsutil.pytparse_hosts s"
%


cC@s�|jd�}td|�}||kr^x1|D]&}|||kr1|j|�q1q1Wn|sqdj|�Sdj|dj|��}tjjj|d��#}|j	tjj
j|��WdQXdj||�S(	u�
    Append a single line to the /etc/hosts file.

    CLI Example:

    .. code-block:: bash

        salt '*' dnsutil.hosts_append /etc/hosts 127.0.0.1 ad1.yuk.co,ad2.yuk.co
    u,Ru%No additional hosts were added to {0}u
{0} {1}u uaNu'The following line was added to {0}:{1}(RRtremovetformattjoinRRRR	twriteR
tto_str(Rtip_addrtentriest	host_listRthosttappend_lineR((s8/usr/lib/python2.7/site-packages/salt/modules/dnsutil.pythosts_append?s


"	c	C@satjjj|d��"}tjjj|j��}WdQX|jd�}tjjj|d���}x�|j�D]�}|s�|j	�j
d�r�|jtjjjdj
|���qsn|j�}x.|D]&}||dkr�|j|�q�q�Wt|�dkrs|jtjjjdj|���|jtjjjd	��qsqsWWdQXdS(
u�
    Remove a host from the /etc/hosts file. If doing so will leave a line
    containing only an IP address, then the line will be deleted. This function
    will leave comments and blank lines intact.

    CLI Examples:

    .. code-block:: bash

        salt '*' dnsutil.hosts_remove /etc/hosts ad1.yuk.co
        salt '*' dnsutil.hosts_remove /etc/hosts ad2.yuk.co,ad1.yuk.co
    urNu,uwu#u{0}
iu u
(RRRR	R
RRRRtstripRRR RRtlenR(	RR"RRR#tout_fileRRR$((s8/usr/lib/python2.7/site-packages/salt/modules/dnsutil.pythosts_remove[s
!%
%cC@s�|r]y@tjjj|d��"}tjjj|j��}WdQXWq]tk
rYq]Xn|sgdSi}d}x]|j�D]O}|j	d�}|dj
�}|s�q�n|j	�}|jd�r�|d||djdd	�<q�nd
|krd|krd}d	}n|dkro|d
j
|�7}d|kr�d}|jd
d	�jdd	�}qoq�nd|kr�|jd|d�j	�}n|j	�}d|kr}|ddkr�|jd�n|d|d<|d|d<|d|d<|djddd�|d<|d|d<t|d�|d<t|d�|d<t|d�|d<t|d �|d!<q�n|ddkr�|jd|d�n|djd�r�d"|kr�d#j
|d|d�|d<n|d$d"kr|jd"g�j|d�q�|d$d%krfd%|kr�|jd%g�ji|dd&6|dd'6�q�q�|dd,kr�i|dd*6|dd+6|j|di�|d<q�|d|j|d$i�|d<q�W|S(-u�
    Parses a zone file. Can be passed raw zone data on the API level.

    CLI Example:

    .. code-block:: bash

        salt ns1 dnsutil.parse_zone /var/lib/named/example.com.zone
    urNuError: Zone data was not foundusingleu;iu$iuu(u)umultiu {0}uORIGINu@uSOAuINuNETWORKiuSOURCEiu.uCONTACTiuSERIALiuREFRESHiuRETRYiuEXPIREi	uMINTTLuNSu{0}.{1}iuMXupriorityuhostuAuAAAAuTARGETuTTL(uAuAAAA(RRRR	R
RRR
RRR'RtreplaceRtpopt_to_secondstinserttendswithRtappend(tzonefiletzoneRtzonedicttmodeRRtmulti((s8/usr/lib/python2.7/site-packages/salt/modules/dnsutil.pyt
parse_zonezsx
%
	! !  )&cC@s�|j�}d|kr7t|jdd��d}njd|krbt|jdd��d}n?d|krwd}n*yt|�}Wntk
r�d}nX|dkr�d}n|S(u�
    Converts a time value to seconds.

    As per RFC1035 (page 45), max time is 1 week, so anything longer (or
    unreadable) will be set to one week (604800 seconds).
    uHuiuDi�QuWi�:	(tuppertintR+t
ValueError(ttimestrtseconds((s8/usr/lib/python2.7/site-packages/salt/modules/dnsutil.pyR-�s	

	cC@stjjjd�dk	S(u�
    The dig-specific functions have been moved into their own module, but
    because they are also DNS utilities, a compatibility layer exists. This
    function helps add that layer.
    udigN(RRtpathtwhichtNone(((s8/usr/lib/python2.7/site-packages/salt/modules/dnsutil.pyt_has_dig�scC@st�rtd|�SdS(u�
    Check that string ip_addr is a valid IP

    CLI Example:

    .. code-block:: bash

        salt ns1 dnsutil.check_ip 127.0.0.1
    udig.check_ipu<This function requires dig, which is not currently available(R?t__salt__(R!((s8/usr/lib/python2.7/site-packages/salt/modules/dnsutil.pytcheck_ip�s
	cC@s�t�rtd||�S|dkr�yDgtj|dtjdtj�D]}|dd^qK}|SWq�tjk
r�dj|�SXndS(u�
    Return the A record(s) for ``host``.

    Always returns a list.

    CLI Example:

    .. code-block:: bash

        salt ns1 dnsutil.A www.google.com
    udig.AiiuUnable to resolve {0}u<This function requires dig, which is not currently availableN(	R?R@R>tsockettgetaddrinfotAF_INETtSOCK_RAWtgaierrorR(R$t
nameservertsockt	addresses((s8/usr/lib/python2.7/site-packages/salt/modules/dnsutil.pytA�s	<cC@s�t�rtd||�S|dkr�yDgtj|dtjdtj�D]}|dd^qK}|SWq�tjk
r�dj|�SXndS(u�
    Return the AAAA record(s) for ``host``.

    Always returns a list.

    .. versionadded:: 2014.7.5

    CLI Example:

    .. code-block:: bash

        salt ns1 dnsutil.AAAA www.google.com
    udig.AAAAiiuUnable to resolve {0}u<This function requires dig, which is not currently availableN(	R?R@R>RBRCtAF_INET6RERFR(R$RGRHRI((s8/usr/lib/python2.7/site-packages/salt/modules/dnsutil.pytAAAAs	<cC@s!t�rtd|||�SdS(u�
    Return a list of IPs of the nameservers for ``domain``

    If 'resolve' is False, don't resolve names.

    CLI Example:

    .. code-block:: bash

        salt ns1 dnsutil.NS google.com

    udig.NSu<This function requires dig, which is not currently available(R?R@(tdomaintresolveRG((s8/usr/lib/python2.7/site-packages/salt/modules/dnsutil.pytNS-s
	uSPFcC@s!t�rtd|||�SdS(u^
    Return the allowed IPv4 ranges in the SPF record for ``domain``.

    If record is ``SPF`` and the SPF record is empty, the TXT record will be
    searched automatically. If you know the domain uses TXT and not SPF,
    specifying that will save a lookup.

    CLI Example:

    .. code-block:: bash

        salt ns1 dnsutil.SPF google.com
    udig.SPFu<This function requires dig, which is not currently available(R?R@(RMtrecordRG((s8/usr/lib/python2.7/site-packages/salt/modules/dnsutil.pytSPF@s	cC@s!t�rtd|||�SdS(u
    Return a list of lists for the MX of ``domain``.

    If the 'resolve' argument is True, resolve IPs for the servers.

    It's limited to one IP, because although in practice it's very rarely a
    round robin, it is an acceptable configuration and pulling just one IP lets
    the data be similar to the non-resolved version. If you think an MX has
    multiple IPs, don't use the resolver here, resolve them in a separate step.

    CLI Example:

    .. code-block:: bash

        salt ns1 dnsutil.MX google.com
    udig.MXu<This function requires dig, which is not currently available(R?R@(RMRNRG((s8/usr/lib/python2.7/site-packages/salt/modules/dnsutil.pytMXTs	ucC@s�i}d}|r(|dj|�7}ntdd|�}tjd�}|sZ|pY|S|r�||kr�tjt|�d�}n|}tdd|d|�|S(	u#
    Return, store and update a dns serial for your zone files.

    zone: a keyword for a specific zone

    update: store an updated version of the serial in a grain

    If ``update`` is False, the function will retrieve an existing serial or
    return the current date if no serial is stored. Nothing will be stored

    If ``update`` is True, the function will set the serial to the current date
    if none exist or if the existing serial is for a previous date. If a serial
    for greater than the current date is already stored, the function will
    increment it.

    This module stores the serial in a grain, you can explicitly set the
    stored value as a grain named ``dnsserial_<zone_name>``.

    CLI Example:

    .. code-block:: bash

        salt ns1 dnsutil.serial example.com
    u	dnsserialu_{0}u
grains.gettkeyu%Y%m%d01iu
grains.setvaltval(RR@ttimetstrftimeRt	text_typeR8(R2tupdatetgrainsRStstoredtpresenttcurrent((s8/usr/lib/python2.7/site-packages/salt/modules/dnsutil.pytserialks
("t__doc__t
__future__RRRtloggingRBRUtsalt.utils.filesRtsalt.utils.pathtsalt.utils.stringutilstsalt.extRt	getLoggert__name__tlogRR>RR&R*R6R-R?RARJRLRRORQtFalseRRR](((s8/usr/lib/python2.7/site-packages/salt/modules/dnsutil.pyt<module>s.	N				

Zerion Mini Shell 1.0