File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/states/__pycache__/win_network.cpython-310.pyc
Back
o ;j�8 � @ s| d Z ddlZddlZddlZddlZddlmZ e�e �Z dZdZdd� Z dd � Zd d� Zdd � Z ddd�ZdS )a 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 � N)�CommandExecutionError)�static�dhcp�networkc C s t jj�� rdtv rtS dS )zb Confine this module to Windows systems with the required execution module available. �ip.get_interface)Fzip module could not be loaded)�salt�utils�platformZ is_windows�__salt__�__virtualname__� r r �K/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/win_network.py�__virtual__N s r c C s g }| dkr|dur|� d� n(t|��� dv rnt|t�s$|� d� ndd� |D �}|r8|� d�d �|��� |dkrP|durE|� d � |durN|� d� |S |sY|� d� |S t|t�se|� d � |S dd� |D �}|ry|� d�d �|��� |dur�tjj j �|�s�|� d|� d�� |S )zo Ensure that the configuration passed is formatted correctly and contains valid IP addresses, etc. r NzJThe dns_servers param cannot be set if unless dns_proto is set to 'static')�nonez[]z1The dns_servers param must be formatted as a listc S � g | ]}t jjj�|�s|�qS r �r r �validate�net� ipv4_addr��.0�xr r r � <listcomp>k s ��z_validate.<locals>.<listcomp>zInvalid DNS server IPs: {}�, zFThe ip_addrs param cannot be set if unless ip_proto is set to 'static'z@A gateway IP cannot be set if unless ip_proto is set to 'static'z0The ip_addrs param is required to set static IPsz.The ip_addrs param must be formatted as a listc S r r r r r r r r � s z(The following static IPs are invalid: {}zGateway IP z is invalid)�append�str�lower� isinstance�list�format�joinr r r r r )� dns_proto�dns_servers�ip_proto�ip_addrs�gateway�errorsZbad_ipsr r r � _validateX sV �� ���� � ���r'