ok

Mini Shell

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

B

F�sdD��@s�ddlmZddlmZddlmZddlmZddlZddlZddlm	Z	ddl
mZmZddl
mZmZdd	lmZdd
lmZddlmZmZmZdd
lmZmZmZmZmZmZmZm Z m!Z!m"Z"ddl#m$Z$m%Z%m&Z&ddl'm(Z(ddl)m*Z*m+Z+ddl,m-Z-m.Z.m/Z/m0Z0ddl1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;ddl<m=Z=ddl>m?Z?Gdd�de=�Z@dd�dd�dd�dd�dd�dd�dd�dd�d d�d!d�d"�
ZAd#d$d%gZBd&d'gZCGd(d)�d)eD�ZEGd*d+�d+eE�ZFdS),�)�print_function)�absolute_import)�division)�
basestringN)�ClPwd)�
MySQLGovernor�MySQLGovException)�	iteritems�
itervalues)�CloudlinuxLicenseLib)�defaultdict)�convert_to_kernel_format�is_active_reseller_limits�lve�)
�CloudlinuxLimitsOptsParser�CloudlinuxLimitsNoLveOptsParser�AVAILABLE_LIMITS�AVAILABLE_LVE_KEYS�AVAILABLE_MYSQL_KEYS�AVAILABLE_QUOTA_KEYS�AVAILABLE_KEYS�AVAILABLE_LVP_KEYS�ADMIN_ONLY_OPTIONS�AVAILABLE_MYSQL_KEYS_ALL)�QuotaDisabledException�ClQuotaException�
ClQuotaLib)�convert_mem_value_to_bytes)�print_dictionary�replace_params)�LveCtl�CageFs�CageFsException�LvectlException)
�cpinfo�reseller_users�is_reseller�	getCPName�NotSupported�domain_owner�is_admin�get_main_username_by_uid�Feature�is_panel_feature_supported)�FormattedException)�
EncodingErrorc@seZdZdS)�DomainExceptionN)�__name__�
__module__�__qualname__�r5r5�D/opt/alt/python37/lib/python3.7/site-packages/cllimits/lib/limits.pyr1%sr1c	Cs4|d�dttt|��r"d�|�n|��d�i�S)N�cpu�allz{}%�d)�update�str�intr
�isdigit�format)�limits�valuer5r5r6�<lambda>*srAcCs|d�d|i�S)N�ior8)r:)r?r@r5r5r6rA/�cCs|d�d|i�S)Nr7�mysql)r:)r?r@r5r5r6rA0rCcCs|d�d|i�S)NrBrD)r:)r?r@r5r5r6rA1rCcCs0|d�|�d�d��|�d�d��d��S)N�inodes�,rr)�soft�hard)r:�split�strip)r?r@r5r5r6rA2scCs|�d|i�S)N�ep)r:)r?r@r5r5r6rA6rCcCs|�d|i�S)N�nproc)r:)r?r@r5r5r6rA7rCcCs|�dt|�i�S)N�pmem)r:r)r?r@r5r5r6rA8scCs|�dt|�i�S)N�vmem)r:r)r?r@r5r5r6rA:scCs|�d|i�S)N�iops)r:)r?r@r5r5r6rA<rC)
�speedrBz	mysql-cpuzmysql-iorE�
maxEntryProcsrLrMrNrO�rootZadmin�-ZabusersZsinglecs6eZdZdZdZdZdZdZdZdZ	�fdd�Z
dd�ZdEd	d
�Zdd�Z
d
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zed�d d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zed,d-��Zd.d/�Z d0d1�Z!d2d3�Z"d4d5�Z#d6d7�Z$d8d9�Z%d:d;�Z&d<d=�Z'd>d?�Z(d@dA�Z)dFdCdD�Z*�Z+S)G�CloudlinuxLimitsz2
    Class for run cloudlinux-limits commands
    NFcs&ttj�sttt��t�St��|�S)N)r.r-ZLVE�superrT�CloudlinuxLimitsNoLve�__new__)�cls)�	__class__r5r6rWSs
