관리-도구
편집 파일: user_limits.cpython-311.pyc
� b��f � �H � d Z ddlZddlZ G d� de� � Zd� Zd� Zd� ZdS )zW This module provides functions to retrieve any limits and usage for a specified user. � Nc � � e Zd Zd� ZdS )�LveCommandErrorc � � | j d � S )Nr )�args)�selfs �P/opt/cloudlinux/venv/lib64/python3.11/site-packages/xray/internal/user_limits.py�__str__zLveCommandError.__str__ s � ��)�A�,� � � N)�__name__� __module__�__qualname__r � r r r r s# � � � � � �!� !� !� !� !r r c � � � ddd� dg} t |� � }t j |� � }nF# t $ r}dt |� � icY d}~S d}~wt j $ r}dd|� �icY d}~S d}~ww xY wd|vs!t � fd �|d D � � � � sdd � � d�iS t � fd�|d D � � � � }d t |d d � d� � � � id t |d � d� � � � id t |d � d� � � � id t |d � d� � � � id t |d d � d� � � � dz id t |d � d� � � � id�S )a� Retrieves the LVE limits for a specified user. Args: username (str): The username to retrieve LVE limits for. Returns: When user limits are found { "lve_cpu": { "limit": int }, "lve_ep": { "limit": int }, "lve_pmem": { "limit": int }, "lve_iops": { "limit": int }, "lve_io": { "limit": int }, "lve_nproc": { "limit": int }, } or an error { "error": str } z/usr/sbin/cloudlinux-limits�getz --usernamez--json�errorNzFailed to decode JSON: �usersc 3 �0 �K � | ]}|d �k V � �dS )�usernameNr ��.0�userr s �r � <genexpr>z!get_lve_limits.<locals>.<genexpr>? s- �� � � �'a�'a���Z�(8�H�(D�'a�'a�'a�'a�'a�'ar zLVE Limit for user z not foundc 3 �@ �K � | ]}|d �k �|d V � �dS )r �limitsNr r s �r r z!get_lve_limits.<locals>.<genexpr>B s7 �� � � �b�b�$�T�*�EU�Ya�Ea�Ea�t�H�~�Ea�Ea�Ea�Ea�b�br �limit�cpu�all�*�ep�pmem�iops�io� �nproc��lve_cpu�lve_ep�lve_pmem�lve_iops�lve_io� lve_nproc) �_call_lve_command�json�loadsr �str�JSONDecodeError�any�next�int�strip)r �cmd�stdoutr �e�user_limitss ` r �get_lve_limitsr9 s/ �� �D )�%��x�� R�C�8�"�3�'�'����F�#�#����� !� !� !���Q��� � � � � � � ������� 8� 8� 8��6�1�6�6�7�7�7�7�7�7�7�����8���� �f���C�'a�'a�'a�'a�QW�X_�Q`�'a�'a�'a�$a�$a���C�x�C�C�C�D�D��b�b�b�b�&��/�b�b�b�b�b�K� �S��U�+�E�2�8�8��=�=�>�>� � �S��T�*�0�0��5�5�6�6� � �S��V�,�2�2�3�7�7�8�8� � �S��V�,�2�2�3�7�7�8�8� � �S��T�*�5�1�7�7��<�<�=�=��D� � �S��W�-�3�3�C�8�8�9�9� �!� � s, �#. � A1�A�A1�A1� A,�&A1�,A1c �p � g d�} t |� � }|� � � � d� � }n(# t $ r}dt |� � icY d}~S d}~ww xY wi }|dd� D ]�}|� � � }|d | k r�dt |d � d � � � � idt |d � � idt |d � � dz dz idt |d � � idt |d � � idt |d � � id�} n��|S )a� Retrieves the current LVE usage for a specified user. Args: username (str): The username to retrieve LVE usage for. Returns: When user usage are found { "lve_cpu": { "usage": int }, "lve_ep": { "usage": int }, "lve_pmem": { "usage": int }, "lve_iops": { "usage": int }, "lve_io": { "usage": int }, "lve_nproc": { "usage": int }, } or empty dict when user sleep {} or an error { "error": str } )z/usr/sbin/lvepsz-dz-oz*id:15,ep:7,pno:7,cpu:7,mem:9,io:11,iops:11� r N� r �usage� �%� r# � � � r% )r, r4 �splitr r/ r3 )r r5 r6 �linesr7 r= �line�fieldss r � get_lve_usagerH Z st � �H X� W� W�C�!�"�3�'�'�������$�$�T�*�*����� !� !� !���Q��� � � � � � � �����!���� �E��a�b�b� � � ���������!�9�� � � �S�������!5�!5�6�6�� �S����^�^�� �S����^�^�d�2�T�9�� �S����^�^�� �S����^�^�� �S����^�^��!� �E�( �E�+ !�. �Ls �6= � A"�A�A"�A"c �� � t j | ddd�� � }|j S # t j $ r}t d| � d|� �� � �d }~wt $ r}t d|� �� � �d }~ww xY w)NT)�capture_output�text�checkz Command 'z' failed with error: zAn unexpected error occurred: )� subprocess�runr6 �CalledProcessErrorr � Exception)r5 �resultr7 s r r, r, � s� � �D����D�t�4�P�P�P���}����(� I� I� I��G�#�G�G�A�G�G�H�H�H������ D� D� D��B�q�B�B�C�C�C�����D���s �! �A)�A� A)�A$�$A))�__doc__rM r- rP r r9 rH r, r r r �<module>rS s� ��� � � � � � ����!� !� !� !� !�i� !� !� !� C� C� C�LE� E� E�PD� D� D� D� Dr