HEX
Server: Apache
System: Linux insrv.serversdaddy.com 5.14.0-362.24.2.el9_3.x86_64 #1 SMP PREEMPT_DYNAMIC Sat Mar 30 14:11:54 EDT 2024 x86_64
User: jsaha (1066)
PHP: 8.3.6
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/alt/python37/lib/python3.7/site-packages/cllimits/lib/__pycache__/arg_parsers.cpython-37.pyc
B

�7L���$@s�ddlmZddlmZmZddlmZmZddlmZm	Z	m
Z
mZmZddl
mZmZddlmZdZd	d
ddd
ddhZd	d
dd
ddhZdhZddhZeeBeBeBZedhBZeej�s�dhZnedddhBZedddhBZdddddddgZdd �Zd!d"�Zeeeeee	ed#d$�d%d&�eeed'e	e
d(d$��e�d)d&�eed'e	e
e �d*d$��e	e
d+d$��d,d$��d-d&�ed'e	e
e �d.d$��d/d&�ed'e	e!d0d$��d1d&�eed'e	e!d2d$��d1d&�ed'e!�ed'e!�ed'ed)d&�ed'd3d$�d4�"ed5�d&�ed'd6d$�d4�"ed7�d&�ed'd8d$�d4�"ed9�d&�eed'e!�ed'e!�ed'e!�ed'e!�ed'e!�ed'e!�ed'e!�ed'e	e
e �d:d$��d;d&�ed'e	e
e �d<d$��d=d&�ed'e!�ed>� �Z#Gd?d@�d@�Z$GdAdB�dBe$�Z%d'S)C�)�absolute_import)�Tuple�Union)�
DocoptExit�docopt)�Schema�And�Use�Or�SchemaError)�Feature�is_panel_feature_supported�)�
VALUES_STRzcloudlinux-limitsZspeedZnprocZpmemZvmemZ
maxEntryProcs�ioZiopsZinodesz	mysql-cpuzmysql-io�allZcagefsz	mysql-govzmysql-restrictzmysql-unrestrict-allz--mysql-restrictz--mysql-unrestrict-allz--mysql-govz
--mysql-ioz--mysql-cpuz--cagefsz--inodescCstt|�t�dkS)z,
    Validate limits keys for --default
    r)�len�set�AVAILABLE_DEFAULTS)�keys�r�py/cllimits/lib/arg_parsers.py�_default_keys_validate#srcCstt|�d��tt��dkS)z
    Validate limits keys
    �,r)rr�split�AVAILABLE_LIMITS)rrrr�_limits_keys_validate*srcCs|S)Nr)�xrrr�<lambda>9�rz4use --json option, other modes currently unsupported)�errorNcCs
|�d�S)Nr)r)rrrrr<rzInvalid keyscCst|�dkS)Nr)�int)rrrrr>rcCst|���S)N)�str�lower)rrrrr?rcCs|dkS)N�defaultr)rrrrr@rz8--lve-id must be non-negative integer value or 'default'cCst|�dkS)Nr)r!)rrrrrBrz0--reseller-id must be non-negative integer valuecCs
|��S)N)�isdigit)rrrrrDrzInvalid reseller namecCs
|��S)N)r%)rrrrrFrcCs|dkS)N)ZignoredZwatchedr)rrrrrJrz{}{}z: 'ignored', 'watched'cCs|dkS)N)ZenabledZdisabledr)rrrrrLrz: 'enabled', 'disabled'cCs|dkS)N)Z
restrictedZunrestrictedr)rrrrrNrz: 'restricted', 'unrestricted'cCs|dkS)Nrr)rrrrrXrz.--mysql-cpu must be non-negative integer valuecCs|dkS)Nrr)rrrrr\rz---mysql-io must be non-negative integer value) r�getzdisable-reseller-limitszenable-reseller-limitsz--jsonz--human-readable-numbersz--unlimitedz	--defaultz--save-all-parametersz--lve-idz
--reseller-idz--reseller-namez--allz--for-resellerz
--usernamez--domainz--limitsz--mysql-govz--cagefsz--mysql-restrictz--mysql-unrestrict-allz--speedz--pmemz--vmemz--nprocz--ioz--iopsz--maxEntryProcsz--mysql-cpuz
--mysql-ioz--inodesz--helpc@s�eZdZdZd�e�ZdZee	e
eee	fd�dd��Z
e
eee	fd�dd	�Zeeee	fd
�dd�Ze
eeee	fd
�dd�Zeed�dd��Zeeeeee	fd�dd��Zde
eeeee	effd
�dd�ZdS)�CloudlinuxLimitsOptsParserz�
    Parse arguments for cloudlinux-limits command
    :param argv: sys.argv
    :param _is_json_need: sys.argv contains --json key
    :return cortege: (error_flag, s_message)
    a�Utility to get/set any Cloudlinux limits