zCloudlinuxLimits.__new__cCs:t�|_t�|_t�|_t�|_t�|_	t
�|_i|_dS)z#
        Empty constructor
        N)
r�_clpwdr!�_lvectlr"�_cagefsr�	_cl_quotar�_mysql_governorr�_opts_parser�_users_list)�selfr5r5r6�__init__XszCloudlinuxLimits.__init__�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�dictr:�timer�_is_json)ra�dataZ
force_jsonrdr5r5r6�
print_datags
zCloudlinuxLimits.print_datacCs�t�}|��s"d|_|�ddi�Sd|k|_|�|�|_|j�d�sP|j�d�rnt��sn|�dd�	t
��i�|j�d�dk	r�t��s�|�dd	i�|��|�
�|jd
r�|��S|jdr�|��S|jdr�|��S|jd
r�|��S|�ddi�SdS)z$
        Run command action
        TrdzCloudlinux license isn't validz--jsonz--for-resellerz--reseller-namez;--for-reseller/--reseller-name options not supported on {}.NzEReseller limits are not supported. Can not use --for-reseller option.�set�getzdisable-reseller-limitszenable-reseller-limitszUnknown action, exit)rZget_license_statusri�_error_and_exit�_parse_args�_optsrmrZis_panel_supportedr>r(Zreseller_limit_supported�_verify_reseller�_check_user_owner�_set_run�_get_run�_disable_reseller_limits�_enable_reseller_limits)ra�argvZlicencer5r5r6�runrs0





zCloudlinuxLimits.runcCs@|j�||j�\}}|s&|�t|��t|dt�r<d|d<|S)z%
        Parse CLI arguments
        z--lve-idr)r_�
parse_argsrirnr rfr)rarwZstatusrjr5r5r6ro�szCloudlinuxLimits._parse_argscCsh|j�d�}|sdS|j�d�dkr(dS|��\}}|dkr@dS||�|�krd|�d||d�d��dS)	z�
        Checks that specified reseller is an owner of specified user and
        terminate program if need
        :return:
        z--for-resellerNz--lve-idr)NzN/Az2%(username)s is not owned by reseller %(reseller)s)�username�reseller)rd�context)rprm�_check_user�_get_reseller_namern)ra�for_reseller�_rzr5r5r6rr�sz"CloudlinuxLimits._check_user_ownercCs4|jds$|jdr$|jd|jd<|��|��S)z#
        Run `get` command
        z--reseller-namez--for-reseller)rp�_get_check_user�_get_action_list)rar5r5r6rt�szCloudlinuxLimits._get_runc
Csn|jdp|jd}y|j�|�|�id�Wn8tk
rh}z|�t|j|jd��Wdd}~XYnXdS)z7
        Run `disable-reseller-limits` command
        z--reseller-namez
