Your IP : 3.15.26.184


Current Path : /opt/imunify360/venv/lib64/python3.11/site-packages/clcommon/__pycache__/
Upload File :
Current File : //opt/imunify360/venv/lib64/python3.11/site-packages/clcommon/__pycache__/sysctl.cpython-311.pyc

�

\�Dgp��z�ddlZddlmZddlmZmZmZddlmZm	Z	dZ
dZGd�d��ZGd	�d
��Z
dS)�N)�ConfigParser)�run_command�get_file_lines�ExternalProgramFailed)�AnyStr�Listz /etc/sysctl.d/90-cloudlinux.confz/etc/sysctl.confc�z�eZdZdZdZedfd�Zd�Zed���Z	d�Z
ed���Zd	�Z
d
�Zd�Zdd�Zd
�ZdS)�
SysCtlConfz(
    For reading params from sysctl
    z/sbin/sysctlTc�@�||_|j�d�|_||_dS)z�
        :param config_file: path to user defined systcl config file
        :param mute_errors: T/F value to define should we skip errors or not (used in cldiag checker)
        �.tmpN)�config_file�config_tmp_file�mute_errors)�selfr
rs   �o/builddir/build/BUILD/imunify360-venv-2.4.0/opt/imunify360/venv/lib/python3.11/site-packages/clcommon/sysctl.py�__init__zSysCtlConf.__init__s.��'���"&�"2�8�8�8���&�����c�j�|jdg}	t|��dS#t$r|js�YdSwxYw)z>
        Apply all params from sysctl.d & sysctl.conf
        z--systemN)�
SYSCTL_BINrrr)r�cmds  r�
_apply_allzSysCtlConf._apply_all$sf��
�O��
��	�
��������$�	�	�	��#�
��
�
�
�	���s��2�2c�n�|jdd|g}t|d���\}}}|���}|S)zM
        Read sysctl param
        :param name: name of sysctl param
        z-bz-nT)r�return_full_output)rr�strip)�cls�namer�ret_code�std_out�std_in�values       r�_read_sysctl_paramzSysCtlConf._read_sysctl_param6sP��
�N����	
��%0��#�%
�%
�%
�!��'�6��
�
�����rc�j�t|jdd���5}d�|��}|�|��|���tj|�����ddd��n#1swxYwYtj|j|j	��dS)zm
        Write sysctl params to sysctl.conf
        :param lines: content for writing to sysctl.conf
        �w�utf-8��encoding�N)
�openr�join�write�flush�os�fsync�fileno�renamer
)r�lines�sysctl_confs   r�_write_params_to_filez SysCtlConf._write_params_to_fileLs����$�&��g�
>�
>�
>�	+�+��G�G�E�N�N�E����e�$�$�$��������H�[�'�'�)�)�*�*�*�		+�	+�	+�	+�	+�	+�	+�	+�	+�	+�	+����	+�	+�	+�	+�
	�	�$�&��(8�9�9�9�9�9s�A%B	�	B
�B
c�\�|�d��d���S)N�=r)�splitr)�lines r�_get_param_name_from_linez$SysCtlConf._get_param_name_from_lineYs%���z�z�#���q�!�'�'�)�)�)rc�.�t|j��}|S)zW
        Read content from sysctl.conf
        :return: lines from sysctl.conf
        )rr
)r�results  r�_read_sysctl_confzSysCtlConf._read_sysctl_conf_s�� �� 0�1�1���
rc�j�������}t��fd�|D����}|S)Nc3�J�K�|]}���|��kV��dS)N)r7)�.0r6�
param_namers  ��r�	<genexpr>z+SysCtlConf.has_parameter.<locals>.<genexpr>ns6�����_�_�D�Z�4�#A�#A�$�#G�#G�G�_�_�_�_�_�_r)r:�any)rr>�
file_linesr9s``  r�
has_parameterzSysCtlConf.has_parameterjsB�����+�+�-�-�
��_�_�_�_�_�T^�_�_�_�_�_���
rc�X�|���|�|��}|S)z{
        Get sysctl param by name
        :param name: name of sysctl param
        :return: value of sysctl param
        )rr!)rrr s   r�getzSysCtlConf.getqs,��	
�������'�'��-�-���rc��|�d|�d�}t|�����}d}t|��D]8\}}|�d��r�|�|��}	||	kr|}�9|dkr|�|��n|r|||<|�|��|���dS)z�
        Set sysctl param by name
        :param overwrite: overwrite value of existed parameter
        :param name: name of sysctl param
        :param value: value of sysctl param
        z = �
����#N)�listr:�	enumerate�
startswithr7�appendr2r)
rrr �	overwrite�param�sysctl_conf_output�	idx_param�ir6�keys
          r�setzSysCtlConf.set~s����%�%�E�%�%�%��!�$�"8�"8�":�":�;�;���	� �!3�4�4�	�	�G�A�t����s�#�#�
���0�0��6�6�C��s�{�{��	����?�?��%�%�e�,�,�,�,�
�	2�,1��y�)��"�"�#5�6�6�6��������rc�:�|���t|�����}g}t|��D]6\}}|�|��}||kr|�d|���7|D]}||=�|�|��dS)z[
        Remove systcl param from config
        :param name: name of sysctl param
        rN)rrIr:rJr7�insertr2)rrrO�idx_listrQr6rRs       r�removezSysCtlConf.remove�s���	
������!�$�"8�"8�":�":�;�;���� �!3�4�4�	&�	&�G�A�t��0�0��6�6�C��s�{�{�����1�%�%�%���	&�	&�A�"�1�%�%��"�"�#5�6�6�6�6�6rN)T)�__name__�
__module__�__qualname__�__doc__r�SYSCTL_FILErr�classmethodr!r2�staticmethodr7r:rBrDrSrW�rrr
r
s��������� �J�#.�D�	'�	'�	'�	'����$����[��*:�:�:��*�*��\�*�
	�	�	�����������47�7�7�7�7rr
c�<�eZdZdZdZe�d�ZdZd�Zd�Zd�Z	d�Z
d	S)
�
SysCtlMigratezp
    Class for migrating of sysctl parameter from /etc/sysctl.conf to /etc/sysctl.conf.d/90-cloudlinux.conf
    z/var/lve/cl-sysctl.migrater�mainc���tt���|_tt���|_tdd���|_|j�|j��dS)N)r
F)�
interpolation�strict)	r
r\�	_src_conf�SYSCTL_CL_CONF_FILE�	_dst_confr�_migrate_config�read�MIGRATE_CONFIG_PATH)rs rrzSysCtlMigrate.__init__�s^��#��<�<�<���#�0C�D�D�D��� ,�$�u�M�M�M�����!�!�$�":�;�;�;�;�;rc���d}|j�|j��r@|j�|j|��r |j�|j|��}|S)NF)ri�has_section�MAIN_SECTION�
has_option�
getboolean)rr>r9s   r�_is_migration_donez SysCtlMigrate._is_migration_done�se������+�+�D�,=�>�>�	T��$�/�/��0A�:�N�N�	T��)�4�4�T�5F�
�S�S�F��
rc��|j�|j��s|j�|j��|j�|j|d��t|jdd���5}|j�|��|���tj
|�����ddd��n#1swxYwYtj|j|j
��dS)N�truer#r$r%)rirmrn�add_sectionrSr(�MIGRATE_CONFIG_TMP_PATHr*r+r,r-r.r/rk)rr>�
config_tmps   r�_set_migration_state_to_donez*SysCtlMigrate._set_migration_state_to_done�s(���#�/�/��0A�B�B�	@�� �,�,�T�->�?�?�?��� � ��!2�J��G�G�G�
�$�.��g�
F�
F�
F�	*�*�� �&�&�z�2�2�2��������H�Z�&�&�(�(�)�)�)�	*�	*�	*�	*�	*�	*�	*�	*�	*�	*�	*����	*�	*�	*�	*�	�	�$�.��0H�I�I�I�I�Is�7AC�C�Cc�N�|�|���rdS|j�|��r|j�|��}n|}|j�|��|�#|�dnd}|j�|||���|�|���dS)a%
        Migrate sysctl parameter from one config to another
        in conformity with presence of parameter in source config and default value.
        All cases of using you can see in doc:
        https://docs.google.com/spreadsheets/d/1H_q3TA3CMFCj1YwAOn7G1LZgxcS1F4h90B6jCgiTUpo
        )r>NTF)rM)rqrfrBrDrWrhrSrw)rr>�
default_valuer rMs     r�migratezSysCtlMigrate.migrate�s����"�"�j�"�9�9�	��F��>�'�'�
�3�3�	"��N�&�&�z�2�2�E�E�"�E�	
����j�)�)�)���!.� 5���5�I��N���z�5�I��F�F�F��)�)�Z�)�@�@�@�@�@rN)rXrYrZr[rkrurnrrqrwrzr_rrrara�s~��������7��!4�:�:�:���L�<�<�<����J�J�J�A�A�A�A�Arra)r,�configparserr�clcommon.utilsrrr�typingrrrgr\r
rar_rr�<module>r~s���
�	�	�	�%�%�%�%�%�%�M�M�M�M�M�M�M�M�M�M���������8�� ��W7�W7�W7�W7�W7�W7�W7�W7�tDA�DA�DA�DA�DA�DA�DA�DA�DA�DAr

?>