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/clwizard/__pycache__/wizard.cpython-37.opt-1.pyc
B

�S�;�����@s0ddlmZddlmZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZmZddl
Z
ddlmZddlmZmZmZddlmZddlmZdd	lmZd
dlmZd
dlmZd
d
lmZmZmZd
dl m!Z!m"Z"m#Z#m$Z$m%Z%d
dl&m'Z'm(Z(d
dl)m*Z*d
dl+m,Z,m-Z-m.Z.Gdd�de/�Z0dS)�)�print_function)�absolute_importN)�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@s�eZdZdZejejejgZej	ejej
gZdd�Zdd�Z
edd��Zdd	�Zd%dd�Zd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zed&d#d$��Zd
S)'�CloudlinuxWizardzAMain class for working with Wizard that exposes high level logic.cCsd|_t�|_tdt�|_dS)Nzwizard.main)�_optsr�_supported_modulesrr�log)�self�r%�py/clwizard/wizard.py�__init__CszCloudlinuxWizard.__init__c
Cs�t|�|_�y
|jjdkrj|��|��r@|jjs@|jddd�|��|jjrXt	�q�|j
|jjd�nf|jjdkr�|��|jjr�|�
�q�|��n6|jjdkr�|�|jj�n|jjdkr�|��nt�|jjd	kr�|��s�|jjdk�r|���s|��|��|��Wn�tk
�rd}z.|j�d
t|��|j|j|j|jdd�Wdd}~XYnjtk
�r�|jd
dd�YnHtk
�r�}z(|j�dt|��|jdt �!�d�Wdd}~XYnXdS)zv
        CL Wizard main function
        :param argv: command line arguments for wizard
        :return: None
        �installzInstallation already finishedr)�result�	exit_code)�options�status�cancelZfinish)r(r-z;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)r/)"rr!Z	subparser�_validate_system�is_installation_finishedZforce�_print_result_and_exit�_prepare_for_installationZno_asyncr�run_background_installationZ	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�messager.r/r�	ExceptionZ	exception�	traceback�
format_exc)r$�argv�errr%r%r&�runHsR




$zCloudlinuxWizard.runcCstj�t�S)N)�os�path�isfilerr%r%r%r&r1�sz)CloudlinuxWizard.is_installation_finishedc
Csfyt�t�|j�d�WnFttfk
r`}z$|j�dt|��|j	ddd�Wdd}~XYnXdS)NzWizard execution completez:Wizard 'finish' command called more than once, error: '%s'z-Wizard 'finish' command called more than oncer)r)r*)
rH�mknodrr#�info�OSError�IOError�warningr@r2)r$rFr%r%r&r:�s
z)CloudlinuxWizard.create_completion_markerNc	Csrtjdd�}|�d�t��<}t�r4|jddd�|dk	rF|�|�t|�j}||_	WdQRX|jd|d�dS)Nz
--no-asynczMUnable to start a new installation because a background task is still workingr)r)r*�success)r)�pid)
�sysrE�appendrrr2Zset_modulesrrQ�
worker_pid)r$r+�cmd�configrTr%r%r&r4�s


z,CloudlinuxWizard.run_background_installationcCst�dkr|jdd�dS)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))rr2)r$r%r%r&r0�s
z!CloudlinuxWizard._validate_systemc
Cs�t�rbdddg}yt|�}|j�d|�Wq�tk
r^}z|jjd||d�Wdd}~XYq�Xn\dd	d
dg}yt|�}|j�d|�Wn4tk
r�}z|jjd
||d�Wdd}~XYnXdS)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_infoNZyumz-qyZcleanzexpire-cachez!yum clean expire-cache output:
%sz)Error during yum clean expire-cache: '%s')r
r	r#rLr
r?)r$rU�outrFr%r%r&r3�s
&z*CloudlinuxWizard._prepare_for_installationcCs|j|jS)zGet path to module log file)r"ZLOG_FILE)r$�module_namer%r%r&�_get_module_log_path�sz%CloudlinuxWizard._get_module_log_pathc
Cs�g}t���}|�|�}xr|jD]h}y|�|�}|�|�}Wntk
rPwYnX|||d�}|tjtjgkr||�	|�|d<|�
|�qWWdQRX|tjkr�|j
||td�|j
||d�dS)z?
        Get information about background worker state
        )r,�name�status_timeZlog_fileN)�
wizard_status�modulesZ	crash_log)r^r_)r�_get_wizard_stater"�get_module_statusZget_module_status_timerr�FAILED�AUTO_SKIPPEDr[rSr�CRASHEDr2r)r$r_rV�stater\r,r]Z
module_statusr%r%r&r7�s&


z&CloudlinuxWizard._get_modules_statusescCsLt�}|r|j|d�n0|jdd�|j��D�ttt�t|j��d�dS)zg
        Get initial modules status that is used
        by lvemanager to display wizard pages
        )r)cSsi|]\}}|���|�qSr%)Zinitial_status)�.0rZ�clsr%r%r&�
<dictcomp>sz8CloudlinuxWizard._get_initial_status.<locals>.<dictcomp>)r_Zunsuppored_by_cpN)rr2r"�items�list�setr)r$Z
error_messager%r%r&r6�sz$CloudlinuxWizard._get_initial_statusc	Csr|j�d|�t��T}|�|�}||jkrJ|j|tjd�|j�d|�n|j�d||�t	||��WdQRXdS)z@Remove module from queue or print the error if it's not possiblez0Trying to cancel the installation of module '%s')rZZ	new_statez.Module '%s' installation successfully canceledzGUnable to cancel module '%s' installation, because it is in status '%s'N)
r#rLrra�CANCELLABLE_MODULE_STATUSESZset_module_statusr�	CANCELLEDrOr)r$r9rVr,r%r%r&r8s

z,CloudlinuxWizard._cancel_module_installationc
Cszddg}tj�d�s|�d�|j�d�yt|�}|j�d|�Wn0tk
rt}z|j�d|�Wdd}~XYnXdS)	z,
        Collects user`s statistics
        z/usr/sbin/cloudlinux-summaryz--sendZSYNCHRONOUS_SUMMARYz--asynczCollecting statistics...z*Statistics collection command output: '%s'z(Error during statistics collection: '%s'N)	rH�environ�getrSr#rLr	r