--reseller-idT)rdr|N)	rpr[Zdisable_reseller_limitsrkr$rnrg�messager|)ra�res_id�er5r5r6ru�sz)CloudlinuxLimits._disable_reseller_limitsc
Csv|jdp|jdpd}y |j�t|��|�id�Wn8tk
rp}z|�t|j|j	d��Wdd}~XYnXdS)Nz--reseller-namez
--reseller-idz--allT)rdr|)
rpr[Z#_set_container_limits_by_id_or_namer;rkr$rnrgr�r|)rar�r�r5r5r6rv�s

z(CloudlinuxLimits._enable_reseller_limitscCsP|��\}}|dk	r$|dk	r$||fS|j}|dr�y|�|d�}Wn8tk
r|}z|�t|j|jd��Wdd}~XYnXy|j�	|�}Wn:t
jk
r�}z|�t|j|jd��Wdd}~XYnX|�|�s�t
|�r�|�dd|id��||j|<�nJ|d}|�r�t|�}xf|D]^}y|j�	|�}Wn<t
jk
�rj}z|�t|j|jd��Wdd}~XYnX||j|<�qWd|jd<n�yt��|_Wn:tk
�r�}z|�t|j|jd��Wdd}~XYnXd	}xl|jD]b}y|j�|�d}Wn<t
jk
�r2}z|�t|j|jd��Wdd}~XYnX||j|<�q�Wd}||fS)
z|
        Determines users according to --lve-id/--username/--domain arguments
        Or build all panel users list
        Nz--domain)rdr|z %(username)s is not a panel userrzz--reseller-namerRr�)r}rp�get_user_name_by_domainr1rnrgr�r|rZ�get_uidr�NoSuchUserException�get_package_name_by_user_id�boolr`r&r!Zget_panel_users_uid_list�_panel_uids_listr0�	get_names)ra�uidrz�or��
reseller_nameZresellers_users�namer5r5r6r��sP((
(((z CloudlinuxLimits._get_check_usercCs|j�|�S)N)r[r�)rar�r5r5r6r�"sz,CloudlinuxLimits.get_package_name_by_user_idcCs|||dd�}|dkrFd|d<d|d<|j�d�}|dk	r<|nd|d<n2|�|d�}|r`||d<|�|�|d<|�|�|S)	a?
        Retrives username, domain and reseller
        for supplied uid/username, for uid==0 returns '-'
        either reseller_name if has --for-reseller
        :param uid: uid
        :param username: username
        :return: dict {"id": uid, "username": username, "domain": domain, "reseller": reseller}
        rS)�idrzr{r�domainrzz--for-resellerNr{)rprm�_get_user_main_domainr~�_fix_single_uid_users)rar�rz�userrZuser_main_domainr5r5r6�_get_username_domain_reseller%s	
z.CloudlinuxLimits._get_username_domain_resellercCs$y
|�|�Stk
rdSXdS)zP
        Retrives user's main domain
        :param username: User name
        N)�get_user_domainr1)rarzr5r5r6r�?s