Usage:
    {0} set [--json] (--lve-id <int> | --username <str>) (--unlimited) [--for-reseller <str>]
    {0} set [--json] (--lve-id <int> | --username <str> | --reseller-name <str>) (--default <str>)
    {0} set [--json] (--lve-id <int> | --username <str>) (--mysql-gov <ignored,watched> | --cagefs <enabled,disabled> | --mysql-restrict <restricted,unrestricted>)
    {0} set [--json] (--mysql-unrestrict-all)
    {0} set [--json] (--lve-id <int> | --username <str>) [--speed <str> --io <str> --nproc <str> --pmem <str> --vmem <str> --iops <str> --inodes <N,M> --maxEntryProcs <str> --mysql-cpu <int> --mysql-io <int> --save-all-parameters]
    {0} set [--json] (--lve-id <int> | --username <str> | --reseller-name <str>) [--speed <str> --io <str> --nproc <str> --pmem <str> --vmem <str> --iops <str> --maxEntryProcs <str>] [--default <str>] [--for-reseller <str>]
    {0} set [--json] (--reseller-name <str>) (--unlimited)
    {0} [get] [--json] [--lve-id <int> | --username <str> | --reseller-name <str> | --domain <str>] [--limits=<keys>] [--human-readable-numbers] [--for-reseller <str>]
    {0} disable-reseller-limits (--reseller-id <int> | --reseller-name <str>) [--json]
    {0} enable-reseller-limits ((--reseller-id <int> | --reseller-name <str>) | --all) [--json]
    {0} (-h | --help)

Options:
    --json                              Return data in JSON format.
    --lve-id <int>                      LVE id. will display record only for that LVE id.
    --username <str>                    Execute command only for specific user.
    --reseller-name <str>               Execute command only for specific reseller.
    --reseller-id <int>                 Execute command only for specific reseller.
    --all                               Execute command for all resellers
    --for-reseller <str>                Use supplied reseller for get/set data.
    --domain <str>                      Show data only for specific domain
    --limits <keys>                     Available keys: speed,nproc,pmem,vmem,maxEntryProcs,io,
                                                        iops,mysql-gov,mysql-cpu,mysql-io,cagefs,inodes
    --human-readable-numbers            Return PMEM and VMEM limits in KBytes, MBytes or GBytes
    --unlimited                         Set all limits to unlimited.
    --default [limits]                  Reset limits to the Package defaults. List of comma-separated limits to reset them to default or "all"
    --mysql-gov <ignored|watched>       Monitor or ignore by MySQL governor.
    --cagefs <enabled|disabled>         Enable or disable CageFS for a user.
    --mysql-restrict <[un]restricted>   Set user restrict status with dbctl (restricted or unrestricted).
    --mysql-unrestrict-all              Unrestrict all restricted users with dbctl.
    --speed <str>                       Limit CPU usage for LVE | LVP.
    --pmem <str>                        Limit physical memory usage for applications inside LVE | LVP.
    --vmem <str>                        Limit virtual memory for applications inside LVE.
    --nproc <str>                       Limit number of processes for LVE | LVP.
    --io <str>                          Define io limits for LVE | LVP (KB/s).
    --iops <str>                        Limit io per second for LVE | LVP.
    --maxEntryProcs <str>               Limit number of entry processes for LVE | LVP.
    --mysql-cpu <int>                   Set MySQL governor CPU limit (pct).
    --mysql-io <int>                    Set MySQL governor IO limit (read + write MB/s)
    --inodes <N,M>                      Set inode limits. N - soft, M - hard.
    --save-all-parameters               Save all parameters even if they match with defaults settings.
    -h, --help                          Show this help message and exit
)rr&zdisable-reseller-limitszenable-reseller-limits)�option�argv�returncCsbd}d}x<|D]4}|�|�r"d}q|sxtD]}|�|�r,|}q,WqW|r^|r^dd|�d�fSdS)z�
        Checks options compatibility with admin options
        :return: Cortege (flag, message)
        flag: True/False - compatible/not compatible
        message - comment if flag is False
        F�TzERROR: option 'z)' is not compatible with '--for-reseller')Tr+)�
startswith�ADMIN_ONLY_OPTIONS)r(r)Zoption_foundZadmin_option_name�argZadmin_optionrrr�!_is_option_compatible_with_admins�s



z<CloudlinuxLimitsOptsParser._is_option_compatible_with_admins)r)r*cCs|�d|�\}}||fS)z:
        Performs checks before parsing arguments
        z--for-reseller)r/)�selfr)Z
