HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/suse_ip.cpython-310.pyc
o

�N�g8��@s�dZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
mZe�e
�Zeje�ej�ejjjd��d�ZdZdddd	dd
d�ZdZd
ZdZdZdZdZdd�Zdd�Z dd�Z!dd�Z"dd�Z#dd�Z$dd�Z%d d!�Z&d"d#�Z'd$d%�Z(d&d'�Z)d(d)�Z*d*d+�Z+d,d-�Z,d.d/�Z-d0d1�Z.d2d3�Z/d4d5�Z0d6d7�Z1d8d9�Z2d:d;�Z3d<d=�Z4d>d?�Z5d@dA�Z6dBdC�Z7dDdE�Z8dFdG�Z9dHdI�Z:dJdK�Z;dLdM�Z<dNdO�Z=d^dPdQ�Z>dRdS�Z?d^dTdU�Z@dVdW�ZAdXdY�ZBdZd[�ZCd\d]�ZDdS)_zG
The networking module for SUSE based distros

.. versionadded:: 3005

�N)�CommandExecutionErrorZsuse_ip)�loader�ip�0Z16�1�layer2)�	ad_selectZ	tx_queues�	lacp_rateZ	max_bonds�use_carrier�xmit_hash_policyz/etc/sysconfig/networkz/etc/sysconfig/network/configz/etc/sysconfig/network/routes)�yes�on�truerT)�no�off�falserF)�eth�bond�alias�cloneZipsecZdialup�bridge�slave�vlan�ipip�ibcCstddkrtSdS)z3
    Confine this module to SUSE based distros
    Z	os_familyZSuse)FziThe suse_ip execution module cannot be loaded: this module is only available on SUSE based distributions.)�
__grains__�__virtualname__�rr�H/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/suse_ip.py�__virtual__JsrcCs2t|t�r|f}d}|�||d�dd�|D���S)�c
    Build an appropriate error message from a given option and
    a list of expected values.
    z;Invalid option -- Interface: {}, Option: {}, Expected: [{}]�|cs��|]}t|�VqdS�N��str��.0�errr�	<genexpr>_��z#_error_msg_iface.<locals>.<genexpr>��
isinstancer%�format�join��iface�option�expected�msgrrr�_error_msg_ifaceWs
r4cCsd}|�|||�S)r zAInvalid option -- Route interface: {}, Option: {}, Expected: [{}])r-r/rrr�_error_msg_routesbsr5cCst�d|||�dS)Nz:Using default option -- Interface: %s Option: %s Value: %s��log�info)r0�opt�valuerrr�_log_default_ifaceks�r;cCs0t|t�r|f}d}|�|d�dd�|D���S)r z6Invalid network setting -- Setting: {}, Expected: [{}]r!csr"r#r$r&rrrr)yr*z%_error_msg_network.<locals>.<genexpr>r+�r1r2r3rrr�_error_msg_networkqs
r=cCst�d||�dS)Nz/Using existing setting -- Setting: %s Value: %sr6)r9r:rrr�_log_default_network|sr>cCs�t|�}i}|r?|D]4}|��}|r|�d�s|�d�rq
dd�|�dd�D�}t|�dkr/q
|\}}tjj�|�||�	�<q
|S)N�!�#cSsg|]}|���qSr)�rstrip)r'�prrr�
<listcomp>�sz&_parse_suse_config.<locals>.<listcomp>�=��)
�
_read_file�strip�
startswith�split�len�salt�utils�stringutilsZdequote�upper)�pathZsuse_configZcv_suse_config�line�pair�namer:rrr�_parse_suse_config�srTcCsi}d|vr*|dtvr|�ddi�n|dtvr"|�ddi�nt|dtt�d|vrHddg}|d|vrB|�d|di�nt|d|�d|vrjgd�}t|d�|vrb|�d|di�nt||d|�d	|vr�gd
�}t|d	�|vr�|�d	|d	i�nt|d	|�d|vr�d|����}g}d
D]1}||dvr�tdtdd�}|d||vr�|�d�	||d|��q�t||d||�q�|r�|�|d�
|�i�tt}dD]*}||v�r||tvr�|�|di�q�||tv�r|�|di�q�t|||�q�|S)z�
    Parses valid options for ETHTOOL_OPTIONS of the interface
    Logs the error and raises AttributeError in case of getting invalid options
    Zautonegr