z&CloudlinuxLimits._get_user_main_domain)r�cCsv|d}|j�|�}t|�dkr$dSxL|D]D}|�|�}|�|�}|dkr*|dkr*||d<||d<||d<dSq*WdS)	a
        Check and fix user info if some users with same uid present. See LU-1816 for details
        :param user: User info. Example:
            {'id': 10001, 'username': 'cltest2', 'reseller': 'admin', 'domain': 'cltest2.com'}
        :return: None
        r�rNzN/ArSr�r{rz)rZr��lenr�r~)rar�r�Z	usernamesrzZmain_domainr{r5r5r6r�Is


z&CloudlinuxLimits._fix_single_uid_userscs�i}|j}|j��rd|d<nd|d<|ddkrN|j��rFd|d<nd|d<|j��rbd|d<nd|d<t|dt�r�|d�	d	�nd�t
�fd
d�tD��}g}|ddk�r&|d
dk�r&|ddk�r&y|jj
|d|dd�Wn:tk
�r$}z|�t
|j|jd��Wdd}~XYnXy|��}Wnbtk
�r�}zB|ddk�r�d|d<d|k�r�t
�|d<t|�|dd<d}Wdd}~XYnX�x�t|j�D�]|\}}|�||�}	|d�rH|j���rHy&|j�|	d�}
|
�r�dnd|	d<WnPtk
�rF}z0d|d<d|k�r&t
�|d<t|�|dd<Wdd}~XYnX|�|�|	d<|ddk	�s�|d
dk	�s�|ddk	�r�d|j_|j�||d�}|ddk�r�|d�r�|j���s�d|d<d|k�r�t
�|d<d|dd<n�|j���sd|d<d|k�rt
�|d<d|dd<n�y"|j�|�\}}
||
d�|d<Wn�tk
�r�}z0d|d<d|k�rpt
�|d<t|�|dd<Wdd}~XYn8tk
�r�}z|j|d<|j|d<Wdd}~XYnXt |d|d |d!|d"g��r|�ry�|d�r|j�!|	d�|	d<|d �r.|j�"|	d�|	d#<|d!�sB|d"�r�|jj#|	dd$d%�\}}|d!�r�d&|k�rxt
�|d&<||d&d'<|d"�r�d(|k�r�t
�|d(<||d(d'<WnPtk
�r}z0d|d<d|k�r�t
�|d<t|�|dd<Wdd}~XYnX|�$||�||	d)<|�%|	��q�Wt&|�|d*<||d+<|d�s�|jj'dk	�r�g}x0t(|jj'�D] }|�$||d)�|�%|��qdW||d,<ng|d,<|�)|d$�d-S).z3
        Process output for selected users
        �enabled�cageFS�disabledz--for-resellerN�quota�mySqlGovz--limitsrFc3s |]}|�p|�kfVqdS)Nr5)�.0�k)�lkr5r6�	<genexpr>{sz4CloudlinuxLimits._get_action_list.<locals>.<genexpr>z--lve-idz
--usernamez--domainz--human-readable-numbersz--reseller-name)r{)rdr|�error�errorsF�cagefsrz�packagerEz'LVE Manager/quota package not installedz#Quotas not activated on this system)rGrHZwarningr|z	mysql-govzmysql-restrictz	mysql-cpuzmysql-ioZmySqlRestrictedT)�with_package_markr7rDrBr?�items�users�	resellersr)*rpr\�is_cagefs_presentr]Zis_clquota_presentr^�is_governor_presentrfr;rIrgrr[Z
_load_infor$rnr�r|�can_get_governor_limitsrr	r`r��get_user_statusr#r��
_package_data�get_limits_by_user_idZis_clquota_activatedZget_inodes_limits_by_uidrr�anyZget_governor_status_by_usernameZget_restrict_status_by_username�get_limits_by_user�_filter_limits�appendr�Z_resellers_datar
rk)rardr��keysr�r�Zis_governor_availabler�rzr��
cagefs_statusr?Z
soft_limitZ
hard_limitZ	cpu_limitZio_limitZresellers_datar{r5)r�r6r�^s�





 *(



"*






 
"









"

z!CloudlinuxLimits._get_action_listcCsP|j��r6|j��tkrdSdddd�d�}t|��ndddid�}t|��dS)	NTz%(util)s mode is not %(mode)sZGovernorzabusers or single)�util�mode)r�r|z%(util)s not present in systemr�)r^r�Zget_governor_mode�MYSQL_GOV_ENABLED_MODEr)raZexc_messager5r5r6r��s

z(CloudlinuxLimits.can_get_governor_limitscCs�x*dD]"}||s|�|d�r|�|�qW|dsJ|�dd�rJ|�d�|ds�|�dd�r�|d�dd�r�|d�d�|ds�|�d�|ds�|�dd�r�|d�dd�r�|d�d�|ds�|�d�d	S)
z�
        Remove limits that are stored as key: False in `keys` dict;
        Used for --limits key;
        :type keys: dict[str, bool]
        :type limits: dict[str, str | dict]
        )rMrNrLrOFrQrKrPr7r8rBN)rm�pop)rar�r?r�r5r5r6r�	s

$
$zCloudlinuxLimits._filter_limitscCs |��\}}|��|�||�S)z#
        Run `set` command
        )�_set_check_userrq�_set_action)rar�rzr5r5r6rsszCloudlinuxLimits._set_runcs����\}}t�fdd�dD��}|dks2|dkrD|sD��ddi�t�fdd�tD��rxt�fdd�tD��sx||fS�jd	s�jd
dk	r�t�jd
�s�t�jd
�s��dd�jd
id
��n$��|�}t|�r��dd|i�||fS)z&
        Find user for modify
        csg|]}�j|�qSr5)rp)r��x)rar5r6�
<listcomp>/sz4CloudlinuxLimits._set_check_user.<locals>.<listcomp>)z--mysql-unrestrict-allz--reseller-nameNrdz1You must set lve-id or username for modify limitscsg|]}�j|�qSr5)rp)r�r�)rar5r6r�7scsg|]}�jd�|��qS)z--{})rpr>)r�r�)rar5r6r�8sz--reseller-namez--for-resellerz.Reseller limits for %(reseller)s are disabled.r{)rdr|zOReseller limits for %s are enabled. Admin can`t set limits for resellers users.)	r}r�rnrrrpr+rr~)rar�rzZopts_without_userr�r5)rar6r�)s$


