%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/share/netplan/netplan/cli/commands/__pycache__/
Upload File :
Create Path :
Current File : //usr/share/netplan/netplan/cli/commands/__pycache__/try_command.cpython-36.pyc

3

�Bd]��@szdZddlZddlZddlZddlZddlZddlZddlmZddl	j
jZddlm
Z
ddlZdZGdd�dej�ZdS)znetplan try command line�N)�
ConfigManager)�NetplanApply�xcsheZdZ�fdd�Zedd��Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
�ZS)�
NetplanTrycs4t�jdddd�d|_d|_d|_d|_d|_dS)N�tryzLTry to apply a new netplan config to running system, with automatic rollbackT)�
command_id�description�leafF)�super�__init__�configuration_changed�new_interfaces�_config_manager�
t_settings�t)�self)�	__class__��6/usr/share/netplan/netplan/cli/commands/try_command.pyr'szNetplanTry.__init__cCs|jst�|_|jS)N)rr)rrrr�config_manager2szNetplanTry.config_managercCs@|jjddd�|jjdttdd�|j|_|j�|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�defaultr)�parser�add_argument�int�DEFAULT_INPUT_TIMEOUT�command_try�func�
parse_args�run_command)rrrr�run8szNetplanTry.runcCs.|j�stjtj�z�yjtjj�}tjj	|�|_
|j
j|j�t
j
t
j|j�|j�|j�tjdddd�|j
j|jd�Wn�tjjk
r�td�|j�Yn^tjjk
r�td�Yn@tk
�r}z"td|�td�|j�WYdd}~XnXWd|j
�r |j
j|j�|j�XdS)NTF)�run_generate�sync�
exit_on_error)�timeoutz
Reverting.z
Configuration accepted.z
An error occurred: %s)�
is_revertable�sys�exit�os�	EX_CONFIG�stdin�fileno�netplan�terminalZTerminalrZsaver�signal�SIGINT�_signal_handler�backup�setupr�
command_applyZget_confirmation_inputr%�
InputRejected�print�revertZ
InputAccepted�	Exception�reset�cleanup)r�fd�errrrDs.
zNetplanTry.command_trycCs d}|jrd}|jj|d�dS)NFT)�backup_config_dir)�config_filerr2)rr=rrrr2dszNetplanTry.backupcCsd|jrZtjjddd�}tjj|j�jd�}tj�}tjj|dj||��}|jj	|j|i�d|_
dS)N�/�etcr-z.yamlz
{}.{}.yamlT)r>r)�path�join�basename�rstrip�time�formatr�addr)rZdest_dirZ	dest_nameZdest_suffixZ	dest_pathrrrr3jszNetplanTry.setupcCs�|jj�tjdddd�x�|jD]|}||jjkr\||jjkr\||jjkr\tj	dj
|��q"yddd|g}tj|�Wq"tj
k
r�tjdj
|��Yq"Xq"WdS)	NFT)r"r#r$z/{} will not be removed: not a virtual interface�ip�link�delz,Could not revert (remove) new interface '{}')rr7rr4r
�bonds�bridges�vlans�logging�debugrF�
subprocess�
check_call�CalledProcessError�warn)r�ifname�cmdrrrr7ss
zNetplanTry.revertcCs|jj�dS)N)rr:)rrrrr:�szNetplanTry.cleanupcCs�g}|jr|j|j�|jj|d�|jj|_tjdj|j��g}i}|j|jj	�|j|jj
�x2|j�D]&\}}|rnd|krnd}|j||f�qnW|r�x |D]\}}tdj||��q�Wtd�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.
        )�extra_configzNew interfaces: {}Z
parameterszBreverting custom parameters for bridges and bonds is not supportedz{}: {}zL
Please carefully review the configuration and use 'netplan apply' directly.FT)
r>�appendr�parser
rNrOrF�updaterLrK�itemsr6)rrVZrevert_unsupportedZmulti_ifacerT�settings�reasonrrrr&�s(
zNetplanTry.is_revertablecCs|jrtjj��dS)N)rr-r.r5)rr/�framerrrr1�szNetplanTry._signal_handler)�__name__�
__module__�__qualname__r�propertyrr!rr2r3r7r:r&r1�
__classcell__rr)rrr%s 	-r)�__doc__r)rEr/r'rNrP�netplan.configmanagerr�netplan.cli.utils�cli�utils�netplan.cli.commands.applyrZnetplan.terminalr-r�NetplanCommandrrrrr�<module>s

Zerion Mini Shell 1.0