is_compatible�messagerrr�_perform_checks_before_docopt�sz8CloudlinuxLimitsOptsParser._perform_checks_before_docopt)�argsr*cCs|dr|drdSdS)z9
        Performs checks after parsing arguments
        z--reseller-namez--for-reseller)FzEERROR: '--reseller-name' and '--for-reseller' cannot be used together)Tr+r)r0r3rrr�_perform_checks_after_docopt�sz7CloudlinuxLimitsOptsParser._perform_checks_after_docopt)r)�is_jsonr*cCs||�|�\}}|si|fSyt|j|�}Wn.tk
rXd}|sP|d|j7}i|fSX|�|�\}}|sti|fS|dfS)zm
        Applies docopt to parse utility arguments.
        Performs checks before and after parsing
        z@ERROR: Invalid parameter passed or required parameter is missingz

r+)r2r�	docstringrr4)r0r)r5�okr1r3Zs_error_stringrrr�
_apply_docopt�s
z(CloudlinuxLimitsOptsParser._apply_docopt)r*cCstS)zQ
        Returns schema that should be used to validate parsed arguments
        )�
global_schemarrrr�_get_schema�sz&CloudlinuxLimitsOptsParser._get_schema)�schemar3r*c
CsBy|�|�}Wn*tk
r8}zit|�fSd}~XYnX|dfS)z@
        Validate parsed arguments with provided schema
        Nr+)Zvalidaterr")r;r3�errr�_validate_schema�s
z+CloudlinuxLimitsOptsParser._validate_schemaFcsh|�||�\�}�sd|fSt�fdd�|jD��s<d�d<|��}|�|��\�}�s`d|fSd�fS)zF
        Parses and validates arguments passed to the utility
        Fc3s|]}��|�VqdS)N)r&)�.0Zcommand)r3rr�	<genexpr>�sz8CloudlinuxLimitsOptsParser.parse_args.<locals>.<genexpr>Tr&)r8�any�commandsr:r=)r0r)r5r1r;r)r3r�
parse_args�sz%CloudlinuxLimitsOptsParser.parse_argsN)F)�__name__�
__module__�__qualname__�__doc__�format�	PROG_NAMEr6rA�staticmethodr"�listr�boolr/r2�dictr4r8rr:r=rrBrrrrr'hs.
	
r'cs�eZdZd�e�ZdZeee	e
fd�dd�Zeee	e
fd�dd�Z
eed	�d
d��Zdee	ee	ee
effd
��fdd�
Z�ZS)�CloudlinuxLimitsNoLveOptsParserafUtility to get/set any Cloudlinux limits

Usage:
    {0} set [--json] (--lve-id <int> | --username <str>) (--cagefs <enabled,disabled>)
    {0} [get] [--json] [--lve-id <int> | --username <str>]
    {0} (-h | --help)

Options:
    --json                              Return data in JSON format.
    --lve-id <int>                      LVE id. will display record only for that LVE id.
    --username <str>                    Execute command only for specific user.
    --cagefs <enabled|disabled>         Enable or disable CageFS for a user.
    -h, --help                          Show this help message and exit
)rr&)r)r*cCsdS)N)Tr+r)r0r)rrrr2sz=CloudlinuxLimitsNoLveOptsParser._perform_checks_before_docopt)r3r*cCsdS)N)Tr+r)r0r3rrrr4sz<CloudlinuxLimitsNoLveOptsParser._perform_checks_after_docopt)r*cs2dddddddh��fdd	�tj��D�}t|�S)
Nrr&z--jsonz--lve-idz
--usernamez--cagefsz--helpcsi|]\}}|�kr||�qSrr)r>r(�value)�schema_optionsrr�
<dictcomp>&sz?CloudlinuxLimitsNoLveOptsParser._get_schema.<locals>.<dictcomp>)r9r;�itemsr)Zoptionsr)rOrr:"s
z+CloudlinuxLimitsNoLveOptsParser._get_schemaF)r)r5r*csVt��||�\}}|sd|fSx.tj��D] \}}|�||tkrDdnd�q*Wd|fS)NFT)�superrBr9r;rQ�
setdefaultrK)r0r)r5r7r3�keyrN)�	__class__rrrB,sz*CloudlinuxLimitsNoLveOptsParser.parse_args)F)rCrDrErGrHr6rArJrrKr"r2rLr4rIrr:rrB�
__classcell__rr)rUrrMs
	rM)&Z
__future__r�typingrrrrr;rrr	r
rZclcommon.cpapirr
ZutilsrrHZAVAILABLE_LVE_KEYSZAVAILABLE_LVP_KEYSZAVAILABLE_QUOTA_KEYSZAVAILABLE_MYSQL_KEYSZAVAILABLE_KEYSrZLVErZAVAILABLE_MYSQL_KEYS_ALLr-rrrKr!r"rGr9r'rMrrrr�<module>s�







!