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

�
���^c@@s3dZddlmZmZmZddlZddlZddlZddl	Zddl
ZddlmZm
Z
ddlmZeje�ZdZd�Zd�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zded�Z d�Z!d�Z"d�Z#d�Z$d�Z%dS(u1
The networking module for Windows based systems
i(tabsolute_importtunicode_literalstprint_functionN(tCommandExecutionErrortSaltInvocationError(trangeuipcC@s tjjj�rtStdfS(u0
    Confine this module to Windows systems
    u3Module win_ip: module only works on Windows systems(tsalttutilstplatformt
is_windowst__virtualname__tFalse(((s7/usr/lib/python2.7/site-packages/salt/modules/win_ip.pyt__virtual__scC@sdddddg}td|dt�j�}i}d}d}x�|D]�}|j�}|std}d}qJnd|kr�|jd	�jd	d
�\}}i}|||<qJnd|kr�|r�|j|�qJtj	d|�qJn|jdd
�\}}	|j�}|	j�}	|j
�}
d
|
ksCd|
krcg}|||<|j|	�qJd|
kr�|jdg�ji|	|6�qJd|
kr�|	jdd�\}}}|dd}
|j�|
d<|j�jd�|
d<qJ|	||<qJW|S(u&
    Return all interface configs
    unetshu	interfaceuipushowuconfigucmd.runtpython_shelluConfiguration for interfaceu"iu:uCannot parse "%s"udns serversuwins serversu
ip addressuip_addrsu
subnet prefixu ii����uSubnetu)uNetmaskN(
t__salt__Rt
splitlinestNonetstriptrstriptsplittappendtlogtwarningtlowert
setdefaulttlstrip(tcmdtlinestrett
current_ifacetcurrent_ip_listtlinet_tifacetkeytvaltlkeytsubnettnetmasktlast_ip((s7/usr/lib/python2.7/site-packages/salt/modules/win_ip.pyt_interface_configs%sL
!

#cC@s)dddddg}td|dt�S(u�
    Return raw configs for all interfaces

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.raw_interface_configs
    unetshu	interfaceuipushowuconfigucmd.runR
(RR(R((s7/usr/lib/python2.7/site-packages/salt/modules/win_ip.pytraw_interface_configs]s
cC@st�S(u�
    Return configs for all interfaces

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.get_all_interfaces
    (R((((s7/usr/lib/python2.7/site-packages/salt/modules/win_ip.pytget_all_interfacesks
cC@st�j|i�S(u�
    Return the configuration of a network interface

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.get_interface 'Local Area Connection'
    (R(tget(R!((s7/usr/lib/python2.7/site-packages/salt/modules/win_ip.pyt
get_interfacexs
cC@s�dddddj|�g}t}xJtd|dt�j�D],}d|krAt}|j�dd	kSqAW|s�td
j|���ntS(u�
    Returns ``True`` if interface is enabled, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.is_enabled 'Local Area Connection #2'
    unetshu	interfaceushowuname={0}ucmd.runR
uConnect state:i����u	ConnecteduInterface '{0}' not found(tformatRRRtTrueRR(R!Rtiface_foundR((s7/usr/lib/python2.7/site-packages/salt/modules/win_ip.pyt
is_enabled�s
#cC@st|�S(u�
    Returns ``True`` if interface is disabled, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.is_disabled 'Local Area Connection #2'
    (R0(R!((s7/usr/lib/python2.7/site-packages/salt/modules/win_ip.pytis_disabled�s
cC@sOt|�rtSdddddj|�dg}td|dt�t|�S(u�
    Enable an interface

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.enable 'Local Area Connection #2'
    unetshu	interfaceusetuname={0}u
admin=ENABLEDucmd.runR
(R0R.R-RR(R!R((s7/usr/lib/python2.7/site-packages/salt/modules/win_ip.pytenable�s
	cC@sOt|�rtSdddddj|�dg}td|dt�t|�S(u�
    Disable an interface

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.disable 'Local Area Connection #2'
    unetshu	interfaceusetuname={0}uadmin=DISABLEDucmd.runR
(R1R.R-RR(R!R((s7/usr/lib/python2.7/site-packages/salt/modules/win_ip.pytdisable�s
	cC@sCtjjjj|�s0tdj|���ntjjj|�S(u�
    Convenience function to convert the netmask to the CIDR subnet length

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.get_subnet_length 255.255.255.0
    u'{0}' is not a valid netmask(	RRtvalidatetnetR&RR-tnetworktget_net_size(tmask((s7/usr/lib/python2.7/site-packages/salt/modules/win_ip.pytget_subnet_length�s
c	C@s�dd�}tjjjj|�s<tdj|���n|rstjjjj|�rstdj|���nd|kr�|d7}n|r�|||�r�tdj||���ndd	d
g}|r�|jd�n
|jd�|j	d
dj|�g�|s |jd�n|jdj|��|rU|jdj|��nt
d|dt�}|ddkr�tdj|d���n|||dd�}|s�iSi|d6}|r�||d<n|S(u�
    Set static IP configuration on a Windows NIC

    iface
        The name of the interface to manage

    addr
        IP address with subnet length (ex. ``10.1.2.3/24``). The
        :mod:`ip.get_subnet_length <salt.modules.win_ip.get_subnet_length>`
        function can be used to calculate the subnet length from a netmask.

    gateway : None
        If specified, the default gateway will be set to this value.

    append : False
        If ``True``, this IP address will be added to the interface. Default is
        ``False``, which overrides any existing configuration for the interface
        and sets ``addr`` as the only address on the interface.

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.set_static_ip 'Local Area Connection' 10.1.2.3/24 gateway=10.1.2.1
        salt -G 'os_family:Windows' ip.set_static_ip 'Local Area Connection' 10.1.2.4/24 append=True
    icS@s�|jdd�\}}tjjj|�}xht|�D]Z}xDt|�jdg�D]*}|d|krY|d|krY|SqYWtj	d�q:WiS(Nu/iuip_addrsu
IP AddressuNetmask(
trsplitRRR6tcidr_to_ipv4_netmaskRR,R+ttimetsleep(R!taddrttimeouttiptcidrR&tidxtaddrinfo((s7/usr/lib/python2.7/site-packages/salt/modules/win_ip.pyt
_find_addr�suInvalid address '{0}'uInvalid default gateway '{0}'u/u/32u/Address '{0}' already exists on interface '{1}'unetshu	interfaceuipuaddusetuaddressuname={0}u
source=staticuaddress={0}ugateway={0}ucmd.run_allR
uretcodeiuUnable to set IP address: {0}ustderrR?i
uAddress InfouDefault Gateway(RRR4R5t	ipv4_addrRR-RRtextendRR(	R!R>tgatewayRRDRtresulttnew_addrR((s7/usr/lib/python2.7/site-packages/salt/modules/win_ip.pyt
set_static_ip�sB



cC@sAddddd|dg}td|dt�i|d	6d
d6S(u�
    Set Windows NIC to get IP from DHCP

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.set_dhcp_ip 'Local Area Connection'
    unetshu	interfaceuipusetuaddressudhcpucmd.runR
u	InterfaceuYesuDHCP enabled(RR(R!R((s7/usr/lib/python2.7/site-packages/salt/modules/win_ip.pytset_dhcp_ip3s
cG@s�|dks(t|d�j�dkr:i|d6dd6St|d�j�dkr�tjd�dd	d
ddd
j|�ddg}td|dt�i|d6gd6Sd}x�|D]�}|dkr#dd	d
ddd
j|�ddj|�dg	}td|dt�|d}q�dd	d
ddd
j|�dj|�dj|�g}td|dt�|d}q�Wi|d6|d6S(u�
    Set static DNS configuration on a Windows NIC

    Args:

        iface (str): The name of the interface to set

        addrs (*):
            One or more DNS servers to be added. To clear the list of DNS
            servers pass an empty list (``[]``). If undefined or ``None`` no
            changes will be made.

    Returns:
        dict: A dictionary containing the new DNS settings

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.set_static_dns 'Local Area Connection' '192.168.1.1'
        salt -G 'os_family:Windows' ip.set_static_dns 'Local Area Connection' '192.168.1.252' '192.168.1.253'
    iunoneu	Interfaceu
No Changesu
DNS Serveru[]uClearing list of DNS serversunetshu	interfaceuipusetudnsuname={0}u
source=staticuaddress=noneucmd.runR
iuaddress={0}uregister=primaryuaddu	index={0}((tstrRRtdebugR-RR(R!taddrsRt
addr_indexR>((s7/usr/lib/python2.7/site-packages/salt/modules/win_ip.pytset_static_dnsBs6(
	
	
cC@sAddddd|dg}td|dt�i|d	6d
d6S(u�
    Set DNS source to DHCP on Windows

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.set_dhcp_dns 'Local Area Connection'
    unetshu	interfaceuipusetudnsudhcpucmd.runR
u	InterfaceuDHCPu
DNS Server(RR(R!R((s7/usr/lib/python2.7/site-packages/salt/modules/win_ip.pytset_dhcp_dnsxs
cC@s-t|�t|�i|d6dd6dd6S(u�
    Set both IP Address and DNS to DHCP

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.set_dhcp_all 'Local Area Connection'
    u	InterfaceuDHCPu
DNS ServeruYesuDHCP enabled(RKRQ(R!((s7/usr/lib/python2.7/site-packages/salt/modules/win_ip.pytset_dhcp_all�s


c	C@sgyCttd�tddddddgdt�j�D���SWntk
rbtd	��nXd
S(u�
    Set DNS source to DHCP on Windows

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.get_default_gateway
    cs@s+|]!}d|kr|j�dVqdS(uDefault Gateway:i����N(R(t.0tx((s7/usr/lib/python2.7/site-packages/salt/modules/win_ip.pys	<genexpr>�sucmd.rununetshu	interfaceuipushowuconfigR
uUnable to find default gatewayN(tnexttiterRRRt
StopIterationR(((s7/usr/lib/python2.7/site-packages/salt/modules/win_ip.pytget_default_gateway�s


(&t__doc__t
__future__RRRtloggingR<tsalt.utils.networkRtsalt.utils.platformtsalt.utils.validate.nettsalt.exceptionsRRtsalt.ext.six.movesRt	getLoggert__name__RR
RR(R)R*R,R0R1R2R3R9RRRJRKRPRQRRRX(((s7/usr/lib/python2.7/site-packages/salt/modules/win_ip.pyt<module>s4			8		
	
		
			S		6		

Zerion Mini Shell 1.0