*CeOdZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z ddl mZdd l mZd ZGd d e j"Zy) znetplan try command lineN) ConfigManager)utils) NetplanApply)terminalxcjeZdZfdZedZdZdZdZdZ dZ dZ d Z d Z d Zd ZxZS) NetplanTryc*t|dddd|_d|_d|_d|_d|_d|_tjjdd|_ tjj|jdd d |_y) NtryzLTry to apply a new netplan config to running system, with automatic rollbackT) command_id descriptionleafFDBUS_TEST_NETPLAN_ROOT/runnetplanznetplan-try.ready)super__init__configuration_changednew_interfaces config_file_config_manager t_settingstosenvironget_rootdirpathjoin_netplan_try_stamp)self __class__s :/usr/share/netplan/netplan_cli/cli/commands/try_command.pyrzNetplanTry.__init__)s E&G"  $&+""# '?E "$'',,t}}eYPc"dch|jst|j|_|jS)N)prefix)rrr!r%s r'config_managerzNetplanTry.config_manager7s(###0 #FD ###r(ctjj|jr tj|jyy)NTF)rr"isfiler$remover+s r'clear_ready_stampzNetplanTry.clear_ready_stamp=s0 77>>$11 2 IId-- .r(ctj|jdzddt|jdj y)Nz /run/netplaniT)modeexist_okw)rmakedirsr!openr$closer+s r'touch_ready_stampzNetplanTry.touch_ready_stampCs4 DMMN2N T $ $c*002r(c(|jjdd|jjdttd|jjdd|j|_|j |jy) Nz --config-filezGApply the config file in argument in addition to current configuration.)helpz --timeoutz=Maximum number of seconds to wait for the user's confirmation)typedefaultr:z--statez0Directory containing previous YAML configuration)parser add_argumentintDEFAULT_INPUT_TIMEOUT command_tryfunc parse_args run_commandr+s r'rzNetplanTry.runGs   &o ! q   &)3H&e ! g   &X ! Z$$   r(c@|js#tjtj tj j }tj||_ |jj|jtjtj|jtjtj|j|j!|j#t%j'ddd|j(|j+|jj-|j.|jr%|jj;|j|j=|j?y#tj0$rt3d|j5Ytj6$rt3dYt8$r3}t3d|zt3d|j5Yd}~d}~wwxYw#|jr%|jj;|j|j=|j?wxYw)NTF run_generatesync exit_on_error state_dir)timeoutz Reverting.z Configuration accepted.z An error occurred: %s) is_revertablesysexitr EX_CONFIGstdinfilenor TerminalrsaversignalSIGINT_signal_handlerSIGUSR1backupsetupr command_applystater8get_confirmation_inputrK InputRejectedprintrevert InputAccepted Exceptionresetcleanupr0)r%fdes r'rAzNetplanTry.command_tryUs!!# HHR\\ " %!!#B&&r*DF FFKK ( MM&--)=)= > MM&..$*>*> ? KKM JJL N ( (dUZfjfpfp ( q  " " $ FF ) )$,, ) ?vv T__- LLN  " " $%%  . ! KKM%% / - .  +a/ 0 . ! KKMM  vv T__- LLN  " " $sCD6F==.I+I -I I I)I=I II AJc\d}|jrd}|jj|y)NFT)backup_config_dir)rr,rX)r%rgs r'rXzNetplanTry.backupzs/!    $  ""5F"Gr(c|jrtjjddd}tjj |jj d}t j }tjj|dj||}|jj|j|id|_ y)Nretcrz.yamlz {}.{}.yamlT) rrr"r#basenamerstriptimeformatr,addr)r%dest_dir dest_name dest_suffix dest_paths r'rYzNetplanTry.setups   ww||C :H(()9)9:AA'JI))+K X|/B/B9k/Z[I    # #T%5%5y$A B%)"r(c`tj}tjj |dd}tj |t jd|d|jjtjddd|t j|y)Nrirz /etc/netplanT) dirs_exist_okFrF) tempfilemkdtemprr"r#r5shutilcopytreer,r_rrZrmtree)r%tempdirconfdirs r'r_zNetplanTry.reverts{""$'',,wy9 GtD ""$$$%dRWcj$k gr(c8|jjyN)r,rcr+s r'rczNetplanTry.cleanups ##%r(cg}|jr|j|jd} |jj|}g}i}|j|j|j|j|jD].}|j rd}|j|j"|f0|r1|D] \}}t%dj'||"t%dyy#tj $rB}t j|tjtjYd}~d}~wwxYw)a  Check if the configuration is revertable, if it doesn't contain bits that we know are likely to render the system unstable if we apply it, or if we revert. Returns True if the parsed config is "revertable", meaning that we can actually rely on backends to re-apply /all/ of the relevant configuration to interfaces when their config changes. Returns False if the parsed config contains options that are known to not cleanly revert via the backend. N) extra_configzBreverting custom parameters for bridges and bonds is not supportedz{}: {}zL Please carefully review the configuration and use 'netplan apply' directly.FT)rappendr,parser config_errorsloggingerrorrMrNrrOupdatebridgesbondsvalues_is_trivial_compound_itfidr^rm) r%rnp_statererevert_unsupported multi_ifaceitfreasonifnames r'rLzNetplanTry.is_revertables,       0 0 1 #**00l0KH   9; 8++,8>>*%%' rsJ$ *c/%%c/r(