%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python37/lib/python3.7/site-packages/clconfig/__pycache__/
Upload File :
Create Path :
Current File : //opt/alt/python37/lib/python3.7/site-packages/clconfig/__pycache__/config.cpython-37.pyc

B

�2Lb�]�@sPddlmZddlmZddlZddlZddlZddlZddlmZm	Z	ddl
mZddlm
Z
ddlmZmZdd	lmZmZdd
lmZddlmZmZddlmZdd
lmZmZmZmZm Z m!Z!m"Z"m#Z#ddl$m%Z%ddl&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-Gdd�de%�Z.Gdd�de�Z/Gdd�de/�Z0Gdd�de/�Z1dS)�)�print_function)�absolute_importN)�ABC�abstractmethod)�
ClQuotaLib)�cpapi�)�
ui_config_lib�db_governor_lib)�is_active_reseller_limits�lve)�CloudlinuxLicenseLib)�print_dictionary�replace_params)�parse_cloudlinux_config_opts)�boolean_to_0_1�boolean_to_on_off�boolean_to_yes_no�is_int�	is_string�is_string_or_none�time_unit_to_letter�is_positive_int)�FormattedException)�is_admin)�	MysqlInfo)�is_litespeed_running)�Featurec@seZdZdS)�ValidateDataExceptionN)�__name__�
__module__�__qualname__�r"r"�@/opt/alt/python37/lib/python3.7/site-packages/clconfig/config.pyr#src@s>eZdZdd�Zedd��Zddd�Zdd
d�Zdd
d�ZdS)�
ClConfingBasecCsd|_i|_dS)NF)�_is_json�_opts)�selfr"r"r#�__init__)szClConfingBase.__init__cCsdS)zM
        Return list of pairs (input_dict_keys, validator_function).
        Nr")r'r"r"r#�_get_data_list-szClConfingBase._get_data_listF�successcCs2t|t�r|�|t��d��t||jp*|�dS)z�
        Output data wrapper
        :param: `dict` data - data for output to stdout
        :param: `bool` force_json - always output json format
        )�result�	timestampN)�
isinstance�dict�update�timerr%)r'�dataZ
force_jsonr+r"r"r#�_print_data4s
zClConfingBase._print_datarc
Cs�|jr$|�dt��i�t|d�nXy tt|d�|�di��Wn6tk
rz}ztdt|�|f�Wdd}~XYnXt�	|�dS)z�
        Print error and exit
        :param message: Dictionary with keys "result" as string and optional "context" as dict
        r,Tr+�contextzError: %s [%s]N)
r%r/r0r�print�str�get�KeyError�sys�exit)r'�messageZ
error_code�er"r"r#�_error_and_exit>s &zClConfingBase._error_and_exitNc		Cs�|��}xz|D]r}yX|\}}|�dd��dd��dd��d�}td|�}||�dkrhtdd	|id
���Wqtk
r~YqXqWdS)z4
        Validate config single parameters.
        �[��'�]�/zdata_dict%sNz*Value error in JSON key(s) options/%(key)s�key)r:r3)r)�replace�rstrip�evalrr7)	r'�	data_dict�resellerZcontrol_data_listZcontrol_data_itemZinput_dict_keysZvalidator_functionZkey_name_for_exceptionZinput_valuer"r"r#�_validate_parameters_singleMs
z)ClConfingBase._validate_parameters_single)Fr*)r)N)	rr r!r(rr)r2r<rHr"r"r"r#r$'s



r$c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�ClConfigSolozC
    Perform cloudlinux-config utility for CloudLinux OS Solo.
    cCsft�}|��s"d|_|�ddi�Sd|k|_|�|�}t|�|_|j�d�dkrZ|��n|�	�dS)NTr+zCloudlinux license isn't validz--json�command�set)
r
�get_license_statusr%r<�_parse_args�varsr&r6�_set_run�_get_run)r'�args�licence�optsr"r"r#�runks



zClConfigSolo.runc
CsJi}yt�|jd�d}Wn&ttfk
rB|�ddi�YnXy|�|�Wn8tk
r�}z|�ddt|�i�Wdd}~XYnXdt	�	�id�}t
�}d	|kr�|d	|d	<yt�|�WnLtj
k
�r}z*|d|jd
7<|d�|j�Wdd}~XYnX|d�s$d|d<t|d�d
k�r<|d=t|d�dS)zA
        Set parameters from self._opts
        :return:
        r1�optionsr+z/ERROR: Invalid JSON string passed in --data keyz	Error: %sNr>)r+r,r3�
uiSettingsz; r3r*rT)�json�loadsr&�
ValueErrorr7r<�_validate_input_dictionaryrr5r0r.r	�
set_ui_config�UIConfigExceptionr:r/r3�lenr)r'rFr;r+�
ui_parametersr"r"r#rOys.("
zClConfigSolo._set_runcCsvdt��d�}i}|�t���||d<dd�t����D�|d<|d}t�rftj	|krf|�
tj	�t||j�dS)z#
        Run 'get' command
        r*)r+r,rUcSsg|]\}}|r|�qSr"r")�.0�	component�is_supportedr"r"r#�
<listcomp>�sz)ClConfigSolo._get_run.<locals>.<listcomp>�supported_cl_featuresN)
r0r/r	�
get_ui_configr�get_supported_cl_features�itemsrr�LSAPI�removerr%)r'r+�full_config�supported_cl_features_listr"r"r#rP�szClConfigSolo._get_runcCsZtjddd�}|jddd�}|jddd	�|jd
dd	�}|jdd
dd�|�|�\}}|S)z%
        Parse CLI arguments
        zcloudlinux-configz'Utility to get/set Cloudlinux UI config)�prog�descriptionZcommandsrJ)�title�destr6z
get UI config)�helprKz
set UI configz--dataTzdata to set)Zrequiredro)�argparse�ArgumentParserZadd_subparsersZ
add_parser�add_argumentZparse_known_args)r'�argv�parserZ
subparsersZ
set_subparserrS�_r"r"r#rM�s
zClConfigSolo._parse_argscCs|�|�dS)z�
        Check data validity in data_dict.
        For CL OS Solo we check only single parameters.
        :param data_dict: Dictionary with input data
        :return: None, throws ValidateDataException if any error detected
        N)rH)r'rFr"r"r#rZ�sz'ClConfigSolo._validate_input_dictionarycCs.dtfdtfdtfdtfdtfdtfdtfgS)Nz['uiSettings']['hideRubyApp']z['uiSettings']['hidePythonApp']z['uiSettings']['hideNodeJsApp']z#['uiSettings']['hidePHPextensions']z!['uiSettings']['hideLVEUserStat']z['uiSettings']['hideXrayApp']z['uiSettings']['hideWPOSApp'])r)r'r"r"r#r)�szClConfigSolo._get_data_listN)
rr r!�__doc__rTrOrPrMrZr)r"r"r"r#rIfs$	rIc@sJeZdZdZdd�Zdd�Zdd�Zdd	�Zddd�Zd
d�Z	dd�Z
d
S)�ClConfigzT
    Perform cloudlinux-config utility for CloudLinux OS Shared and Shared Pro.
    cCsxt�}|��s"d|_|�ddi�Sd|k|_|�|�|_|jdrXt��sX|�ddi�|jdrl|��n|�	�dS)NTr+zCloudlinux license isn't validz--jsonz--for-resellerzLERROR: reseller limits are not supported, can not use --for-reseller option.r6)
r
rLr%r<rMr&rZreseller_limit_supportedrPrO)r'rQrRr"r"r#rT�s



zClConfig.runc

CsD|j�dd�}|dk	r:t|�s:t|�s:|�dd|id��|jdr�|dk	rZ|�ddi�t�}|��snd	}nd
}|��t|t	�	�d�d�dS|jd
s�|�ddi�i}yt
�|jd
�d}Wn|�ddi�YnXy|j||d�Wn:t
k
�r.}z|�ddt|�i�Wdd}~XYnXdt	�	�id�}d\}}}}	|dk	�r�ddlm}
|||	h}t|�t|���dk�r�|�dd�|�i�nddlm}
t�}||k�r�||||<||k�r�||||<yt�|�WnLtjk
�r2}z*|d|jd7<|d�|j�Wdd}~XYnX||k�r�y|
j|||d�WnL|
jk
�r�}z*|d|jd7<|d�|j�Wdd}~XYnX|	|k�ryt� ||	�WnLtj!k
�r
}z*|d|jd7<|d�|j�Wdd}~XYnX|d�sd
|d<t|d�dk�r6|d=t|d�dS)zA
        Set parameters from self._opts
        :return:
        z--for-resellerNz5ERROR: reseller limits for %(reseller)s are disabled.rG)r+r3z--reset-inodes-limitr+z2ERROR: cannot reset inode limits for reseller userzERROR: quota isn't activatedr*)r+r,Tz--dataz)ERROR: You must provide parameters to setrUz/ERROR: Invalid JSON string passed in --data key)rGz	Error: %sr>)r+r,r3)ZinodeLimitsrVZfaultsNotificationZmySQLGovSettingsr)�lve_stats2_reseller_librz)Error: can only configure {} for reseller)�lve_stats2_libz; r3)"r&r6rrr<rZis_clquota_activatedZreset_inodes_limitsrr0rWrXrZrr5r>rxr]�intersectionrK�formatryr.r	r[r\r:r/r3Zset_notificationZLveStats2Exceptionr
