AlkantarClanX12

Your IP : 3.133.117.107


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

�

�ugJ9���ddlZddlZddlZddlZddlZddlmZmZmZm	Z	ddl
Z
ddlmZddl
mZmZmZddl
mZmZddlmZddlmZdd	lmZdd
lmZmZmZddlmZmZmZm Z m!Z!ddl"m#Z#m$Z$dd
l%m&Z&ddl'm(Z(m)Z)m*Z*Gd�d��Z+dS)�N)�Any�Optional�Dict�NoReturn)�FormattedException)�run_command�ExternalProgramFailed�get_cl_version)�get_package_db_errors�	is_ubuntu)�NoSuchModule�)�acquire_config_access)�Config)�run_installation�ALL_MODULES�get_supported_modules)�WizardStatus�ModuleStatus�CRASH_LOG_PATH�FILE_MARKER_PATH�
MAIN_LOG_PATH)�CancelModuleException�InstallationFailedException)�parse_cloudlinux_wizard_opts)�is_background_process_running�run_background�setup_loggerc���eZdZdZejejejgZej	ejej
gZd�Zd�Z
ed���Zd�Zdd�Zd�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zedd���ZdS)�CloudlinuxWizardzAMain class for working with Wizard that exposes high level logic.c�n�d|_t��|_tdt��|_dS)Nzwizard.main)�_optsr�_supported_modulesrr�log��selfs �F/opt/cloudlinux/venv/lib64/python3.11/site-packages/clwizard/wizard.py�__init__zCloudlinuxWizard.__init__>s,����
�"7�"9�"9����
�}�=�=�����c���t|��|_	|jjdkr�|���|���r#|jjs|�dd���|���|jjrt��n�|�
|jj���n�|jjdkrJ|���|jjr|�
��nq|���n\|jjdkr |�|jj��n,|jjdkr|���nt$�|jjd	vr|���s$|jjdkr<|���s(|���|���|���dS#t,$r[}|j�d
t3|����|�|j|j|jd���Yd}~dSd}~wt:$r|�d
d���YdSt<$r[}|j�dt3|����|�dtAj!�����Yd}~dSd}~wwxYw)zv
        CL Wizard main function
        :param argv: command line arguments for wizard
        :return: None
        �installzInstallation already finishedr��result�	exit_code)�options�status�cancel�finish)r+r1z;Got an error while running cloudlinux-wizard, message: '%s')r-�context�detailsr.Nz<Module installation failed, see the log for more informationz&Unknown error in cloudlinux-wizard, %szVUnknown error occured, please, try again or contact CloudLinux support if it persists.)r-r4)"rr"�	subparser�_validate_system�is_installation_finished�force�_print_result_and_exit�_prepare_for_installation�no_asyncr�run_background_installation�	json_data�initial�_get_initial_status�_get_modules_statuses�_cancel_module_installation�module�create_completion_marker�NotImplementedError�is_all_modules_installed�run_collecting_statistics�run_cagefs_force_updaterr$�error�str�messager3r4r�	Exception�	exception�	traceback�
format_exc)r&�argv�errs   r'�runzCloudlinuxWizard.runCs^��2�$�7�7��
�>	��z�#�y�0�0��%�%�'�'�'��0�0�2�2��4�:�;K���/�/�>�!�0�����.�.�0�0�0��:�&�S�$�&�&�&�&��4�4�T�Z�=Q�4�R�R�R�R���%��1�1��%�%�'�'�'��:�%�1��,�,�.�.�.�.��.�.�0�0�0�0���%��1�1��0�0���1B�C�C�C�C���%��1�1��-�-�/�/�/�/�)�)��
�$�(=�=�=��1�1�3�3�>��
�$��0�0��9V�9V�9X�9X�0��.�.�0�0�0��,�,�.�.�.��'�'�)�)�)�)�)��!�	�	�	��H�N�N�M�s�SV�x�x�
�
�
�
�'�'��{�C�K���XY�
(�
�
�
�
�
�
�
�
�
�����+�	�	�	��'�'�U��
(�
�
�
�
�
�
��	�	�	��H���G��S���R�R�R��'�'�@�!�,�.�.�
(�
�
�
�
�
�
�
�
�
�����	���s,�G#G;�;
K&�AI�$K&�	K&�AK!�!K&c�J�tj�t��S�N)�os�path�isfiler�r)r'r7z)CloudlinuxWizard.is_installation_finished�s���w�~�~�.�/�/�/r)c�*�	tjt��|j�d��dS#t
tf$rJ}|j�dt|����|�	dd���Yd}~dSd}~wwxYw)NzWizard execution completez:Wizard 'finish' command called more than once, error: '%s'z-Wizard 'finish' command called more than oncerr,)
rT�mknodrr$�info�OSError�IOError�warningrIr9)r&rPs  r'rCz)CloudlinuxWizard.create_completion_marker�s���		��H�%�&�&�&��H�M�M�5�6�6�6�6�6����!�	�	�	��H���L�c�RU�h�h�
�
�
�
�'�'�F�RS�
(�
�
�
�
�
�
�
�
�
�����		���s�37�B�?B
�
BNc��tjdd�}|�d��t��5}t	��r|�dd���|�|�|��t|��j}||_	ddd��n#1swxYwY|�d|���dS)Nz
--no-asynczMUnable to start a new installation because a background task is still workingrr,�success)r-�pid)
�sysrO�appendrrr9�set_modulesrr`�
worker_pid)r&r/�cmd�configrds     r'r<z,CloudlinuxWizard.run_background_installation�s
���h�q�q�q�k���
�
�<� � � �
"�
$�
$�	+��-�.�.�
��+�+�9��,�����"��"�"�7�+�+�+�(��,�,�0�J� *�F��	+�	+�	+�	+�	+�	+�	+�	+�	+�	+�	+����	+�	+�	+�	+� 	
�#�#�9�*�#�E�E�E�E�Es�AB�B �#B c�R�t���|�d���dSdS)z;
        Check that wizard supports current system
        Nz�Could not identify the CloudLinux version. Restart your system. If you have the same problem again - contact CloudLinux support.�r-)r
r9r%s r'r6z!CloudlinuxWizard._validate_system�sD�����#��'�'�.�
(�
�
�
�
�
�$�#r)c��t��rfgd�}	t|��}|j�d|��dS#t$r(}|j�d||���Yd}~dSd}~wwxYwgd�}	t|��}|j�d|��dS#t$r(}|j�d||���Yd}~dSd}~wwxYw)	z�
        Prepare the enviroment before performing the installation.
        This function updates the package lists if run on Ubuntu, expires Yum
        cache when running on RHEL-based systems.
        )zapt-getz-q�updatezapt-get update output:
%sz!Error during apt-get update: '%s')�exc_infoN)�yumz-qy�cleanzexpire-cachez!yum clean expire-cache output:
%sz)Error during yum clean expire-cache: '%s')rrr$rZr	rH�r&re�outrPs    r'r:z*CloudlinuxWizard._prepare_for_installation�s+���;�;�
	_�-�-�-�C�
W�!�#�&�&����
�
�:�C�@�@�@�@�@��(�
W�
W�
W�����B�C�RU��V�V�V�V�V�V�V�V�V�����
W����:�9�9�C�
_�!�#�&�&����
�
�B�C�H�H�H�H�H��(�
_�
_�
_�����J�C�Z]��^�^�^�^�^�^�^�^�^�����
_���s/�*A�
A2�
A-�-A2�:*B&�&
C�0C�Cc�&�|j|jS)zGet path to module log file)r#�LOG_FILE)r&�module_names  r'�_get_module_log_pathz%CloudlinuxWizard._get_module_log_path�s���&�{�3�<�<r)c�0�g}t��5}|�|��}|jD]�}	|�|��}|�|��}n#t
$rY�:wxYw|||d�}|tjtjfvr|�	|��|d<|�
|����	ddd��n#1swxYwY|tjkr|�
||t���|�
||���dS)z?
        Get information about background worker state
        )r0�name�status_time�log_fileN)�
wizard_status�modules�	crash_log)rxry)r�_get_wizard_stater#�get_module_status�get_module_status_timer
r�FAILED�AUTO_SKIPPEDrsrbr�CRASHEDr9r)r&ryrf�staterur0rv�
module_statuss        r'r@z&CloudlinuxWizard._get_modules_statuses�s�����
"�
$�
$�	.���*�*�6�2�2�E��/�

.�

.���#�5�5�d�;�;�F�"(�"?�"?��"E�"E�K�K��#�����H�����%� �#.�!�!�
�
�l�1�<�3L�M�M�M�04�0I�0I�$�0O�0O�M�*�-����}�-�-�-�-�

.�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.����	.�	.�	.�	.� �L�(�(�(��'�'�#�W��
(�
�
�
�	
�#�#�%��#�I�I�I�I�Is5�C�*A�C�
A)�&C�(A)�)AC�C�Cc	�.�t��}|r|�|���dS|�d�|j���D��t	tt��t|j��z
�����dS)zg
        Get initial modules status that is used
        by lvemanager to display wizard pages
        rhc�N�i|]"\}}||�������#SrW)�initial_status)�.0rr�clss   r'�
<dictcomp>z8CloudlinuxWizard._get_initial_status.<locals>.<dictcomp>�s@�����(��S� �����!5�!5�!7�!7���r))ry�unsuppored_by_cpN)rr9r#�items�list�setr)r&�
error_messages  r'r?z$CloudlinuxWizard._get_initial_status�s���
.�/�/�
��
	��'�'�}�'�=�=�=�=�=��'�'���,0�,C�,I�,I�,K�,K����"&�c�+�&6�&6��T�=T�9U�9U�&U�!V�!V�
(�
�
�
�
�
r)c��|j�d|��t��5}|�|��}||jvr=|�|tj���|j�d|��n,|j�d||��t||���	ddd��dS#1swxYwYdS)z@Remove module from queue or print the error if it's not possiblez0Trying to cancel the installation of module '%s')rr�	new_statez.Module '%s' installation successfully canceledzGUnable to cancel module '%s' installation, because it is in status '%s'N)
r$rZrr|�CANCELLABLE_MODULE_STATUSES�set_module_statusr�	CANCELLEDr]r)r&rBrfr0s    r'rAz,CloudlinuxWizard._cancel_module_installations(��	
��
�
�H�&�Q�Q�Q�
"�
$�
$�	<���-�-�f�5�5�F���9�9�9��(�(� &�,�2H�)������
�
�N�PV�W�W�W�W��� � �3���	���,�F�F�;�;�;�X�
	<�	<�	<�	<�	<�	<�	<�	<�	<�	<�	<�	<����	<�	<�	<�	<�	<�	<s�BC�C�Cc�f�ddg}tj�d��s|�d��|j�d��	t
|��}|j�d|��dS#t$r&}|j�d|��Yd}~dSd}~wwxYw)	z,
        Collects user`s statistics
        z/usr/sbin/cloudlinux-summaryz--send�SYNCHRONOUS_SUMMARYz--asynczCollecting statistics...z*Statistics collection command output: '%s'z(Error during statistics collection: '%s'N)	rT�environ�getrbr$rZrr	rHrns    r'rFz*CloudlinuxWizard.run_collecting_statisticss���.�x�8���z�~�~�3�4�4�	"��J�J�y�!�!�!���
