ok

Mini Shell

Direktori : /opt/alt/python37/lib/python3.7/site-packages/clcommon/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/clcommon/__pycache__/sysctl.cpython-37.pyc

B

E!wd��@s�ddlmZddlmZddlmZddlZddlmZddlmZm	Z	m
Z
ddlmZm
Z
dZd	ZGd
d�d�ZGdd
�d
�ZdS)�)�absolute_import)�division)�print_functionN)�ConfigParser)�run_command�get_file_lines�ExternalProgramFailed)�AnyStr�Listz /etc/sysctl.d/90-cloudlinux.confz/etc/sysctl.confc@steZdZdZdZedfdd�Zdd�Zedd	��Z	d
d�Z
edd
��Zdd�Z
dd�Zdd�Zddd�Zdd�ZdS)�
SysCtlConfz(
    For reading params from sysctl
    z/sbin/sysctlTcCs||_d�|j�|_||_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)
        z{}.tmpN)�config_file�format�config_tmp_file�mute_errors)�selfrr�r�@/opt/alt/python37/lib/python3.7/site-packages/clcommon/sysctl.py�__init__szSysCtlConf.__init__cCs8|jdg}yt|�Wntk
r2|js.�YnXdS)z>
        Apply all params from sysctl.d & sysctl.conf
        z--systemN)�
SYSCTL_BINrrr)r�cmdrrr�
_apply_all'szSysCtlConf._apply_allcCs,|jdd|g}t|dd�\}}}|��}|S)zM
        Read sysctl param
        :param name: name of sysctl param
        z-bz-nT)rZreturn_full_output)rr�strip)�cls�namerZret_codeZstd_outZstd_in�valuerrr�_read_sysctl_param9s	zSysCtlConf._read_sysctl_paramc	CsVt|jd��0}d�|�}|�|�|��t�|���WdQRXt�|j|j	�dS)zm
        Write sysctl params to sysctl.conf
        :param lines: content for writing to sysctl.conf
        �w�N)
�openr�join�write�flush�os�fsync�fileno�renamer)r�linesZsysctl_confrrr�_write_params_to_fileOs

z SysCtlConf._write_params_to_filecCs|�d�d��S)N�=r)�splitr)�linerrr�_get_param_name_from_line\sz$SysCtlConf._get_param_name_from_linecCst|j�}|S)zW
        Read content from sysctl.conf
        :return: lines from sysctl.conf
        )rr)r�resultrrr�_read_sysctl_confbs
zSysCtlConf._read_sysctl_confcs$���}t��fdd�|D��}|S)Nc3s|]}���|�kVqdS)N)r+)�.0r*)�
param_namerrr�	<genexpr>qsz+SysCtlConf.has_parameter.<locals>.<genexpr>)r-�any)rr/Z
file_linesr,r)r/rr�
has_parametermszSysCtlConf.has_parametercCs|��|�|�}|S)z{
        Get sysctl param by name
        :param name: name of sysctl param
        :return: value of sysctl param
        )rr)rrrrrr�getts
zSysCtlConf.getc
Cs�d�||�}t|���}d}x6t|�D]*\}}|�d�r:q&|�|�}	||	kr&|}q&W|dkrh|�|�n|rt|||<|�|�|��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)	r
�listr-�	enumerate�
startswithr+�appendr'r)
rrr�	overwriteZparam�sysctl_conf_outputZ	idx_param�ir*�keyrrr�set�s	


zSysCtlConf.setcCsn|��t|���}g}x2t|�D]&\}}|�|�}||kr"|�d|�q"Wx|D]
}||=qRW|�|�dS)z[
        Remove systcl param from config
        :param name: name of sysctl param
        rN)rr6r-r7r+�insertr')rrr;Zidx_listr<r*r=rrr�remove�s


zSysCtlConf.removeN)T)�__name__�
__module__�__qualname__�__doc__r�SYSCTL_FILErr�classmethodrr'�staticmethodr+r-r2r3r>r@rrrrrs

rc@sBeZdZdZdZd�e�ZdZdd�Zdd�Z	d	d
�Z
dd�Zd
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.migratez{}.tmp�maincCs8ttd�|_ttd�|_tddd�|_|j�|j�dS)N)rF)Z
interpolation�strict)	rrE�	_src_conf�SYSCTL_CL_CONF_FILE�	_dst_confr�_migrate_config�read�MIGRATE_CONFIG_PATH)rrrrr�szSysCtlMigrate.__init__cCs6d}|j�|j�r2|j�|j|�r2|j�|j|�}|S)NF)rN�has_section�MAIN_SECTIONZ
has_optionZ
getboolean)rr/r,rrr�_is_migration_done�s
z SysCtlMigrate._is_migration_donec	Cs||j�|j�s|j�|j�|j�|j|d�t|jd��(}|j�|�|��t	�
|���WdQRXt	�|j|j
�dS)N�truer)rNrQrRZadd_sectionr>r�MIGRATE_CONFIG_TMP_PATHr r!r"r#r$r%rP)rr/Z
config_tmprrr�_set_migration_state_to_done�sz*SysCtlMigrate._set_migration_state_to_donecCst|j|d�rdS|j�|�r*|j�|�}n|}|j�|�|dk	rd|dkrNdnd}|jj|||d�|j|d�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)r:)rSrKr2r3r@rMr>rV)rr/Z
default_valuerr:rrr�migrate�s
zSysCtlMigrate.migrateN)rArBrCrDrPr
rUrRrrSrVrWrrrrrH�s
	
rH)Z
__future__rrrr"ZconfigparserrZclcommon.utilsrrr�typingr	r
rLrErrHrrrr�<module>	s

Zerion Mini Shell 1.0