Zset_db_gov_config�DBGovernorException)
r'rGZcl_quotar+rFr;Zinode_limitsZui_settingsZfaults_notificationZ	mysql_gov�lve_stats2_notifZadmin_only_settingsr^r"r"r#rO�s�


(



"

"
"
zClConfig._set_runc
CsFdt��d�}i}d}|jdr8|jd}ddlm}nddlm}|dkr�|�|���|�t���y|�t	�
��WnFt	jk
r�}z&d|d	<t�|d
<t
|�|d
d	<Wdd}~XYnX|�dt���i�n|�|j|dd
��||d<dd�t����D�|d<|d}t��r6tj|k�r6|�tj�t||j�dS)z#
        Run 'get' command
        r*)r+r,Nz--for-resellerr)rx)ry�errorZmySqlGov�errorsZdbInfoT)rG�defaultsrUcSsg|]\}}|r|�qSr"r")r_r`rar"r"r#rbrsz%ClConfig._get_run.<locals>.<listcomp>rc)r0r&r>rxryr/Zget_notificationr	rdr
Zget_db_gov_configr|r.r5rr6rrerfrrrgrhrr%)r'r+rirGr}r;rjr"r"r#rPRs2


"zClConfig._get_runcCs&t||j�\}}|s"|�t|��|S)z%
        Parse CLI arguments
        )rr%r<r)r'rsZstatusr1r"r"r#rM{szClConfig._parse_argsNcCs|�||�|�|�dS)z�
        Checks data validity in data_dict
        :param data_dict: Dictionary with input data
        :param str reseller: Reseller name to validate to config reseller
        :return: None, throws ValidateDataException if any error detected
        N)rH�_validate_parameters_pairs)r'rFrGr"r"r#rZ�sz#ClConfig._validate_input_dictionarycFCs�dtfdtfdtfdtfdtfdtfdtfdtfd	tfd
tfdtfdtfd
tfdtfdtfdtfdtfdtfdtfdtfdtfdtfdtfdtfdtfdtfdtfdtfd	tfd
tfdtfdtfd
tfdtfdtfdtfdtfd tfd!tfd"tfd#tfd$tfdtfdtfd%tfd&tfd'tfd(tfd)tfd*tfd+tfd,tfd-tfd.tfd/tfd0tfd1tfd2tfd3tfd4tfd5tfd6tfd7tfd8tfd9tfd:tfd;tfd<tfd=tfgES)>Nz&['inodeLimits']['showUserInodesUsage']z['uiSettings']['hideRubyApp']z['uiSettings']['hidePythonApp']z['uiSettings']['hideNodeJsApp']z#['uiSettings']['hidePHPextensions']z!['uiSettings']['hideLVEUserStat']z['uiSettings']['hideXrayApp']z['uiSettings']['hideWPOSApp']z0['faultsNotification']['faultsToInclude']['cpu']z2['faultsNotification']['faultsToInclude']['nproc']z/['faultsNotification']['faultsToInclude']['io']z0['faultsNotification']['faultsToInclude']['mem']zB['faultsNotification']['faultsToInclude']['concurrentConnections']z1['faultsNotification']['faultsToInclude']['iops']z3['faultsNotification']['notify']['admin']['period']z7['faultsNotification']['notify']['admin']['unitOfTime']z2['faultsNotification']['notify']['user']['period']z6['faultsNotification']['notify']['user']['unitOfTime']z%['faultsNotification']['notifyAdmin']z@['faultsNotification']['minimumNumberOfFaultsToNotify']['admin']z?['faultsNotification']['minimumNumberOfFaultsToNotify']['user']z)['faultsNotification']['notifyCustomers']z)['faultsNotification']['notifyResellers']z1['faultsNotification']['notifyResellerCustomers']z2['faultsNotification']['email']['notifyFromEmail']z0['faultsNotification']['email']['notifySubject']z2['faultsNotification']['email']['reportAdminMail']z0['faultsNotification']['email']['notifyCharset']z6['faultsNotification']['notify']['reseller']['period']z:['faultsNotification']['notify']['reseller']['unitOfTime']z6['faultsNotification']['notify']['customer']['period']z:['faultsNotification']['notify']['customer']['unitOfTime']z3['faultsNotification']['notifyResellerOnCustomers']zC['faultsNotification']['minimumNumberOfFaultsToNotify']['reseller']zC['faultsNotification']['minimumNumberOfFaultsToNotify']['customer']z(['faultsNotification']['notifyReseller']z'['mySQLGovSettings']['modeOfOperation']z"['mySQLGovSettings']['scriptPath']z*['mySQLGovSettings']['userMaxConnections']z1['mySQLGovSettings']['logRestrictedUsersQueries']z2['mySQLGovSettings']['gatherDataForDetailedStats']z.['mySQLGovSettings']['restrictLog']['logPath']z-['mySQLGovSettings']['restrictLog']['format']z+['mySQLGovSettings']['errorLog']['logPath']z)['mySQLGovSettings']['errorLog']['level']z.['mySQLGovSettings']['slowQueries']['logPath']z+['mySQLGovSettings']['slowQueries']['kill']z.['mySQLGovSettings']['slowQueries']['timeout']z,['mySQLGovSettings']['restrictType']['mode']z-['mySQLGovSettings']['unlimit']['unitOfTime']z)['mySQLGovSettings']['unlimit']['period']zE['mySQLGovSettings']['restrictedTimePeriods']['level1']['unitOfTime']zA['mySQLGovSettings']['restrictedTimePeriods']['level1']['period']zE['mySQLGovSettings']['restrictedTimePeriods']['level2']['unitOfTime']zA['mySQLGovSettings']['restrictedTimePeriods']['level2']['period']zE['mySQLGovSettings']['restrictedTimePeriods']['level3']['unitOfTime']zA['mySQLGovSettings']['restrictedTimePeriods']['level3']['period']zE['mySQLGovSettings']['restrictedTimePeriods']['level4']['unitOfTime']zA['mySQLGovSettings']['restrictedTimePeriods']['level4']['period']zF['mySQLGovSettings']['restrictedTimePeriods']['timeout']['unitOfTime']zB['mySQLGovSettings']['restrictedTimePeriods']['timeout']['period'])rrrrrrrr)r'r"r"r#r)�s�zClConfig._get_data_listc	Cs�ddddddddg}x�|D]�}|\}}d	\}}ytd
|�}Wntk
rRYnXytd
|�}Wntk
rxYnX|dkr�|dk	s�|dk	r|dkrtdd
i��qWdS)zK
        Validate config pairs parameters (period and unitOfTime).
        )z3['faultsNotification']['notify']['admin']['period']z7['faultsNotification']['notify']['admin']['unitOfTime'])z2['faultsNotification']['notify']['user']['period']z6['faultsNotification']['notify']['user']['unitOfTime'])z=['mySQLGovSettings']['restrictType']['unlimit']['unitOfTime']z9['mySQLGovSettings']['restrictType']['unlimit']['period'])zE['mySQLGovSettings']['restrictedTimePeriods']['level1']['unitOfTime']zA['mySQLGovSettings']['restrictedTimePeriods']['level1']['period'])zE['mySQLGovSettings']['restrictedTimePeriods']['level2']['unitOfTime']zA['mySQLGovSettings']['restrictedTimePeriods']['level2']['period'])zE['mySQLGovSettings']['restrictedTimePeriods']['level3']['unitOfTime']zA['mySQLGovSettings']['restrictedTimePeriods']['level3']['period'])zE['mySQLGovSettings']['restrictedTimePeriods']['level4']['unitOfTime']zA['mySQLGovSettings']['restrictedTimePeriods']['level4']['period'])zF['mySQLGovSettings']['restrictedTimePeriods']['timeout']['unitOfTime']zB['mySQLGovSettings']['restrictedTimePeriods']['timeout']['period'])NNzdata_dict%sNr:z4Keys 'period' and 'unitOfTime' should be passed both)rEr7r)r'rFZpairs_data_listZpairs_data_itemZkeys1Zkeys2Zval1Zval2r"r"r#r��s,
z#ClConfig._validate_parameters_pairs)N)rr r!rvrTrOrPrMrZr)r�r"r"r"r#rw�sb)


Trw)2Z
__future__rrrpr0r8rW�abcrrZcllimits.clquota_librZclcommonrr>r	r
Z	lvectllibrrZ	cllicenser
Z	cli_utilsrrZcl_config_arg_parserZclconfig_utilsrrrrrrrrZclcommon.clexceptionrZclcommon.cpapirZdb_info_librZclcommon.utilsrZclcommon.constrrr$rIrwr"r"r"r#�<module>
s.(?r

Zerion Mini Shell 1.0