�
�0�1�1�1�	L��c�"�"�C��H�M�M�F��L�L�L�L�L��$�	L�	L�	L��H�N�N�E�s�K�K�K�K�K�K�K�K�K�����	L���s�*B�
B0�
B+�+B0c����t��5}t|j�����}ddd��n#1swxYwYt	�fd�|D����S)zy
        Check that all modules were either:
        -- installed
        -- canceled
        -- or auto-skipped
        Nc3�*�K�|]
}|�jvV��dSrS��DONE_MODULES_STATUSES�r�r0r&s  �r'�	<genexpr>z<CloudlinuxWizard.is_all_modules_installed.<locals>.<genexpr>3�+�����O�O�F�6�T�7�7�O�O�O�O�O�Or))rr��statuses�values�all�r&rfr�s`  r'rEz)CloudlinuxWizard.is_all_modules_installed)s����#�
$�
$�	6���F�O�2�2�4�4�5�5�H�	6�	6�	6�	6�	6�	6�	6�	6�	6�	6�	6����	6�	6�	6�	6��O�O�O�O�h�O�O�O�O�O�Os�'A�A�
Ac�2�d}tj�|��sdS|ddg}|j�d|��t|��}t
tj�d����}|r|�	��dSdS)z=
        Runs cagefsctl --force-update in background
        z/usr/sbin/cagefsctlNz--force-updatez--wait-lockz2Starting cagefs force-update in the background: %s�CL_TEST_SYSTEM)
