HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //proc/self/root/usr/share/netplan/netplan_cli/cli/commands/__pycache__/try_command.cpython-310.pyc
o

ϐxeB�@s�dZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
dd	l
mZd
ZGdd�dej�ZdS)
znetplan try command line�N�)�
ConfigManager�)�utils�)�NetplanApply)�terminal�xcsxeZdZ�fdd�Zedd��Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Z�ZS)�
NetplanTrycs`t�jdddd�d|_d|_d|_d|_d|_d|_tj	�
dd�|_tj�
|jdd	d
�|_dS)N�tryzLTry to apply a new netplan config to running system, with automatic rollbackT)�
command_id�description�leafF�DBUS_TEST_NETPLAN_ROOT�/�run�netplanznetplan-try.ready)�super�__init__�configuration_changed�new_interfaces�config_file�_config_manager�
t_settings�t�os�environ�get�_rootdir�path�join�_netplan_try_stamp��self��	__class__��:/usr/share/netplan/netplan_cli/cli/commands/try_command.pyr(s�zNetplanTry.__init__cCs|js
t|jd�|_|jS)N)�prefix)rrrr"r&r&r'�config_manager6szNetplanTry.config_managercCs"tj�|j�rt�|j�dSdS)NTF)rr�isfiler!�remover"r&r&r'�clear_ready_stamp<szNetplanTry.clear_ready_stampcCs*tj|jdddd�t|jd���dS)Nz/run/netplani�T)�mode�exist_ok�w)r�makedirsr�openr!�closer"r&r&r'�touch_ready_stampBszNetplanTry.touch_ready_stampcCsP|jjddd�|jjdttdd�|jjddd�|j|_|��|��dS)	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)�type�defaultr4z--statez0Directory containing previous YAML configuration)�parser�add_argument�int�DEFAULT_INPUT_TIMEOUT�command_try�func�
parse_args�run_commandr"r&r&r'rFs���zNetplanTry.runc
Csj|��s
t�tj�z�zCtj��}t�|�|_	|j	�
|j�t�tj
|j�t�tj|j�|��|��t�jddd|jd�|��|j	j|jd�Wn>tjy`td�|��Yn-tjymtd�Yn ty�}ztd|�td�|��WYd}~nd}~wwW|j	r�|j	�|j�|��|��dS|j	r�|j	�|j�|��|��w)NTF��run_generate�sync�
exit_on_error�	state_dir)�timeoutz
Reverting.z
Configuration accepted.z
An error occurred: %s) �
is_revertable�sys�exitr�	EX_CONFIG�stdin�filenor�Terminalr�saver�signal�SIGINT�_signal_handler�SIGUSR1�backup�setupr�
command_apply�stater3�get_confirmation_inputrD�
InputRejected�print�revert�
InputAccepted�	Exception�reset�cleanupr,)r#�fd�er&r&r'r;TsB
����
zNetplanTry.command_trycCs d}|jrd}|jj|d�dS)NFT)�backup_config_dir)rr)rQ)r#r_r&r&r'rQyszNetplanTry.backupcCsd|jr-tj�ddd�}tj�|j��d�}t��}tj�|d�||��}|j�	|j|i�d|_
dS)Nr�etcrz.yamlz
{}.{}.yamlT)rrrr �basename�rstrip�time�formatr)�addr)r#�dest_dir�	dest_name�dest_suffix�	dest_pathr&r&r'rRs
zNetplanTry.setupcCs^t��}tj�|dd�}t�|�tjd|dd�|j�	�t
�jddd|d�t�|�dS)Nr`rz/etc/netplanT)�
dirs_exist_okFr?)
�tempfile�mkdtemprrr r0�shutil�copytreer)rXrrS�rmtree)r#�tempdir�confdirr&r&r'rX�s

zNetplanTry.revertcCs|j��dS�N)r)r\r"r&r&r'r\�szNetplanTry.cleanupc	
Cs�g}|jr|�|j�d}z	|jj|d�}Wntjy4}zt�|�t�	t
j�WYd}~nd}~wwg}i}|�|j
�|�|j�|��D]}|jsXd}|�|j|f�qI|rp|D]\}}td�||��q]td�dSdS)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)r�appendr)�parser�
config_errors�logging�errorrFrGrrH�update�bridges�bonds�values�_is_trivial_compound_itf�idrWrd)	r#rs�np_stater^�revert_unsupported�multi_iface�itf�reason�ifnamer&r&r'rE�s4
���zNetplanTry.is_revertablecCs$|tjkr	t���|jrt���dSrr)rMrPrrYrrV)r#�sig�framer&r&r'rO�s

�zNetplanTry._signal_handler)�__name__�
__module__�__qualname__r�propertyr)r,r3rr;rQrRrXr\rErO�
__classcell__r&r&r$r'r
&s
%	-r
)�__doc__rwrrcrmrMrFrk�
configmanagerr�r�applyrrr:�NetplanCommandr
r&r&r&r'�<module>s