rZduplex�fullZhalfZspeed)�10Z100Z1000Z10000Z	advertise)Z0x001Z0x002Z0x004Z0x008Z0x010Z0x020Z0x20000Z0x8000Z0x1000Z0x40000Z0x80000Z0x200000Z0x400000Z0x800000Z	0x1000000Z	0x2000000Z	0x4000000Zchannelsz-L )�rx�tx�otherZcombinedrEZnum_cpusz{} {}� )rWrXZsgZtsoZufoZgsoZgroZlro)�_CONFIG_TRUE�update�
_CONFIG_FALSE�_raise_error_ifacer%rH�ranger�appendr-r.)�optsr0Zconfig�validZchannels_cmdZchannels_paramsr1rrr�_parse_ethtool_opts�s\��
�rccCs|ddvrt�d|�t||�S|ddvr"t�d|�t||�S|ddvr3t�d|�t||�S|ddvrDt�d	|�t||�S|dd
vrUt�d|�t||�S|ddvrft�d
|�t||�S|ddvrwt�d|�t||�Sd}t	|d|�dS)z�
    Parses valid options for bonding interface
    Logs the error and raises AttributeError in case of getting invalid options
    �mode)�
balance-rrrz5Device: %s Bonding Mode: load balancing (round-robin))�
active-backuprz8Device: %s Bonding Mode: fault-tolerance (active-backup))�balance-xor�2z-Device: %s Bonding Mode: load balancing (xor))�	broadcast�3z4Device: %s Bonding Mode: fault-tolerance (broadcast))�802.3ad�4z>Device: %s Bonding Mode: IEEE 802.3ad Dynamic link aggregation)�balance-tlb�5z0Device: %s Bonding Mode: transmit load balancing)�balance-alb�6z0Device: %s Bonding Mode: adaptive load balancing)rrrhrjrlrnrprerfrgrirkrmroN)
r7r8�_parse_settings_bond_0�_parse_settings_bond_1�_parse_settings_bond_2�_parse_settings_bond_3�_parse_settings_bond_4�_parse_settings_bond_5�_parse_settings_bond_6r^)rar0rbrrr�_parse_settings_bond�s2



�


rxc	CsNi}dD]'}||vr+zt||�|�|||i�Wqty*t||d�Yqwqd|vr<d|vr<|dd|d<d|vr�|dsJt|dd�dD]}||vre|||dret||d�|d��qLd	|vr�|d	tvry|�d	d
i�|S|d	tvr�|�d	di�|Stt}t|d	|�|St|d	td	�|�d	td	i�|S)zc
    Add shared settings for miimon support used by balance-rr, balance-xor
    bonding types.
    )�miimon�	downdelay�updelay�integerryrzrFznonzero integer)rzr{z0 or a multiple of miimon ({})r
rr)	�intr\�
ValueErrorr^r-r[r]r;�_BOND_DEFAULTS)rar0�ret�bindingrbrrr�_parse_settings_miimonsJ����
���r�cCs�i}d|vrhzt|d�|�d|di�Wnty&t|dd�Ynwd}d|vrbt|dt�rZdt|d�krBdkrRnn|�dd�|d�i�|St|d|�|St|d|�|St|d|�|S)zT
    Add shared settings for arp used by balance-rr, balance-xor bonding types.
    �arp_intervalr|zlist of ips (up to 16)Z
arp_ip_targetrE��,)r}r\r~r^r,�listrKr.)rar0r�rbrrr�_parse_settings_arp@s(� ���r�cCsHddi}|�t||��|�t||��d|vr"d|vr"t|dd�|S)z�
    Parses valid options for balance-rr (type 0) bonding interface
    Logs the error and raises AttributeError in case of getting invalid options
    rdrryr��miimon or arp_interval�!at least one of these is required�r\r�r�r^�rar0rrrrrq\s�rqcC�Jddi}|�t||��d|vrt|dd�d|vr#|�d|di�|S)z�
    Parses valid options for active-backup (type 1) bonding interface
    Logs the error and raises AttributeError in case of getting invalid options
    rdrryr|�primary�r\r�r^r�rrrrrm�rrcCs�ddi}|�t||��|�t||��d|vr"d|vr"t|dd�d|vr?d}|d|vr9|�d	|di�|St|d|�|S)