rTrUrVr$rZr�boolr�r��communicate)r&�
cagefsctl_binre�cagefsctl_proc�is_test_environments     r'rGz(CloudlinuxWizard.run_cagefs_force_update5s���.�
��w�~�~�m�,�,�	��F��.�
�>����
�
�J�C�P�P�P�'��,�,��"�2�:�>�>�2B�#C�#C�D�D���	)��&�&�(�(�(�(�(�	)�	)r)c����|j�tjS	tj|j��n�#tj$r�t
|j�����}t�fd�|D����rtj
cYStd�|D����r'td�|D����stjcYStj
cYSwxYwtjS)Nc3�*�K�|]
}|�jvV��dSrSr�r�s  �r'r�z5CloudlinuxWizard._get_wizard_state.<locals>.<genexpr>Vr�r)c3�JK�|]}|tjtjfvV��dSrS)rr~r��r�r0s  r'r�z5CloudlinuxWizard._get_wizard_state.<locals>.<genexpr>ZsF��������|�2�L�4J�K�K������r)c3�4K�|]}|tjfvV��dSrS)r�
INSTALLINGr�s  r'r�z5CloudlinuxWizard._get_wizard_state.<locals>.<genexpr>]s-����V�V�6�&�\�%<�$>�>�V�V�V�V�V�Vr))rdr�IDLE�psutil�Process�
NoSuchProcessr�r�r�r��DONE�anyr~r��IN_PROGRESSr�s`  r'r{z"CloudlinuxWizard._get_wizard_stateEs���
��$��$�$�	(��N�6�,�-�-�-�-���#�	(�	(�	(��F�O�2�2�4�4�5�5�H��O�O�O�O�h�O�O�O�O�O�
)�#�(�(�(�(����"*������
+��V�V�X�V�V�V�V�V�
+�$�*�*�*�*��'�'�'�'�!	(����$�'�'s�0�AC�>C�C�Cr_rc���|tj��d�}|�|��ttj|dd�����tj|��dS)z�
        Print data in default format for web and exit
        :param dict extra: extra fields for the response,
                           usually we expect 'context' here
        )r-�	timestamp�T)�indent�	sort_keysN)�timerj�print�json�dumpsra�exit)r-r.�extrarJs    r'r9z'CloudlinuxWizard._print_result_and_exitcs^��$�$�)�+�+�>�>�����u����
�d�j���d�;�;�;�<�<�<��������r)rS)r_r)�__name__�
__module__�__qualname__�__doc__r�PENDINGr~r�r��	INSTALLEDrr�r(rQ�staticmethodr7rCr<r6r:rsr@r?rArFrErGr{r9rWr)r'r r -sx������K�K�	������#��	�����!���>�>�>�
E�E�E�N�0�0��\�0����F�F�F�F�,	�	�	�_�_�_�,=�=�=�J�J�J�:���$<�<�<�(
L�
L�
L�
P�
P�
P�)�)�)� (�(�(�<�
�
�
��\�
�
�
r)r ),r�rTrar�rM�typingrrrrr��clcommonr�clcommon.utilsrr	r
rr�clwizard.configr
rfrrryrrr�	constantsrrrrr�
exceptionsrr�parserr�utilsrrrr rWr)r'�<module>r�s�������	�	�	�	�
�
�
�
���������0�0�0�0�0�0�0�0�0�0�0�0�
�
�
�
�'�'�'�'�'�'�����������
<�;�;�;�;�;�;�;�(�(�(�(�(�(�)�)�)�)�)�)�������I�I�I�I�I�I�I�I�I�I���������������K�J�J�J�J�J�J�J�0�0�0�0�0�0�����������A�A�A�A�A�A�A�A�A�Ar)