AlkantarClanX12

Your IP : 18.224.31.82


Current Path : /opt/cloudlinux/venv/lib64/python3.11/site-packages/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/__pycache__/lveapi.cpython-311.pyc

�

".gN���ddlZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZddlm
Z
mZddlmZ	ddlZn
#e$rdZYnwxYwddlmZe	��ZdZd	Zd
ZdZGd�d
e��ZGd�de��ZGd�de��ZGd�d��ZGd�d��ZGd�de��Z Gd�d��Z!Gd�d��Z"dS)�N)�Optional)�uid_max)�ProcLve)�cpapi�ClPwd)�NotSupported)�	ve_configi����reseller��c��eZdZdS)�NameMapErrorN��__name__�
__module__�__qualname__���py/lveapi.pyrr(��������Drrc��eZdZdS)�NameMapConfigErrorNrrrrrr,rrrc��eZdZdS)�NameMapNotInitializedNrrrrrr0rrrc�J�eZdZdZefd�Zd�Zd�Zd�Zdd�Z	d	�Z
d
d
�Zd�ZdS)�NameMapz�
    Container for backend storing resellers_name<=>resellers_id map
    As backend store use ve.cfg

    Usage:
    >>> name_map = NameMap()
    >>> name_map.link_xml_node()

    >>> name_map.id_list()
    [1001]
    c�0�||_d|_d|_dS�N)�
_xml_tag_name�	_xml_node�_reseller_id_name_map)�self�xml_tag_names  r�__init__zNameMap.__init__@s��)������%)��"�"�"rc�N�|���D]\}}||kr|cS�dSr��load_from_node)r"�name�name_�id_s    r�get_idzNameMap.get_idFsB���-�-�/�/�	�	�J�E�3���}�}��
�
�
��	�	rc�N�|���D]\}}||kr|cS�dSrr&)r"r*r)�_ids    r�get_namezNameMap.get_nameKsB���-�-�/�/�	�	�J�E�3��c�z�z������	�	rc�>�d�|���D��S)Nc��g|]\}}|��Srr)�.0�_r*s   r�
<listcomp>z#NameMap.id_list.<locals>.<listcomp>Qs��8�8�8���3��8�8�8rr&�r"s r�id_listzNameMap.id_listPs"��8�8�$�"5�"5�"7�"7�8�8�8�8rNTc�b�|�d|_|�|��dS||_d|_dS)aC
        Initialize NameMap. If xml_node is none,
        config will be loaded automatically
        :param use_cache: Bool whether bypass ve.cfg xml cache
        :param xml_node: !! DEPRECATED PARAM !!
                         this param is left only for
                         compatibility with our old code
        N)r �_load_resellers_map_from_ve_cfgr!)r"�xml_node�	use_caches   r�
link_xml_nodezNameMap.link_xml_nodeSsB����!�D�N��0�0��;�;�;�;�;�&�D�N�)-�D�&�&�&rc��g|_|�|���\}}|D]b}|�d��}t|�d����}|r'|r%||jvr|j�||f���c~~dS)zT
        Fills self._reseller_id_name_map from ve.cfg file
        :return:
        �r9�user�idN)r!�_try_get_xml_node�getAttribute�int�append)r"r9�ve_cfgr8�el_r(r*s       rr7z'NameMap._load_resellers_map_from_ve_cfges���
&(��"��1�1�I�1�F�F�����	?�	?�C��#�#�F�+�+�D��c�&�&�t�,�,�-�-�C��
?��
?��4�+E� E� E��*�1�1�3��+�>�>�>����F�Frc���	tj|���\}}n.#tj$r}d|_t	d��|�d}~wwxYw||�|j��fS)Nr<z-Error happened while loading data from ve.cfg)r	�get_xml_config�BadVeConfigExceptionr!r�getElementsByTagNamer)r"r9rCr8�es     rr?zNameMap._try_get_xml_nodeus���	]�(�7�)�L�L�L��F�H�H���-�	]�	]�	]�)-�D�&�$�%T�U�U�[\�\�����	]�����x�4�4�T�5G�H�H�H�Hs��A�A�Ac#�PK�|j�|j�td���|jrc|j�|j��D]C}|�d��}t
|�d����}|r|r||fV��D|jr|jD]
\}}||fV��dSdS)z?
        Obtain data from xml node as (name, id_) list
        NzLName map is not initialized. Use obj.link_xml_node() to get data from configr=r>)r r!rrHrr@rA)r"rDr(r*s    rr'zNameMap.load_from_node}s������>�!�d�&@�&H�'�)Z�[�[�
[��>�	$��~�:�:�4�;M�N�N�
$�
$���'�'��/�/���#�*�*�4�0�0�1�1���$�C�$���)�O�O�O���%�	 �!�7�
 �
 �	��T��C�i�����	 �	 �
 �
 r)NT)T)
rrr�__doc__�LVP_XML_TAG_NAMEr$r+r.r5r:r7r?r'rrrrr4s�������
�
�%5�*�*�*�*����
���
9�9�9�.�.�.�.�$��� I�I�I�I� � � � � rrc�p�eZdZdZd�Zd�Zd
d�Zd�Zd�Zd�Z	d	�Z
ed
���Zed���Z
d�ZdS)�LvpMapzl
    Container for storing information about lve:lvp mapping
    In which reseller container stored lve
    c�|�t��|_i|_i|_d|_t��|_dSr)r�name_map�_id_name_map�_name_id_map�_reseller_id_map_panelr�_pwdr4s rr$zLvpMap.__init__�s4���	�	��
�������&*��#��G�G��	�	�	rc�.�||j|<||j|<dSr)rQrR)r"r(r*s   r�_add_mapzLvpMap._add_map�s"��!%���#��"%���$���rNc�p�	|j�|��jS#tj$r|cYSwxYwr)rT�get_pw_by_name�pw_uidr�NoSuchUserException)r"r(�defaults   rrYz
LvpMap.pw_uid�sG��	��9�+�+�D�1�1�8�8���(�	�	�	��N�N�N�	���s�!�5�5c��|�|��}|�|S|j�tj��|_|j�|��Sr)rYrSr�get_reseller_id_pairs�get)r"r
�uids   r�_get_panel_reseller_idzLvpMap._get_panel_reseller_id�sP���k�k�(�#�#���?��J��&�.�*/�*E�*G�*G�D�'��*�.�.�x�8�8�8rc��|j�|��p|j�|��}|�|S	|�|��}n#t
$rd}YnwxYw|�|�||��|S)z�
        Convert reseller name to an LVE id.
        It supports resellers without a system account (for Plesk compatibility).
        N)rPr+rRr^r`rrV)r"r(r_s   r�get_reseller_idzLvpMap.get_reseller_id�s����m�"�"�4�(�(�G�D�,=�,A�,A�$�,G�,G���?��J�	��-�-�d�3�3�C�C���	�	�	��C�C�C�	�����?��M�M�$��$�$�$��
s�A�A�Ac�*�|j�|��p|j�|��}|�|S	t	j|��j}tj|��r|�	||��nd}n#t$rd}YnwxYw|S)z�
        Convert reseller id to reseller name
        It support resellers without system account (for Plesk compatibilyty)
        N)rPr.rQr^�pwd�getpwuid�pw_namer�is_resellerrV�KeyError)r"r*r(s   r�get_reseller_namezLvpMap.get_reseller_name�s����}�%�%�c�*�*�H�d�.?�.C�.C�C�.H�.H�����K�	��<��$�$�,�D�� ��&�&�
��
�
�d�C�(�(�(�(������	�	�	��D�D�D�	�����s�AB�B�Bc#��K�ttj����}i}|D]N}	|�|��||<�#t$r&tjt
jd|�d���Y�KwxYwtjd���D]\\}}|�|��}|�$tjt
jd|�d����@|�	|d��}||fV��]dS)z�
        This method loops over all user:reseller pairs in control panel
        and returns appropriate lve_id:lvp_id pairs.
        THIS METHOD WON'T CHECK IF 'RESELLER LIMITS' IS ENABLED IN ve.cfg
        z	Reseller �> still exists in control panel, but absent in /etc/passwd file)�cploginr
)�keylsN�user r)
�setr�	resellersrbr�syslog�LOG_WARNING�cpinforYr^)r"rp�
reseller_uidsr
rl�lve_id�lvp_ids       r�
lve_lvp_pairszLvpMap.lve_lvp_pairs�s`�������)�)�*�*�	��
�!�	J�	J�H�
J�*.�*>�*>�x�*H�*H�
�h�'�'���
J�
J�
J��
��&�)I�H�)I�)I�)I�J�J�J�J�J�
J����"'��4K�!L�!L�!L�	!�	!��G�X��[�[��)�)�F�
�~��
��&�)I��)I�)I�)I�J�J�J��"�&�&�x��3�3�F��&�.� � � � �	!�	!s�A�-A3�2A3c#�>K�tj��D]}|V��dSr)rrp)�
reseller_names rrpzLvpMap.resellers�s6����"�_�.�.�	 �	 �M������	 �	 rc��g}tj|��}|D]d}	tj|��j}|�|���2#t$r&tjtjd|�d���Y�awxYw|S)z:
        Obtain from control panel resellers uids
        rnrk)	r�reseller_usersrd�getpwnamrYrBrhrqrr)r(�uidsr{r=r*s     rrtzLvpMap.reseller_uids�s���
���-�d�3�3��"�	J�	J�D�
J��l�4�(�(�/�����C� � � � ���
J�
J�
J��
��&�)I��)I�)I�)I�J�J�J�J�J�
J�����s�.A�-A;�:A;c�V�|�|��}|�|��Sr)rirt)r"rvrys   r�lvp_lve_id_listzLvpMap.lvp_lve_id_list
s)���.�.�v�6�6�
��!�!�-�0�0�0rr)rrrrKr$rVrYr`rbrirw�staticmethodrprtrrrrrNrN�s������������&�&�&�����	9�	9�	9����"���&!�!�!�:� � ��\� �����\�� 1�1�1�1�1rrNc��eZdZdS)�
PyLveErrorNrrrrr�r�rrr�c��eZdZdZed���Zd�Zd�Zd�Ze	dddfd	�Z
d
�Zd�Zd�Z
eefd
�Zejd���ZdS)�PyLvezA
    Wrapper for generate traceback with pretty descriptions
    c�Z�t|t��o|tjko|dkS)Nr)�
isinstancerA�errno�ENOSYS)�codes r�_code_is_errorzPyLve._code_is_errors)���$��$�$�L��%�,��)>�L�4�1�9�Lrc����t�|jj��r5d��fd�t	���D����}d|�d�}nt���}|S)N�, c�d��g|],}|�d���|�dt�|������-S)r2�=)�
startswith�getattr)r1�attr�arg_vars  �rr3z%PyLve._arg_to_str.<locals>.<listcomp>sF���i�i�i��TX�Tc�Tc�dg�Th�Th�i�D�3�3�7�7�D�1�1�3�3�i�i�irz<liblve_settings object �>)r��_pylve�liblve_settings�join�dir�str)r"r��liblve_settings_attr�arg_var_strs `  r�_arg_to_strzPyLve._arg_to_strsr����g�t�{�:�;�;�	'�#'�9�9�i�i�i�i��G���i�i�i�$�$� �M�5I�L�L�L�K�K��g�,�,�K��rc���|�d�j��}|�d�j��}||i|��}��|��}|r=�jr6tj�j��||i|��}��|��}||j|j	d�
tt�j
|�����fd�|���D��z��d�}||j|j	d�
tt�j
|�����fd�|���D��z��d�}�jdkrt!�jjd	i|�����jdkr�j���|s|r|jd	i|��}	t+|	���|S)
N�err_msg�ignore_errorr�c�J��g|]\}}|�d��|������ S�r��r��r1�k�vr"s   �rr3z&PyLve._wrapped_fun.<locals>.<listcomp>5s9���I�I�I�$�!�Q�A�-�-��(�(��+�+�-�-�I�I�Ir)r��fun_name�module�args_c�J��g|]\}}|�d��|������ Sr�r�r�s   �rr3z&PyLve._wrapped_fun.<locals>.<listcomp>=s9���X�X�X���A�1� <� <�t�'7�'7��':�':� <� <�X�X�Xr�rr)�pop�default_msg_templater�r��_retry�time�sleep�_retry_timerrr��list�mapr��items�debug�print�debug_msg_template�format�	traceback�print_stackr�)
r"�call�args�kwargs�msg_templater�r��is_error�format_args�msgs
`         r�_wrapped_funzPyLve._wrapped_fun%s�����z�z�)�T�-F�G�G���z�z�.�$�2C�D�D���t�T�$�V�$�$���&�&�t�,�,���	1���	1��J�t�'�(�(�(��4��(��(�(�D��*�*�4�0�0�H���
��o��Y�Y��S��)�4�0�0�1�1�I�I�I�I�&�,�,�.�.�I�I�I�J���	
�
����
��o��Y�Y�t�C��(8�$�$?�$?�@�@�X�X�X�X������X�X�X� Y�Z�Z�	
�
���:��?�?��0�$�)�0�?�?�;�?�?�@�@�@��:��?�?��N�&�&�(�(�(��	"��	"�%�,�%�4�4��4�4�C��S�/�/�!��rc������fd�}|S)Nc�&���j�g|�Ri|��Sr)r�)r�r�r�r"s  ��r�funzPyLve._wrap_code.<locals>.funIs&���$�4�$�T�;�D�;�;�;�F�;�;�;rr)r"r�r�s`` r�
_wrap_codezPyLve._wrap_codeHs'����	<�	<�	<�	<�	<�	<��
rTg�������?rc�0�||_|jdkrtd��|_d|_d|_d|_||_||_t��|_	||_
|j���|_|jj
|_
|�|jj��|_|jj|_|�|jj��|_|�|jj��|_|jj|_|�|jj��|_|�|jj��|_|�|jj��|_|�|jj��|_|�|jj��|_t3|d��r�|�|jj��|_|�|jj��|_|�|jj��|_|�|jj��|_|�|j��|_dSdS)Nrr�z/Error code {code}; {module}.{fun_name}({args_})zBDEBUG [lvectl]: call {module}.{fun_name}({args_}) with code {code}F�lve_lvp_create)r��
__import__r�r�r�r�r�r�r�_procr��lve_get_api_version�api_version�
initializer��	lve_startr��
lve_create�lve_destroy�lve_info�lve_set_default�	lve_setup�
lve_enter_pid�lve_enter_pid_flags�
lve_leave_pid�hasattrr��lve_lvp_destroy�lve_lvp_map�lve_lvp_move�
lve_lvp_setup)r"�pylve�retry�
retry_tymer�s     rr$zPyLve.__init__Ms�����
��:��?�?�'��4�4�D�N�$U��!�"f���!����������Y�Y��
�%����;�:�:�<�<����+�0��������)>�?�?���#�{�:����/�/�$�+�*@�A�A����?�?�4�;�+B�C�C�����,��
�#���t�{�/J�K�K��������)>�?�?���!�_�_�T�[�-F�G�G���#'�?�?�4�;�3R�#S�#S�� �!�_�_�T�[�-F�G�G����5�*�+�+�	E�"&�/�/�$�+�2L�"M�"M�D��#'�?�?�4�;�3N�#O�#O�D� �#���t�{�/F�G�G�D�� $�����0H� I� I�D��"&����1C�!D�!D�D����	E�	Erc�,�t|jd��S)zB
        Check in pylve binding reseller limits supported
        r�)r�r�r4s r�resellers_supportedzPyLve.resellers_supportedns���t�{�$4�5�5�5rc�T�	|�|��dS#t$rYdSwxYw)zD
        Check if lve exists in kernel
        :rtype: bool
        TF)r��OSError)r"rus  r�
lve_existszPyLve.lve_existsts@��
	��M�M�&�!�!�!��4���	�	�	��5�5�	���s��
'�'c��|dkr|j�||��Si}|j�|��D]�}	|�|��}|||<|j|jkrJ|�|��}t
|j|j��|_|�||���x#t$rY��wxYw|�	|jj��}|||d���}|j�|��D]L}||vr|�|||���#|�||�|�����M|S)a�
        Wrapper for lve_lvp_setup.
        When reseller's limits changed,
        we should iterate over his user's limits
        and set them again;

        This behaviour is needed cause kernel
        does not update users limits after
        changing reseller's one

        Adjust parameters for top level container.
        :param int lvp_id: top level container ID, 0 by default;
        :param settings: liblve_settings instance.
        :return: 0 or errno value
        rT�r�)
r�r�r��lve_id_listr��ls_cpu�minr�r�r�)	r"rv�settings�real_lve_settingsru�
real_settings�
temp_settings�_lve_lvp_setup�results	         rr�zPyLve.lve_lvp_setup�sz��"�Q�;�;��;�,�,�V�X�>�>�>����j�,�,�V�4�4�	�	�F�
� $�
�
�f� 5� 5�
�,9�!�&�)� �'�(�/�9�9�$(�M�M�&�$9�$9�M�+.�}�/C�X�_�+U�+U�M�(��N�N�6�=�9�9�9����
�
�
���
����
�����)B�C�C������t�D�D�D���j�,�,�V�4�4�	>�	>�F��*�*�*����v�'8��'@�A�A�A�A�
���v�t�}�}�V�'<�'<�=�=�=�=��
s�A4B6�6
C�Cc��t|dz|��D],}	|�|���#t$r|cYcSwxYwtd|�d|�d����)z�
        Iter over lves and find available one.
        :param int start: value to start search from; UID_MAX by default
        :param int stop: max value when we will stop search
        :return int: lve_id
        r�z"Unable to find free lve in range (r��))�ranger�r�r�)r"�start�stoprus    r�get_available_lve_idzPyLve.get_available_lve_id�s����E�A�I�t�,�,�	�	�F�
��
�
�f�%�%�%�%���
�
�
��
�
�
�
�
�
�����N�e�N�N�t�N�N�N�O�O�Os�-�>�>c#�XK�||jc|_}	dV�||_dS#||_wxYwrr�)r"r��saved_ignore_errors   r�context_ignore_errorzPyLve.context_ignore_error�sJ����0<�d�>O�-���-�	3��E�E�E� 2�D����� 2�D��2�2�2�2s� �	)N)rrrrKr�r�r�r�r�r�r$r�r�r��UID_MAX�
MAX_LVE_IDr��
contextlib�contextmanagerr�rrrr�r�s����������M�M��\�M����!�!�!�F���
#�$�3�a�E�E�E�E�B6�6�6�	�	�	�4�4�4�l*1�z�P�P�P�P���3�3���3�3�3rr�c�F�eZdZdd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�ZdS)�LveNc��|p
t��|_|p
t��|_|p
t	��|_dSr)r�procr��pyrNr�)r"r�r�r�s    rr$zLve.__init__�s4���%�G�I�I��	��-�������?�&�(�(����rc#�K�t|jj�����}|j���D]\}}||vr||fV��|dfV��dS)a5
        Obtain {lve id}:{lvp id} pairs iterator based on ve.cfg config
        (detect enabled resellers containers)

        This method (unlike LvpMap.lve_lvp_pairs) will check
        if reseller is enabled in ve.cfg and return lvp_id=0
        for users of reseller with disabled reseller limits
        rN)ror�rPr5rw)r"�enabled_lvp_idrurvs    r�lve_id_lvp_id_pairszLve.lve_id_lvp_id_pairs�s~�����T�X�.�6�6�8�8�9�9��"�h�4�4�6�6�	 �	 �N�F�F���'�'��f�n�$�$�$�$��a�i�����		 �	 rc�N�|���D]\}}||kr|cS�dS)z\
        Obtain lvp id based on ve.cfg config (detect enabled resellers containers)
        r)r)r"ru�lve_id_�lvp_id_s    r�lve2lvpzLve.lve2lvp�sB��!%� 8� 8� :� :�	�	��G�W��� � �����!��qrc��tj�|j�����r.|j����|d��}nd}|jj|g|�Ri|��|dkrC	tj
|��|j�||��dS#t$rYdSwxYwdS)zH
        safe destroy lve container with preserving lvp mapping
        rN)
�os�path�existsr��proc_lve_mapr�r^r�r�rdrer�rh)r"rur�r�rvs     rr�zLve.lve_destroy�s����7�>�>�$�)�0�0�2�2�3�3�	��Y�]�]�_�_�(�(���3�3�F�F��F�����F�4�T�4�4�4�V�4�4�4��Q�;�;�
���V�$�$�$���#�#�F�F�3�3�3�3�3���
�
�
����
����	�;s�/B5�5
C�Cc�J�|j���}|���D]t\}}|�|d��|krU|j�|���s|j�|��|j�||��|||<�udS)z4
        Load lve_id:lvp_id map to kmod-lve
        r)rvN)r�r�rr^�	exist_lvpr�r�r�)r"�
proc_map_dictrurvs    r�	_sync_mapz
Lve._sync_map�s���
�	�
�
���
�#�6�6�8�8�	/�	/�N�F�F�� � ���+�+�v�5�5��y�*�*�&�*�9�9�3��G�*�*�6�2�2�2���$�$�V�V�4�4�4�(.�
�f�%��	/�	/rc�R�	|���dS#t$rYdSwxYw)zZ
        wrapped _sync_map function for prevent error if some cpapi not supported
        N)rrr4s r�sync_mapzLve.sync_maps?��	��N�N��������	�	�	��D�D�	���s��
&�&c�L�	tj��S#t$rYdSwxYw)z^
        Check if current panel supported for reseller's limits;
        :rtype: bool
        F)r�is_reseller_limits_supportedrr4s r�is_panel_supportedzLve.is_panel_supporteds8��
	��5�7�7�7���	�	�	��5�5�	���s��
#�#c��t|j���|j���|���f��S)zo
        Check present all needed (kmod-lve, liblve, /proc/lve, panel) for manipulate resellers limits
        )�allr�r�r�rr4s r�reseller_limit_supportedzLve.reseller_limit_supported"sK���D�G�/�/�1�1��I�1�1�3�3��+�+�-�-�/�0�0�	0rc��t|j���|j���f��S)zh
        Check present all needed (kmod-lve, liblve, /proc/lve) for manipulate resellers limits
        )rr�r�r�r4s r�is_lve10zLve.is_lve10*s3���D�G�/�/�1�1�4�9�3P�3P�3R�3R�S�T�T�Tr)NNN)rrrr$rrr�rrrrrrrrr�r��s�������#�#�#�#�
 � � � ������ /�/�/�$������0�0�0�U�U�U�U�Urr�)#r�rr�rqr�rd�typingr�clcommon.clfuncr�clcommon.clprocr�clcommonrr�clcommon.cpapi.cpapiexceptionsrr��ImportError�
clveconfigr	r�r�rL�
LVE_NO_UBC�LVE_NO_MAXENTER�	ExceptionrrrrrNr�r�r�rrr�<module>r#s�������	�	�	�	�����
�
�
�
�����
�
�
�
�������#�#�#�#�#�#�#�#�#�#�#�#�!�!�!�!�!�!�!�!�7�7�7�7�7�7���L�L�L�L�������E�E�E�����!� � � � � ��'�)�)���
���
�
���
	�	�	�	�	�9�	�	�	�	�	�	�	�	��	�	�	�	�	�	�	�	�L�	�	�	�[ �[ �[ �[ �[ �[ �[ �[ �|z1�z1�z1�z1�z1�z1�z1�z1�z	�	�	�	�	��	�	�	�x3�x3�x3�x3�x3�x3�x3�x3�v`U�`U�`U�`U�`U�`U�`U�`U�`U�`Us�?�A	�A