z�
    Parses valid options for balance-xor (type 2) bonding interface
    Logs the error and raises AttributeError in case of getting invalid options
    rdrhryr�r�r��hashing-algorithm�rzlayer2+3zlayer3+4rr�)rar0rrbrrrrs~s��rscCs0ddi}|�t||��d|vrt|dd�|S)z�
    Parses valid options for broadcast (type 3) bonding interface
    Logs the error and raises AttributeError in case of getting invalid options
    rdrjryr|r�r�rrrrt�s
rtc	Cs>ddi}|�t||��d|vrt|dd�dD]g}||vrn|dkrKd}|||vr0t|||�||dkr=|�|d	i�||d
krJ|�|di�nd}zt||�|�|||i�Wqtymt|||�Yqwt||t|�|�|t|i�qd|vr�d
}|d|vr�|�d|di�|St|d|�|S)z�
    Parses valid options for 802.3ad (type 4) bonding interface
    Logs the error and raises AttributeError in case of getting invalid options
    rdrlryr|)r	rr	)�fastr�slowrr�rr�rr�r�r)r\r�r^r}r~r;r)rar0rr�rbrrrru�s>���rucCr�)z�
    Parses valid options for balance-tlb (type 5) bonding interface
    Logs the error and raises AttributeError in case of getting invalid options
    rdrnryr|r�r�r�rrrrv�r�rvcCr�)z�
    Parses valid options for balance-alb (type 6) bonding interface
    Logs the error and raises AttributeError in case of getting invalid options
    rdrpryr|r�r�r�rrrrw�r�rwcCs�i}d|vr"|dttvr|�d|di�n
tt}t|d|�d|vr<|ddkr6|�d|di�nt|dd�d|vrYt|d�dkrS|�d|di�|St|dd�|S)zE
    Filters given options and outputs valid settings for a vlan
    Zreorder_hdrZvlan_idrzPositive integerZphys_devzNon-empty string)r[r]r\r^rK)rar0rrbrrr�_parse_settings_vlan�s �r�c	Cs�d|i}d|vr!gd�}|d|vr|d|d<nt||d|�d|vr@z
t|d�|d<Wnty?t|ddg�Ynwd|vrSd|vrSd}t�|�t|��|d	vrlt||�}|rld
�dd�|��D��|d
<|dkrtd|d<|dkr�d|vr�d}t�d||�t|��t	||�}|r�d
�dd�|��D��|d<d|d<d|vr�t
|dt�r�|d|d<n|d��|d<|dkr�t
||�}	|	r�d|d<|	D]}
||
||
<q�|dkr�d|d<|dk�r?d|d<d}tt}d D]"}
|
|v�r||
tvr�d}q�||
tv�r	d!}q�t|||
|�q�gd"�}|�rd#}
nd$}
|D]}z
td%||
�W�q t�y=t�d&|�Y�q wnd|v�rJ|d|d<|d'k�rld(|d<d)D]}
|
|v�rdt||
d*��qU||
||
<�qU|d+k�rud,|d<d-|v�r�d.|v�r�d/}t�|�t|��|d-|d-<nd.|v�r�|d.|d.<d0D]}
|
|v�r�||
||
<�q�d1|v�s�d2|v�s�d3|v�r�g|d1<d1|v�r�|d1D]*}
tjjj�|
��s�tjjj�|
��r�|d1�|
��q�|
�d4�}t�|�t|��d2|v�rtjjj�|d2��r|d1�|d2�n|
�d5�}t�|�t|��d3|v�rG|d3D]!}
tjjj�|
��r9|d1�|
��q%|
�d5�}t�|�t|��d6|v�rR|d6|d6<tt}d7D]*}
|
|v�r�||
tv�rld8||
<�qX||
tv�ryd9||
<�qXt|||
|��qXd:|v�r�t�d;||�d<|v�r�d=}|d<|v�r�|d<|d<<nt||d<|�n|�r�d>|d<<nd?|d<<d|v�r�|dtv�r�d8|d<n|dtv�r�d9|d<nt||d|�d@|v�r�|d@tv�r�d9|d@<dA|v�r�|dA|dA<dB|v�r|dB|dB<dC|v�r|dC|dC<d|v�r|d|d<d|v�r%|d|d<dD|v�rN|dDtv�r7d8|dD<|S|dDtv�rDd9|dD<|St||dD|�|Sd9|dD<|S)EzW
    Filters given options and outputs valid settings for a
    network interface.
    rS�proto)	ZstaticZdhcpZdhcp4Zdhcp6Zautoipzdhcp+autoipZauto6Z6to4�noneZmtur|ZhwaddrZmacaddrzFCannot pass both hwaddr and macaddr. Must use either hwaddr or macaddr)rrZcS�g|]\}}|�d|���qS)rZr�r'�x�yrrrrC0�z'_parse_settings_eth.<locals>.<listcomp>�ethtoolrr�rrdzMissing required option 'mode'z%s for bond interface '%s'cSr�)rDrr�rrrrC<r��bondingZBondZdevtypeZslavesrZVlanrZEthernetrZBridgeT)�bypassfirewallF)z#net.bridge.bridge-nf-call-ip6tablesz"net.bridge.bridge-nf-call-iptablesz#net.bridge.bridge-nf-call-arptablesrrEzsysctl.persistzFailed to set sysctl: %srZIPIP)Zmy_inner_ipaddrZmy_outer_ipaddrz1.2.3.4rZ