z CloudlinuxLimits._set_check_usercCsXtdg�}t|Bt|Bt|Bt|Bd�|}tt|�|@�dkrPtt|�|@�SdSdS)z�
        Return keys to reset that are only acceptable to this type of limits
        :param list defaults: List of keys to reset
        :param str t: one of "lve", "cl-quota", "dbgov"
        r8)r�lvpzcl-quota�dbgovrN)rlrrrrr��list)�defaults�tZall_keyr�r5r5r6�_clean_defaultsIs

z CloudlinuxLimits._clean_defaultscCs@|j}|dp|d}|sdSt|�s<|�tdd|id��dS)z�
        If any reseller is specified in cli options ensures that it exists
        and really a reseller. Will exit with error if not.
        z--reseller-namez--for-resellerNzNo such reseller: %(reseller)sr{)rdr|)rpr'rnrg)rar�r{r5r5r6rq\sz!CloudlinuxLimits._verify_resellerc		Cs�|j}d}d}|dr:|ddkr:|�||�\}}}d}n@|ddk	}d|d<|rf|�||�\}}}n|�|||�\}}}|p�dg}t|�r�tdd	�|D�d
�S|dkr�|j��|�|||||||�S)zl
        Process set limits command
        :param uid: User uid
        :param username: User name
        Fz--for-resellerz--lve-idrTz--reseller-nameNcss|]}|r|VqdS)Nr5)r��coder5r5r6r��sz/CloudlinuxLimits._set_action.<locals>.<genexpr>�*)rp�_set_reseller_action�_set_user_actionr��nextr[Zapply_all_limits�_make_set_action_response)	rar�rzr��action_with_reseller_container�set_default_resellers_limits�is_lvectl_error�ret_listrdr5r5r6r�ks(

zCloudlinuxLimits._set_actioncs�|jstd�dS|�t��dd��|ds6|drV|sVd|j_d|j_|���n�d}d}	t	t
��|ddk	s~|ddk	r�|jj|d	d
�\|d<|d<xZt
|�D]N\}
}|
dd�}
|r�|
tkr�d	}	|r�|
tkr�d	}t|�}t|
}|�|�q�W|	�r�|�r�d|j_|�r"|j�|d��nF|�r\|j�|d
�}
|
d}|dk�rR|
d}|
d�n|j�|��dd�����fdd�t
��D��|�|�}|�r�||�d�g}|�d|i�n,||dk�r�dn||�d�g}|�d|i�|�|d	�dS)Nrcr)rerdz	--defaultz--unlimitedFz--mysql-cpuz
--mysql-ioT)r��z--for-resellerz--reseller-namer�r�r?cSst|t�r|�|�n|}|S)N)rfrgr:)�	old_valueZ	new_valuer5r5r6�update_func�s
z?CloudlinuxLimits._make_set_action_response.<locals>.update_funccs4i|],\}}|�kr&��|�|�n�||�qSr5r5)r��keyr@)�
getted_limits�
setted_limitsr�r5r6�
<dictcomp>�sz>CloudlinuxLimits._make_set_action_response.<locals>.<dictcomp>)r�r�r?r�rRrS)r�rzr{r?r�)ri�printr:rhr]Z_inode_user_limitsr[r�r�rrgr^r�r	rrr;�
OUT_LIMITSZ#get_default_limits_by_reseller_nameZget_limits_by_reseller_namer�r~rk)rar�r�r�rdr�r�rzZ
is_lve_limitsZ	is_limitsr�r@Z
value_funcZgetted_reseller_datar�r�r�r5)r�r�r�r6r��sj





