%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/states/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/states/win_network.pyo

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddl	Zddl
mZddlm
Z
ddlmZeje�ZdZd	Zd
�Zd�Zd�Zd
�Zddddded�ZdS(u	
Configuration of network interfaces on Windows hosts
====================================================

.. versionadded:: 2014.1.0

This module provides the ``network`` state(s) on Windows hosts. DNS servers, IP
addresses and default gateways can currently be managed.

Below is an example of the configuration for an interface that uses DHCP for
both DNS servers and IP addresses:

.. code-block:: yaml

    Local Area Connection #2:
      network.managed:
        - dns_proto: dhcp
        - ip_proto: dhcp

.. note::

    Both the ``dns_proto`` and ``ip_proto`` arguments are required.

Static DNS and IP addresses can be configured like so:

.. code-block:: yaml

    Local Area Connection #2:
      network.managed:
        - dns_proto: static
        - dns_servers:
          - 8.8.8.8
          - 8.8.4.4
        - ip_proto: static
        - ip_addrs:
          - 10.2.3.4/24

.. note::

    IP addresses are specified using the format
    ``<ip-address>/<subnet-length>``. Salt provides a convenience function
    called :mod:`ip.get_subnet_length <salt.modules.win_ip.get_subnet_length>`
    to calculate the subnet length from a netmask.

Optionally, if you are setting a static IP address, you can also specify the
default gateway using the ``gateway`` parameter:

.. code-block:: yaml

    Local Area Connection #2:
      network.managed:
        - dns_proto: static
        - dns_servers:
          - 8.8.8.8
          - 8.8.4.4
        - ip_proto: static
        - ip_addrs:
          - 10.2.3.4/24
        - gateway: 10.2.3.1
i(tabsolute_importtunicode_literalstprint_functionN(trange(tCommandExecutionError(tsixustaticudhcpunetworkcC@s&tjjj�r"dtkr"tStS(ub
    Confine this module to Windows systems with the required execution module
    available.
    uip.get_interface(tsalttutilstplatformt
is_windowst__salt__t__virtualname__tFalse(((s;/usr/lib/python2.7/site-packages/salt/states/win_network.pyt__virtual__TscC@s�g}|dkr1|dk	r�|jd�q�n�t|�j�dkrLnxt|t�sk|jd�nYg|D]$}tjjj	j
|�sr|^qr}|r�|jdjdj|���n|dkr|dk	r�|jd�n|dk	r�|jd	�q�n�|s!|jd
�n�t|t�s@|jd�n�g|D]$}tjjj	j
|�sG|^qG}|r�|jdjdj|���n|dk	r�tjjj	j
|�s�|jd
j|��q�n|S(uo
    Ensure that the configuration passed is formatted correctly and contains
    valid IP addresses, etc.
    udhcpuJThe dns_servers param cannot be set if unless dns_proto is set to 'static'unoneu[]u1The dns_servers param must be formatted as a listuInvalid DNS server IPs: {0}u, uFThe ip_addrs param cannot be set if unless ip_proto is set to 'static'u@A gateway IP cannot be set if unless ip_proto is set to 'static'u0The ip_addrs param is required to set static IPsu.The ip_addrs param must be formatted as a listu)The following static IPs are invalid: {0}uGateway IP {0} is invalidN(unoneu[](
tNonetappendtstrtlowert
isinstancetlistRRtvalidatetnett	ipv4_addrtformattjoin(t	dns_prototdns_serverstip_prototip_addrstgatewayterrorstxtbad_ips((s;/usr/lib/python2.7/site-packages/salt/states/win_network.pyt	_validate^sJ


$




$cC@s;g|D]0}dj|d|djdd�d�^qS(uq
    Extracts a list of IP/CIDR expressions from a list of addrdicts, as
    retrieved from ip.get_interface
    u{0}/{1}u
IP AddressuSubnetu/ii����(Rtrsplit(taddrsR((s;/usr/lib/python2.7/site-packages/salt/states/win_network.pyt_addrdict_to_ip_addrs�scC@s�i}d|krdnd}|dkr�t|dt�rJ|d}n
|dg}t|pfdg�t|�kr�||d<q�nVd|kr�|d}|dkr�t|p�dg�t|�kr�||d<q�q�n|ddkr�dnd}	t|jd	g��}
|jd
�}||kr:||d<n||	krS||d<nt|p_g�t|
�kr�|dkr�||d	<q�n||kr�|dkr�||d
<q�n|S(u�
    Compares the current interface against the desired configuration and
    returns a dictionary describing the changes that need to be made.
    u!Statically Configured DNS ServersustaticudhcpuNoneudns_serversu#DNS servers configured through DHCPuDHCP enableduNouip_addrsuDefault Gatewayu	dns_protouip_protougateway(RRtsetR$tget(tcurRRRRRtchangest
cur_dns_prototcur_dns_serverstcur_ip_prototcur_ip_addrstcur_gateway((s;/usr/lib/python2.7/site-packages/salt/states/win_network.pyt_changes�s8

!
!

c
K@smi|d6id6td6dj|�d6}tj|�j�}tj|�j�}g}	|tkr�t|d<|	jdjdjt���n|tkr�|	jdjdjt���n|	r�t|d<d	j|	�|d<|Syt	d
|�}
Wnt
k
rt}
nX|s�|
r�tdrLd0|d<dj|�|d<q�t	d
|�|d<|ds�dj|�|d<q�n|dcd7<|S|
s�tdr�d0|d<dj|�|d<q�t	d|�s�t|d<dj|�|d<|Snt
|||||�}	|	rCt|d<djdj|	��|d<|St	d|�}|szt|d<dj|�|d<|St||||||�}t|�j�dkr�|jdd0�n|s�|StdrGg}
d|kr|
jdj|d��n|dkrgd|krgt|d�dkrA|
jd�qg|
jdjdj|d���nd|kr�|
jd j|d��n|dkrd!|kr�|
jd"jdj|d!���nd#|kr|d#d0kr�|
jd$�q|
jd%j|d#��qnd0|d<d&j|dj|
��|d<|S|jd�d'krmt	d(|�nJd|kr�t|d�dkr�gg|d<nt	d)||d�n|jd�d'kr�t	d*|�n|jd!�s|jd#�s|jd�dkr�|jd#�r<|jd!�r<||d!<n|jd�dkrn|jd!�rn||d!<nxztt|d!��D]_}|dkr�t	d+||d!|d,|d-t�q�t	d+||d!|d,d0d-t�q�Wnt	d|�}tjjj||�|d<t||||||�rRt|d<d.j|�|d<nd/j|�|d<|Sd0S(1uR
    Ensure that the named interface is configured properly.

    Args:

        name (str):
            The name of the interface to manage

        dns_proto (str): None
            Set to ``static`` and use the ``dns_servers`` parameter to provide a
            list of DNS nameservers. set to ``dhcp`` to use DHCP to get the DNS
            servers.

        dns_servers (list): None
            A list of static DNS servers. To clear the list of DNS servers pass
            an empty list (``[]``). ``None`` will make no changes.

        ip_proto (str): None
            Set to ``static`` and use the ``ip_addrs`` and (optionally)
            ``gateway`` parameters to provide a list of static IP addresses and
            the default gateway. Set to ``dhcp`` to use DHCP.

        ip_addrs (list): None
            A list of static IP addresses with netmask flag, ie: 192.168.0.11/24

        gateway (str): None
            The gateway to set for the interface

        enabled (bool): True
            Set to ``False`` to ensure that this interface is disabled.

    Returns:
        dict: A dictionary of old and new settings

    Example:

    .. code-block:: yaml

        Ethernet1:
          network.managed:
            - dns_proto: static
            - dns_servers:
              - 8.8.8.8
              - 8.8.8.4
            - ip_proto: static
            - ip_addrs:
              - 192.168.0.100/24

    Clear DNS entries example:

    .. code-block:: yaml

        Ethernet1:
          network.managed:
            - dns_proto: static
            - dns_servers: []
            - ip_proto: dhcp
    unameuchangesuresultuInterface '{0}' is up to dateucommentu+dns_proto must be one of the following: {0}u, u*ip_proto must be one of the following: {0}u