InfiniBand�prefix�netmaskz&Cannot use prefix and netmask together)	Zipaddr�masterZsrcaddr�delay�domainZgatewayZuuidZnickname�zone�ipaddrsZipv6addrZ	ipv6addrsz is invalid ipv4 or ipv6 CIDRz is invalid ipv6 CIDRZenable_ipv6)
ZonparentZpeerdnsZ
peerroutesrrZdefrouteZstpZipv6_peerdnsZ
ipv6_defrouteZipv6_peerroutesZ
ipv6_autoconfZipv4_failure_fatalZdhcpv6crrZonbootzTThe 'onboot' option is controlled by the 'enabled' option. Interface: %s Enabled: %sZ	startmode)Zmanual�autoZnfsrootZhotplugrr�rZarpcheckZipaddr_startZ
ipaddr_endZclonenum_startZ
nm_controlled)r^r}r~r7�error�AttributeErrorrcr.�itemsrxr,r�rJr�r[r]�__salt__r�warningrLrM�validate�netZ	ipv4_addrZ	ipv6_addrr`)ra�
iface_type�enabledr0�resultrbr3r�r�rr9r�Z
bridgectlsZsysctl_valueZsysctlrrr�_parse_settings_ethsR�





���








�

��









�
�











���r�cCsDdd�|��D�}i}d|vrt|dd�|D]}||||<q|S)z[
    Filters given options and outputs valid settings for
    the route settings file.
    cS�i|]	\}}|��|�qSr��lower�r'�k�vrrr�
<dictcomp>�z!_parse_routes.<locals>.<dictcomp>�routeszList of routes)r��_raise_error_routes)r0rar�r9rrr�
_parse_routessr�cCs
dd�|��D�}dd�|��D�}|�dd�}i}|rd|D]E}|}|dkr1d}||��||<n+|dkr@d	}||��||<n|�d
�rV|dvrV|dd
�}||||<n||||<t|||�q|D]}|dvr|t||t�s|||��||<qf||||<qf|S)zd
    Filters given options and outputs valid settings for
    the global network settings file.
    cSr�rr�r�rrrr�r�z+_parse_network_settings.<locals>.<dictcomp>cSr�rr�r�rrrr� r��retain_settingsFZnetconfig_dns_static_servers�dnsZnetconfig_dns_static_searchlist�
dns_searchZ
netconfig_)Znetconfig_modules_orderZnetconfig_verboseZnetconfig_force_replace�
N)r�r�)r��getrJrIr>r,r�)ra�currentr�r�r9Znoptrrr�_parse_network_settingss.r�cC�t|||�}t�|�t|���zB
    Log and raise an error with a logical formatted message.
    )r4r7r�r�r/rrrr^A�
r^cCst||�}t�|�t|��r�)r=r7r�r�r<rrr�_raise_error_networkJs

r�cCr�r�)r5r7r�r�r/rrrr�Sr�r�cCsfz'tjj�|d��}ttjj�|����Wd�WS1s wYWdSty2gYSw)z2
    Reads and returns the contents of a file
    �rbN)	rLrM�files�fopen�_get_non_blank_linesrNZ
to_unicode�read�OSError)rPZrfhrrrrG\s(��rGcCs�tj�||�|��}tj�|�s!|�d|�d�}t�|�t|��tj	j
�|d��}|�tj	j
�|��Wd�dS1s?wYdS)�
    Writes a file to disk
    z cannot be written. z does not exist�wN)�osrPr.r-�existsr7r�r�rLrMr�r��writerN�to_str)r0�dataZfolder�pattern�filenamer3�fp_rrr�_write_file_ifacegs
"�r�cCsJtjj�|d��}|�tjj�|��Wd�dS1swYdS)r�r�N)rLrMr�r�r�rNr�)r�r�r�rrr�_write_file_networkts"�r�cCs.|��}z|�d�W|StyY|Sw)N�)�
splitlines�remover~)r��linesrrrr�|s��r�c	KsJ|��}|tvrt||t�|dkr%d|d<d|vr%d}t�|�t|��|dkr@d|vr8d}t�|�t|��t|d�|d<|dkrHd|d<|d	krXtd
d�sXtdd�|d
vr�t||||�}zt	�
d�}Wntjj
y{t�d�YdSwt�d|�|�|�}|�d�r�t|�St||td�tj�td|���}t|�S)a#
    Build an interface script for a network interface.

    Args:
        :param iface:
            The name of the interface to build the configuration for

        :param iface_type:
            The type of the interface. The following types are possible:
              - eth
              - bond
              - alias
              - clone
              - ipsec
              - dialup
              - bridge
              - slave
              - vlan
              - ipip
              - ib

        :param enabled:
            Build the interface enabled or disabled

        :param settings:
            The settings for the interface

    Returns:
        dict: A dictionary of file/content

    CLI Example:

    .. code-block:: bash

        salt '*' ip.build_interface eth0 eth <settings>
    rrr�z1master is a required setting for slave interfacesrrdz$mode is required for bond interfacesrrzpkg.versionzbridge-utilszpkg.install)rrrrrrrrzifcfg.jinjaz#Could not load template ifcfg.jinjar�zInterface opts:
%s�testzifcfg-{}�ifcfg-)r��_IFACE_TYPESr^r7r�r�r%r�r��JINJA�get_template�jinja2�
exceptions�TemplateNotFound�debug�renderr�r�r��_SUSE_NETWORK_SCRIPT_DIRr�rPr.rG)	r0r�r��settingsr3ra�templateZifcfgrPrrr�build_interface�sD%



�

r�cKs�d}t�d|�t||�}t�d|�zt�|�}Wntjjy,t�d|�YdSwt�d|d�|dkrB|j	|dd�}n	|j	|d|d	�}|d
rSt
|�S|dkrZt}n
tj
�td|���}t||�t|�S)ao
    Build a route script for a network interface.

    Args:
        :param iface:
            The name of the interface to build the routes for

        :param settings:
            The settings for the routes

    Returns:
        dict: A dictionary of file/content

    CLI Example:

    .. code-block:: bash

        salt '*' ip.build_routes eth0 <settings>
    z
ifroute.jinjazTemplate name: %szOpts:
%szCould not load template %sr�z
IP routes:
%sr�)r�)r�r0r��ifroute-)r7r�r�r�r�r�r�r�r�r�r��_SUSE_NETWORK_ROUTES_FILEr�rPr.r�r�rG)r0r�r�raZroutecfgrPrrr�build_routes�s*
�
r�cC�&|r|��dkrtdd|���SdS)a�
    Shutdown a network interface

    Args:
        :param iface:
            The name of the interface to shutdown

        :param iface_type:
            The type of the interface
            If ``slave`` is specified, no any action is performing
            Default is ``None``

    Returns:
        str: The result of ``ifdown`` command or ``None`` if ``slave``
        iface_type was specified

    CLI Example:

    .. code-block:: bash

        salt '*' ip.down eth0
    r�cmd.runzifdown N�r�r��r0r�rrr�down�r�cCstj�td|���}t|�S)a
    Return the contents of an interface script

    Args:
        :param iface:
            The name of the interface to get settings for

    Returns:
        dict: A dictionary of file/content

    CLI Example:

    .. code-block:: bash

        salt '*' ip.get_interface eth0
    r�)r�rPr.r�rG�r0rPrrr�
get_interface/sr�cCr�)a�
    Start up a network interface

    Args:
        :param iface:
            The name of the interface to start up

        :param iface_type:
            The type of the interface
            If ``slave`` is specified, no any action is performing
            Default is ``None``

    Returns:
        str: The result of ``ifup`` command or ``None`` if ``slave``
        iface_type was specified

    CLI Example:

    .. code-block:: bash

        salt '*' ip.up eth0
    rr�zifup Nr�r�rrr�upDr�r�cCs0|dkr
t}t|�Stj�td|���}t|�S)a$
    Return the contents of the interface routes script.

    Args:
        :param iface:
            The name of the interface to get the routes for

    Returns:
        dict: A dictionary of file/content

    CLI Example:

    .. code-block:: bash

        salt '*' ip.get_routes eth0
    r�r�)r�r�rPr.r�rGr�rrr�
get_routesas
�r�cCstt�S)a�
    Return the contents of the global network script.

    Args:
        :param iface:
            The name of the interface to start up

        :param iface_type:
            The type of the interface
            If ``slave`` is specified, no any action is performing
            Default is ``None``

    Returns:
        dict: A dictionary of file/content

    CLI Example:

    .. code-block:: bash

        salt '*' ip.get_network_settings
    )rG�_SUSE_NETWORK_FILErrrr�get_network_settingsysr�cKs�d|vrd|d<d|vrd|d<d}|dtvr,d|vr%td|d�}nt�d�d}d}|dtvr<t�d�d}ntd	d
�}|oE|S)a"
    Apply global network configuration.

    Args:
        :param settings:
            The network settings to apply

    Returns:
        The result of ``service.reload`` for ``network`` service

    CLI Example:

    .. code-block:: bash

        salt '*' ip.apply_network_settings
    Zrequire_rebootFZapply_hostnameT�hostnameznetwork.mod_hostnamezUThe network state sls is trying to apply hostname changes but no hostname is defined.zbThe network state sls is requiring a reboot of the system to properly apply network configuration.zservice.reload�network)r[r�r7r�)r�Zhostname_res�resrrr�apply_network_settings�s(��r�cKs|tt�}t||�}zt�d�}Wntjjy!t�	d�YdSw|�
|�}|dr/t|�St|t�t
dd�tt�S)a
    Build the global network script.

    Args:
        :param settings:
            The network settings

    Returns:
        dict: A dictionary of file/content

    CLI Example:

    .. code-block:: bash

        salt '*' ip.build_network_settings <settings>
    z
network.jinjaz%Could not load template network.jinjar�r�r�znetconfig update -f)rTr�r�r�r�r�r�r�r7r�r�r�r�r�rG)r�Zcurrent_network_settingsrar�r�rrr�build_network_settings�s

�

r�r#)E�__doc__�loggingr�r�Zjinja2.exceptionsZsalt.utils.filesrLZsalt.utils.stringutilsZsalt.utils.templatesZsalt.utils.validate.netZsalt.exceptionsr�	getLogger�__name__r7ZEnvironmentZFileSystemLoaderrPr.rMZ	templatesZTEMPLATE_DIRNAMEr�rrr�r�r�r[r]r�rr4r5r;r=r>rTrcrxr�r�rqrrrsrtrurvrwr�r�r�r�r^r�r�rGr�r�r�r�r�r�r�r�r�r�r�r�rrrr�<module>s�
���
	R0-*~(			
	Z
3
/