r?)r$rUrYrFr%r%r&r= s
z*CloudlinuxWizard.run_collecting_statisticsc	s6t��}t|j���}WdQRXt�fdd�|D��S)zy
        Check that all modules were either:
        -- installed
        -- canceled
        -- or auto-skipped
        Nc3s|]}|�jkVqdS)N)�DONE_MODULES_STATUSES)rfr,)r$r%r&�	<genexpr>9sz<CloudlinuxWizard.is_all_modules_installed.<locals>.<genexpr>)rrj�statuses�values�all)r$rVrrr%)r$r&r</sz)CloudlinuxWizard.is_all_modules_installedcCsTd}tj�|�sdS|ddg}|j�d|�t|�}ttj�d��}|rP|�	�dS)z=
        Runs cagefsctl --force-update in background
        z/usr/sbin/cagefsctlNz--force-updatez--wait-lockz2Starting cagefs force-update in the background: %sZCL_TEST_SYSTEM)
rHrIrJr#rLr�boolrnroZcommunicate)r$Z
cagefsctl_binrUZcagefsctl_procZis_test_environmentr%r%r&r>;s
z(CloudlinuxWizard.run_cagefs_force_updatecs�|jdkrtjSyt�|j�Wnltjk
r�t|j���}t	�fdd�|D��r\tj
Stdd�|D��r�tdd�|D��s�tjStj
SXtjSdS)Nc3s|]}|�jkVqdS)N)rp)rfr,)r$r%r&rq\sz5CloudlinuxWizard._get_wizard_state.<locals>.<genexpr>css|]}|tjtjfkVqdS)N)rrbrm)rfr,r%r%r&rqascss|]}|tjfkVqdS)N)rZ
INSTALLING)rfr,r%r%r&rqcs)rTrZIDLE�psutilZProcessZ
NoSuchProcessrjrrrsrtZDONE�anyrbrdZIN_PROGRESS)r$rVrrr%)r$r&r`Ks

z"CloudlinuxWizard._get_wizard_staterPrcKs:|t��d�}|�|�ttj|ddd��t�|�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)Z	timestamp�T)�indentZ	sort_keysN)�timerW�print�json�dumpsrR�exit)r)r*ZextrarAr%r%r&r2is
z'CloudlinuxWizard._print_result_and_exit)N)rPr)�__name__�
__module__�__qualname__�__doc__rZPENDINGrbrmrlZ	INSTALLEDrcrpr'rG�staticmethodr1r:r4r0r3r[r7r6r8r=r<r>r`r2r%r%r%r&r 2s0H
r )1Z
__future__rrr|rHrRrzrC�typingrrrrrvZclcommonrZclcommon.utilsr	r
rrZclcommon.lib.cleditionr
Zclwizard.configrrVrrr_rrrZ	constantsrrrrr�
exceptionsrr�parserrZutilsrrr�objectr r%r%r%r&�<module>	s*