z*CloudlinuxLimits._make_set_action_responsec
sd}g}t�}�d}t�fdd�tD��r�ddi�t��fdd�tD��}��d�|d	<y|j�|||�}	|�|	�Wn8tk
r�}
z|�t|
j	|
j
d
��Wdd}
~
XYnX�d�r�y|j�||�d}Wn:tfk
�r}
zd}t|
j	|
j
d
�}Wdd}
~
XYnX|�r2d
|d<t�|d<||dd<y"|dk�rJ|j�
|�d}d}
Wn:tfk
�r�}
zd}t|
j	|
j
d
�}
Wdd}
~
XYnX|�r�d
|d<d|k�r�t�|d<|
|dd<d}	|�|	��ddk	�r�y4|��dd�}|dk	�r|j�||�d}d}Wn:tfk
�rH}
zd}t|
j	|
j
d
�}Wdd}
~
XYnX|�rnd
|d<t�|d<||dd<�ddk�r�y.|��dd�dk	�r�|j�|�d}d}
Wn:tfk
�r�}
zd}t|
j	|
j
d
�}
Wdd}
~
XYnX|�rd
|d<d|k�rt�|d<|
|dd<y8|��dd�}|j���rJ|dk	�rJ|j�||�WnRtfk
�r�}
z0d|k�rvt�|d<t|
j	|
j
d
�|dd<Wdd}
~
XYnXd}	|�|	��d�r,y8�ddk�r�d}nd}|j�||�d}	|�|	�Wn:tk
�r*}
z|�t|
j	|
j
d
��Wdd}
~
XYnXt�fdd�tD���r��y�|���rB�d�r��ddk}y|j�||�}	|�|	�Wn:tk
�r�}
z|�t|
j	|
j
d
��Wdd}
~
XYnX�d�r.�ddk}y|j�||�}	|�|	�Wn:tk
�r,}
z|�t|
j	|
j
d
��Wdd}
~
XYnX�d�r�y|j��}	|�|	�Wn:tk
�r�}
z|�t|
j	|
j
d
��Wdd}
~
XYnXt�fdd�tD���rB�d �d!}}|d"k�r�|j�d#��s�d$}d$�d!<y,|j� |d%k�r�d&n|||�}	|�|	�Wn:tk
�r@}
z|�t|
j	|
j
d
��Wdd}
~
XYnXWn:tk
�r~}
z|�t|
j	|
j
d
��Wdd}
~
XYnX�d'�r�y0|jj!|�d'��dd�d(�d}	|�|	�Wn:tk
�r�}
z|�t|
j	|
j
d
��Wdd}
~
XYnX|||fS))NFz--for-resellerc3s|]}�d|VqdS)z--%sNr5)r��s)r�r5r6r��sz4CloudlinuxLimits._set_user_action.<locals>.<genexpr>rQ�mepc3s6|].}�d|dk	r��||��d|fVqdS)z--%sN)rm)r�r�)�
limits_mapr�r5r6r��sz--save-all-parameterszsave-all-parameters)rdr|z--unlimitedTr��lvectlr�r�rz	--defaultrzcl-quotar�r�z--cagefsr�c3s|]}�d|VqdS)z--%sNr5)r�r�)r�r5r6r�_sz--mysql-govZwatchedz--mysql-restrictZ
restrictedz--mysql-unrestrict-allc3s|]}�d|VqdS)z--%sNr5)r�r�)r�r5r6r�zsz--mysql-cpuz
--mysql-iorz1.2-17r�rR�defaultz--inodes)�force)"rgr�rrmr[Zset_lve_limits_by_user_idr�r$rnr�r|Zset_lve_unlimitedr]Z set_user_inodes_limits_unlimitedrr�Zreset_lve_limitsZreset_user_inodes_limitsr^r�Zreset_user_limits_to_defaultsrr\Zset_user_statusr#rr�Zset_governor_status_for_userZset_restricted_status_for_userZ%set_unrestricted_status_for_all_usersrZ_is_governor_newer_thenZset_limits_for_userZset_user_inodes_limits)rar�r�rzr�r�rdr�r?�ret_coder��lvectl_error_dictZis_quota_errorZquota_error_dict�lve_defaultsZ
gov_limitsZnew_user_status�str7rBr5)r�r�r6r��s

