ddlZddlZddlZddlZddlZddlmZmZddlZddl m Z ddl m Z m Z mZmZmZddlmZddlmZmZddlmZmZmZmZmZdd lmZmZdd lm Z m!Z!m"Z"dd l#m$Z$dd l%m&Z&m'Z'm(Z(Gd dZ)dS)N)ClassVarNoReturn)FormattedException)ExternalProgramFailedget_cl_versionget_package_db_errors is_ubuntu run_command) NoSuchModule)Configacquire_config_access)CRASH_LOG_PATHFILE_MARKER_PATH MAIN_LOG_PATH ModuleStatus WizardStatus)CancelModuleExceptionInstallationFailedException) ALL_MODULESget_supported_modulesrun_installation)parse_cloudlinux_wizard_opts)is_background_process_runningrun_background setup_loggercbeZdZUdZejejejgZe e e e d<ej ejejgZe e e e d<dZdZedZdZdd edzd dfd Zd Zd ZdZdZdZde d dfdZdZdZdZde d e fdZ!e dde de"d e#fdZ$dS)CloudlinuxWizardzAMain class for working with Wizard that exposes high level logic.CANCELLABLE_MODULE_STATUSESDONE_MODULES_STATUSEScnd|_t|_tdt|_dS)Nz wizard.main)_optsr_supported_modulesrrlogselfs py/clwizard/wizard.py__init__zCloudlinuxWizard.__init__As, "7"9"9 }==ct||_ |jjdkr||r#|jjs|dd|jjr#|tn| |jj n|jjdkrJ||jj r| nq|n\|jjdkr ||jjn,|jjdkr|nt$|jjd vr|s$|jjdkr<|s(|||d S#t,$rO}|jd | ||j|j|jd Yd }~d Sd }~wt8$r|ddYd St:$rO}|jd| |dt=jYd }~d Sd }~wwxYw)zx CL Wizard main function. :param argv: command line arguments for wizard :return: None installzInstallation already finishedr result exit_code)optionsstatuscancelfinish)r+r1z,Got an error while running cloudlinux-wizardexc_info)r-contextdetailsr.Nz"#0:&S22444$&&&&44TZ=Q4RRRR%11%%''':%1,,......0000%11001BCCCC%11--////)) $(===$B_B_BaBa= $009V9V9X9X0..000,,...  ' ' ) ) ) ) )!    H  >      ' '{   (          +     ' 'U (          H  Cc  R R R  ' 'o!,.. (          s,G#G;; KAI$K6 K?AK  KcJtjtSN)ospathisfilerr)r'r9z)CloudlinuxWizard.is_installation_finishedsw~~.///r)c tjt|jddS#t $rJ}|jdt||ddYd}~dSd}~wwxYw)NzWizard execution completez:Wizard 'finish' command called more than once, error: '%s'z-Wizard 'finish' command called more than oncer r,) rTmknodrr$infoOSErrorwarningstrr;)r&rPs r'rEz)CloudlinuxWizard.create_completion_markers  H% & & & HMM5 6 6 6 6 6    H  LC     ' 'F (           s37 B ?BB Nr/returnctjdd}|dt5}t r|dd|||t|j}||_ dddn #1swxYwY|d|dS)Nz --no-asynczMUnable to start a new installation because a background task is still workingr r,success)r-pid) sysrOappendrrr; set_modulesrra worker_pid)r&r/cmdconfigres r'r>z,CloudlinuxWizard.run_background_installations hqqqk <   " $ $ +-.. ++j, """7+++(,,0J *F  + + + + + + + + + + + + + + + ##9*#EEEEEsABB #B cRt|ddSdS)zC Check whether Wizard supports the current system. NzCould not identify the CloudLinux version. Restart your system. If you have the same problem again - contact CloudLinux support.r-)rr;r%s r'r8z!CloudlinuxWizard._validate_systemsD    #  ' '. (      $ #r)ctregd} t|}|jd|dS#t$r'}|jd|Yd}~dSd}~wwxYwgd} t|}|jd|dS#t$r'}|jd|Yd}~dSd}~wwxYw) z Prepare the environment 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-qupdatezapt-get update output: %szError during apt-get updater3N)yumz-qycleanz expire-cachez!yum clean expire-cache output: %sz#Error during yum clean expire-cache)r r r$rZrrJr&rfoutrPs r'r=z*CloudlinuxWizard._prepare_for_installations, ;; X---C P!#&& :C@@@@@( P P P""#@3"OOOOOOOOO P:99C X!#&& BCHHHHH( X X X""#HSV"WWWWWWWWW Xs/*A A1 A,,A19*B%% C/CCc&|j|jS)z. Get path to module log file. )r#LOG_FILE)r& module_names r'_get_module_log_pathz%CloudlinuxWizard._get_module_log_paths&{3<z7CloudlinuxWizard._get_initial_status..s???Cs3xx???r)cNi|]"\}}||#SrW)initial_status)rrrclss r' z8CloudlinuxWizard._get_initial_status.. s1uuuAQcccee&:&:&<&<uuur))ryunsuppored_by_cpN)rr;rsetr#keyslistitems)r& error_messageall_modules_setsupported_modules_setunsupported_by_cps r'rAz$CloudlinuxWizard._get_initial_statuss.//    ' '} ' = = = = =??;???O$'(?(D(D(F(F$G$G ! $_7L%L M M   ' 'uuUYUlUrUrUtUtuuu!2 (     r)rDc|jd|t5}||}||jvr=||t j|jd|n,|jd||t|| ddddS#1swxYwYdS)zS Remove module from queue or print the error if it's not possible. z0Trying 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|rset_module_statusr CANCELLEDr\r)r&rDrgr0s r'rCz,CloudlinuxWizard._cancel_module_installations'  H&QQQ " $ $ <--f55F999(( &*4) NPVWWWW  ] ,FF;;;X < < < < < < < < < < < < < < < < < z.=+OOF6T77OOOOOOr))rrstatusesvaluesallr&rgrs` r'rGz)CloudlinuxWizard.is_all_modules_installed3s# $ $ 6FO224455H 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6OOOOhOOOOOOs'AA Ac2d}tj|sdS|ddg}|jd|t |}t tjd}|r| dSdS)z= Run cagefsctl --force-update in background. z/usr/sbin/cagefsctlNz--force-updatez --wait-lockz2Starting cagefs force-update in the background: %sCL_TEST_SYSTEM) rTrUrVr$rZrboolrr communicate)r& cagefsctl_binrfcagefsctl_procis_test_environments r'rIz(CloudlinuxWizard.run_cagefs_force_update?s. w~~m,,  F. >  JCPPP',,"2:>>2B#C#CDD  )  & & ( ( ( ( ( ) )r)rgc|j tjS tj|jn#tj$rt |j}tfd|Drtj cYStd|Dr'td|Dstj cYStj cYSwxYwtjS)Nc3*K|] }|jvVdSrSrrs r'rz5CloudlinuxWizard._get_wizard_state.._rr)c3JK|]}|tjtjfvVdSrS)rr~rrr0s r'rz5CloudlinuxWizard._get_wizard_state..cs2bbv6l1<3IJJbbbbbbr)c34K|]}|tjfvVdSrS)r INSTALLINGrs r'rz5CloudlinuxWizard._get_wizard_state..csFoo9?<244oooooor))rerIDLEpsutilProcess NoSuchProcessrrrrDONEanyr~r IN_PROGRESSrs` r'r{z"CloudlinuxWizard._get_wizard_stateOs#   $$ $ ( N6, - - - -# ( ( ( FO224455HOOOOhOOOOO )#((((bbYabbbbb +knooCKoooll +$****' ' ' ' ("''s0AC>C CCr`rr-r.c |tjd}||ttj|ddt j|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- timestampT)indent sort_keysN)timerkprintjsondumpsrbexit)r-r.extrarKs r'r;z'CloudlinuxWizard._print_result_and_exitks^$$)++>>u djd;;;<<< r)rS)r`r)%__name__ __module__ __qualname____doc__rPENDINGr~rrrrr]__annotations__ INSTALLEDrr r(rQ staticmethodr9rEdictr>r8r=rsrBrArCrHrGrIr r{intrr;rWr)r'rr0sKK 8$s)!4 !28DI. >>> IIIV00\0   FF4$;F$FFFF(   XXX*=== JJJ>"<#<$<<<<* S S S P P P))) ((3((((8        \   r)r)*rrTrbrrMtypingrrrclcommonrclcommon.utilsrrrr r clwizard.configr rgr r constantsrrrrr exceptionsrrryrrrparserrutilsrrrrrWr)r'rs %%%%%%%% '''''')(((((KJJJJJJJIIIIIIIIII000000IIIIIIIIIIr)