HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/kmod.cpython-310.pyc
o

�N�gn�@s�dZddlZddlZddlZddlZddlZddlmZe�	e
�Zdd�Zdd�Z
dd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd$dd�Zd$dd�Zdd �Zd%d"d#�ZdS)&z'
Module to manage Linux kernel modules
�N)�CommandExecutionErrorcCstddkS)z$
    Only runs on Linux systems
    Zkernel�Linux��
__grains__�rr�E/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/kmod.py�__virtual__srcCsDt�}t�}|D]	}|�|d�q|D]	}|�|d�q||S�zy
    Return a list of the new modules, pass an lsmod dict before running
    modprobe and one after modprobe has run
    �module��set�add��pre_mods�	post_modsZpreZpost�modrrr�	_new_mods�rcCsDt�}t�}|D]	}|�|d�q|D]	}|�|d�q||Sr	rrrrr�_rm_mods%rrcCsdtvrdSdS)zK
    Return location of modules config file.
    Default: /etc/modules
    Zsystemdz%/etc/modules-load.d/salt_managed.confz/etc/modulesrrrrr�_get_modules_conf3srcCs|��dkrdS|��dS)z�
    Return module name and strip configuration. It is possible insert modules
    in this format:
        bonding mode=4 miimon=1000
    This method return only 'bonding'
    �Fr)�strip�split�rrrr�_strip_module_name=srcCs�t�}tj�|�std|�t|�}|r |td�vs |t�vr#t�St	�
|�}td|d|�d�dd�r?td||�|hStd||�|hS)	zj
    Add module to configuration file to make it persistent. If module is
    commented uncomment it.
    z
file.touchTzfile.searchz^#[	 ]*z[	 ]*$)Z	multilinezfile.uncommentzfile.append)r�os�path�exists�__salt__r�mod_list�	availabler�re�escape)r�conf�mod_name�
escape_modrrr�_set_persistent_moduleIs
�r&cCslt�}t|�}|r|td�vrt�St�|�}|r'td|d|�d��|hStd|d|�d�d�|hS)zj
    Remove module from configuration file. If comment is true only comment line
    where module is.
    Tzfile.commentz^[	 ]*z[	 ]?zfile.sedr)rrrrr!r"r)r�commentr#r$r%rrr�_remove_persistent_module]s
�r(cCs&tjj�|�}|std|�d���|S)zO
    Utility function wrapper to error out early if a command is not found
    z	Command 'z' cannot be found)�salt�utilsr�whichr)�cmdZ_cmdrrr�_whichnsr-c
	CsTg}tj�dt��d�}tj�|d�}tj�|�rDtjj�|d��}|D]}|�	tj�
|�dd��q%Wd�n1s?wYtjj�|�D]\}}}|D]}d|vrh|�	|d|�d���
dd	��qRqKd
tdvr�dt��dd
d�d}	tjj�|	�D]\}}}|D]}d|vr�|�	|d|�d���
dd	��q�q�tt|��S)z�
    Return a list of all available kernel modules

    CLI Example:

    .. code-block:: bash

        salt '*' kmod.available
    z
/lib/modules/�zmodules.builtin�rN���z.ko�-�_ZArchZ	os_familyz/lib/modules/extramodules-r�z-ARCH)rr�join�unamerr)r*�files�fopen�append�basenameZos_walk�index�replacer�sorted�list)
�retZmod_dirZ
built_in_file�f�line�root�dirsr6Zfn_Zmod_dir_archrrrr xs0
�� �� ��r cC�
|t�vS)z�
    Check to see if the specified kernel module is available

    CLI Example:

    .. code-block:: bash

        salt '*' kmod.check_available kvm
    )r rrrr�check_available��

rDcCs�g}tdtd����D]9}|��}t|�dksq|ddkr q|d|d|dd�}t|�dkr<|d�d	�|d
<ng|d
<|�|�q|S)z�
    Return a dict containing information about currently loaded modules

    CLI Example:

    .. code-block:: bash

        salt '*' kmod.lsmod
    zcmd.run�lsmodr.rZModule�)�sizer
Zdepcountr3�,Zdeps)rr-�
splitlinesr�lenr8)r>r@�compsZmdatrrrrF�s 
�rFFcCs�t�}|rRt�}tj�|�rQz3tjj�|d��!}|D]}|�	�}t
|�}|�d�s0|r0|�|�qWd�n1s;wYWnt
yPt�d|�Ynwn
t�D]	}|�|d�qUtt|��S)z�
    Return a list of the loaded module names

    only_persist
        Only return the list of loaded persistent modules

    CLI Example:

    .. code-block:: bash

        salt '*' kmod.mod_list
    r/�#Nz-kmod module could not open modules file at %sr
)rrrrrr)r*r6r7rr�
startswithr
�OSError�log�errorrFr<r=)Zonly_persist�modsr#Zmodules_filer@r$rrrrr�s,

������
rcCspt�}tdd�td�|�dd�}|ddkr0t�}t||�}t�}|r(t|�}tt||B��Sd�||d	�S)
z�
    Load the specified kernel module

    mod
        Name of module to add

    persist
        Write module to /etc/modules to make it load on system reboot

    CLI Example:

    .. code-block:: bash

        salt '*' kmod.load kvm
    �cmd.run_all�{} {}ZmodprobeF�Zpython_shell�retcoderzError loading module {}: {}�stderr)	rFr�formatr-rrr&r<r=)r�persistr�resrrR�persist_modsrrr�load�s�
r\cCrC)z�
    Check to see if the specified kernel module is loaded

    CLI Example:

    .. code-block:: bash

        salt '*' kmod.is_loaded kvm
    )rrrrr�	is_loadedrEr]TcCsrt�}tdd�td�|�dd�}|ddkr1t�}t||�}t�}|r)t||�}tt||B��Sd�||d	�S)
aE
    Remove the specified kernel module

    mod
        Name of module to remove

    persist
        Also remove module from /etc/modules

    comment
        If persist is set don't remove line from /etc/modules but only
        comment it

    CLI Example:

    .. code-block:: bash

        salt '*' kmod.remove kvm
    rSrTZrmmodFrUrVrzError removing module {}: {}rW)	rFrrXr-rrr(r<r=)rrYr'rrZrrRr[rrr�removes�

r^)F)FT)�__doc__�loggingrr!Zsalt.utils.filesr)Zsalt.utils.pathZsalt.exceptionsr�	getLogger�__name__rPrrrrrr&r(r-r rDrFrr\r]r^rrrr�<module>s.


%