u
ip.is_enabledutestu Interface '{0}' will be disabledu
ip.disableu!Failed to disable interface '{0}'u (already disabled)uInterface '{0}' will be enabledu	ip.enableu0Failed to enable interface '{0}' to make changesu;The following SLS configuration errors were detected:
- {0}u
- uip.get_interfaceu7Unable to get current configuration for interface '{0}'unoneudns_serversu	dns_protou$DNS protocol will be changed to: {0}ustaticiu'The list of DNS servers will be clearedu-DNS servers will be set to the following: {0}uip_protou#IP protocol will be changed to: {0}uip_addrsu.IP addresses will be set to the following: {0}ugatewayuDefault gateway will be removedu"Default gateway will be set to {0}u<The following changes will be made to interface '{0}':
- {1}udhcpuip.set_dhcp_dnsuip.set_static_dnsuip.set_dhcp_ipuip.set_static_ipRRu@Failed to set desired configuration settings for interface '{0}'u6Successfully updated configuration for interface '{0}'N(tTrueRRt	text_typeRt
__VALID_PROTORRRR
Rt__opts__RR!R.RtpoptlenR&RRRtdatat
compare_dicts(tnameRRRRRtenabledtkwargstretRtcurrently_enabledtoldR(tcommentstidxtnew((s;/usr/lib/python2.7/site-packages/salt/states/win_network.pytmanaged�sB













	

3
%



(ustaticudhcp(t__doc__t
__future__RRRtloggingtsalt.utils.dataRtsalt.utils.platformtsalt.utils.validate.nettsalt.ext.six.movesRtsalt.exceptionsRtsalt.extRt	getLoggert__name__tlogR1RR
R!R$R.RR/R@(((s;/usr/lib/python2.7/site-packages/salt/states/win_network.pyt<module>=s*	
	?		*

Zerion Mini Shell 1.0