(
"

"



"
"



*

(

(
(

(,(
(z!CloudlinuxLimits._set_user_actionc
sd}t�}g}t�fdd�tD��r�ddi�t��fdd�tD��}yF�jddk	rj�j��jd|�}n�j��jd	|�}|�|�Wn8tk
r�}z��	t|j
|jd
��Wdd}~XYnX|ddk	�rtyB��|dd�}	|	dk	�r
�j�
|d	|	�}|�|�d}d}
Wn:tfk
�rN}zd
}t|j
|jd
�}
Wdd}~XYnX|�rtd|d<t�|d<|
|dd<|d�ry�j�|d	�d}
Wn:tfk
�r�}zd
}t|j
|jd
�}
Wdd}~XYnX|�r�d|d<t�|d<|
|dd<d}|�|�|||fS)NFc3s|]}�jd|VqdS)z--%sN)rp)r�r�)rar5r6r��sz8CloudlinuxLimits._set_reseller_action.<locals>.<genexpr>rQr�c3s:|]2}�jd|dk	r��||��jd|fVqdS)z--%sN)rprm)r�r�)r�rar5r6r��sz--lve-idz--for-resellerz--reseller-name)rdr|z	--defaultr�Tr�r�r�z--unlimitedr)rgr�rrpr[Zset_lvp_defaults_by_reseller_idZset_lvp_limits_by_reseller_idr�r$rnr�r|r�Zreset_reseller_limitsZset_lvp_unlimited)rar�r�r�rdr�r?r�r�r�r�r5)r�rar6r��sV
(

"

"

z%CloudlinuxLimits._set_reseller_actioncCs6tdd�}tdd�|D��|_tdd�|D��|_dS)N)Zcploginr{Zdns)Zkeylscss|]}|d|dfVqdS)rrNr5)r��ir5r5r6r��sz/CloudlinuxLimits._init_cache.<locals>.<genexpr>css|]}|d|dfVqdS)rr�Nr5)r�r�r5r5r6r��s)r%rg�_user_to_reseller�_userdomain_cache)ra�infor5r5r6�_init_cache�s
zCloudlinuxLimits._init_cachecCsF|jdkr4y|��Wntk
r2t�|_YnX|j�|d�}|S)zi
        Try to get reseller for given username;
        :type username: str
        :rtype: str
        NrS)r�r�r)rgrm)rarzr�r5r5r6r~�s
z#CloudlinuxLimits._get_reseller_namecCsB|jdkr4y|��Wntk
r2t�|_YnX|j�|d�S)z~
        Retrive main domain for supplied user
        :param username: User name
        :return: Domain name or N/A
        NzN/A)r�r�r)rgrm)rarzr5r5r6r��s
z CloudlinuxLimits.get_user_domainc
Cs^yt|�}|r|SWn2ttfk
rF}ztt|���Wdd}~XYnXtdd|id���dS)zn
        Retrive username by domain
        :param domain_name: Domain name
        :return: Username
        NzThere is no domain '%(domain)s'r�)r�r|)r*�IOErrorr)r1r;)raZdomain_namerzr�r5r5r6r��sz(CloudlinuxLimits.get_user_name_by_domainc
Cs|j}d\}}dd�}|ds*|ddkrr|d}|�|�}t|�}|sft|�rfdd�}|�||��||j|<n�|dr�|d}y|j�|�}Wn:tj	k
r�}z|�t
|j|jd��Wd	d	}~XYnX|�|�}|s�t|�r�|�||��||j|<||fS)
a
        User identification from CLI options. Common for all commands.
        May return (None, None) when user wasn't specified in any way and this
        is a *valid* case when we want to list all users with command like:
        "... get --json --for-reseller=reseller1"
        )NNcSsdd|id�S)Nz %(username)s is not a panel userrz)rdr|r5)rzr5r5r6rA	sz.CloudlinuxLimits._check_user.<locals>.<lambda>z--lve-idrcSsdd|id�S)Nz%(uid)s is not a panel userr�)rdr|r5)r�r5r5r6rAsz
--username)rdr|N)
rpr�r,r�rnr`rZr�rr�rgr�r|)rar�r�rzZ_username_messageZuser_packageZ_uid_messager�r5r5r6r}s,
(

zCloudlinuxLimits._check_userrc
Cs�|jr$|�dt��i�t|d�nXy tt|d�|�di��Wn6tk
rz}ztdt|�|f�Wdd}~XYnXt�	|�dS)z�
        Print error and exit

        :param message dict: Dictionary with keys "result" as string and optional "context" as dict
        reTrdr|zError: %s [%s]N)
rir:rhrr�r;rm�KeyError�sys�exit)rar�Z
error_coder�r5r5r6rn+s &z CloudlinuxLimits._error_and_exit)Frc)r),r2r3r4�__doc__rprir�r`r�r�rWrbrkrxrorrrtrurvr�r�r�r�rgr�r�r�r�rsr��staticmethodr�rqr�r�r�r�r�r~r�r�r}rn�
__classcell__r5r5)rYr6rTCsP
% :
 (Z,9
+rTc@s$eZdZdd�Zdd�Zdd�ZdS)rVcCs"t�|_t�|_t�|_i|_dS)N)rrZr"r\rr_r`)rar5r5r6rb>szCloudlinuxLimitsNoLve.__init__cCs>ddlm}yt||�d�}Wntk
r8d}YnX|S)z�
        Get package name by user id.
        None package returns as str(None) for user checker compatibility:
          'not str(None)' is True
        :param: id - user/lve id
        :return: Package name
        r)�reseller_package_by_uidrr�)�clcommon.cpapir�r;�
IndexError)raZuser_idr�Zpackage_namer5r5r6r�Ds
z1CloudlinuxLimitsNoLve.get_package_name_by_user_idc
sdi}|j}|j��rd|d<nd|d<t|dt�rB|d�d�nd�t�fdd�tD��}g}x�t|j	�D]�\}}|�
||�}|d	�r
|j���r
y$|j�|d
�}|r�dnd|d<WnNtk
�r}	z.d|d<d|kr�t�|d<t|	�|dd<Wdd}	~	XYnX|�
|�|d
<i|d<|�|�qlWt|�|d<||d<|d�sTg|d<|�|d�dS)z3
        Process output for selected users
        r�r�r�z--limitsrFNc3s |]}|�p|�kfVqdS)Nr5)r�r�)r�r5r6r�dsz9CloudlinuxLimitsNoLve._get_action_list.<locals>.<genexpr>r�rzr�r�r�r?r�r�z--for-resellerr�Tr)rpr\r�rfr;rIrgrr	r`r�r�r#r�r�r�rk)
rardr�r�r�r�rzr�r�r�r5)r�r6r�Ts8

 
"
z&CloudlinuxLimitsNoLve._get_action_listN)r2r3r4rbr�r�r5r5r5r6rV<srV)GZ
__future__rrrZ
past.builtinsrr�rhZclcommonrZclcommon.librrZfuture.utilsr	r
Z	cllicenser�collectionsrZ	lvectllibr
rrZarg_parsersrrrrrrrrrrZcllimits.clquota_librrrZutilsrZ	cli_utilsrr Zcllimitsr!r"r#r$r�r%r&r'r(r)r*r+r,r-r.Zclcommon.clexceptionr/Zclcommon.cpapi.cpapiexceptionsr0r1r�ZADMIN_RESELLER_NAMESr��objectrTrVr5r5r5r6�<module>sT00


Zerion Mini Shell 1.0