Your IP : 216.73.216.52


Current Path : /usr/share/netplan/netplan/cli/commands/__pycache__/
Upload File :
Current File : //usr/share/netplan/netplan/cli/commands/__pycache__/apply.cpython-38.pyc

U

�]aD�@s�dZddlZddlZddlZddlZddlZddlZddlmm	Z	ddl
mZmZddl
mZddlmZddlZGdd�de	j�ZdS)znetplan apply command line�N)�
ConfigManager�ConfigurationError)�apply_sriov_config)�apply_ovs_cleanupcsreZdZ�fdd�Zdd�Zddd	�Zed
d��Zegfdd
��Zedd��Z	eddd��Z
eddd��Z�ZS)�NetplanApplycs"t�jdddd�d|_d|_dS)NZapplyz.Apply current netplan config to running systemT)�
command_id�description�leafF)�super�__init__�
sriov_only�only_ovs_cleanup��self��	__class__��0/usr/share/netplan/netplan/cli/commands/apply.pyr's�zNetplanApply.__init__cCsP|jjdddd�|jjdddd�|jjddd	�|j|_|��|��dS)
Nz--sriov-only�
store_truez0Only apply SR-IOV related configuration and exit)�action�helpz--only-ovs-cleanupz1Only clean up old OpenVSwitch interfaces and exitz--statez0Directory containing previous YAML configuration)r)�parser�add_argument�
command_apply�func�
parse_args�run_commandrrrr�run.s
�
��zNetplanApply.runTFNc!Cs�t�}|r||_|jr&t�||�dS|jr@t�|dd|�dSdtjkr�t	�
d�}|dkrdtd��t�
|ddddd	dd
g�}|dkr�|r�t�|�q�|dkr�td
��q�td|��ndSd}tt�d��}	t�d�}
||
kr�|
�|�t|
�}t�d�}t�|t���}
t|�}g}d}dtjk�r:|�ddg�tj}|�t���|�r~tj
||d�dk�r~|�rvt�tj�ntd��t��}tt�d��}|�s�|	�r�d}t�d�}||k�r�|�|�t|�}|�s�|�r�d}t�d�}|
�t�||��t|�}|�s|�rd}|�rlt� d�|�r,t�!�t�||||�dg}t�"d��rZ|�#dd�tj$d||d�n
t� d�|�r�t� d�t�%��r�|D]B}||
k�r��q�zt�&d d!|g�Wntj'k
�r�YnX�q�tj(d|d"�n
t� d#�t��}|�)�t�*||�}|j�rJt|j�}|�)�|j+�,�}|j+�,�}t�-|||�t��}|D]\}t� d$|�z$tj.d%d&d'd(|gtj/tj/d)�Wn$tj'k
�r�t� d*|�YnX�qV|�0�D]^\}}|�1d+��r�tj.d,d-d.d/|d0gtj/tj/d)�tj.d,d-d.d/|d+|�1d+�gtj/tj/d)��q�t�.d%d1g�t�||�|�rxd2d3�t�d4�D�}d5d3�t�d6�D�} tj$d7d|| d�|�r�t�||�D]}t�2|��q�tj(d7|d"�dS)8NFZSNAP�busctlzmissing busctl utility�callz--quietz--systemzio.netplan.Netplanz/io/netplan/NetplanZApplyr�z'failed to communicate with dbus servicez1failed to communicate with dbus service: error %sz//run/systemd/system/netplan-ovs-cleanup.servicez/run/systemd/network/*netplan-*z!/run/systemd/system/netplan-ovs-*z0/run/NetworkManager/system-connections/netplan-*ZNETPLAN_PROFILEZvalgrindz--leak-check=full)�stderrz(the configuration could not be generatedTzEnetplan generated networkd configuration changed, restarting networkdznetplan-wpa-*.serviceznetplan-wpa@*.service�stop)�sync�extra_servicesz2no netplan generated networkd configuration existsz9netplan generated NM configuration changed, restarting NM�deviceZ
disconnect)r#z,no netplan generated NM configuration existsz%netplan triggering .link rules for %sZudevadmztest-builtinZnet_setup_linkz/sys/class/net/)�stdoutr!z#Ignoring device without syspath: %s�name�ip�link�set�dev�downZsettlecSsg|]}tj�|��qSr��os�path�basename��.0�frrr�
<listcomp>�sz.NetplanApply.command_apply.<locals>.<listcomp>z1/run/systemd/system/*.wants/netplan-wpa-*.servicecSsg|]}tj�|��qSrr-r1rrrr4�sz1/run/systemd/system/*.wants/netplan-ovs-*.service�start)3r�staterr�process_sriov_configr
�process_ovs_cleanupr.�environ�shutil�which�RuntimeError�
subprocessr�sys�exit�PermissionError�bool�glob�remove�utils�
nm_interfaces�	netifaces�
interfaces�extend�STDOUT�append�get_generator_path�	EX_CONFIGr�update�logging�debug�systemctl_daemon_reload�systemctl_is_active�insert�systemctl_networkd�
nm_running�nmcli�CalledProcessError�systemctl_network_manager�parse�process_link_changesZvirtual_interfaces�keys�clear_virtual_links�
check_call�DEVNULL�items�get�
ip_addr_flush)!rZrun_generater#�
exit_on_errorZ	state_dir�config_managerr�resZovs_cleanup_serviceZold_files_networkdZold_ovs_globZ
old_files_ovsZold_nm_globZ	nm_ifacesZold_files_nmZgenerator_callZgenerate_out�devicesZrestart_networkdZrestart_ovs_globZrestart_ovsZrestart_nm_globZ
restart_nmZwpa_servicesr%�changes�cm�
prev_links�
curr_links�iface�settingsZnetplan_wpaZnetplan_ovsrrrr;s


���
















��
�
��
zNetplanApply.command_applycCsV|D]L}|��D]>\}}t|�tk	r&q|�dg�}|D]}||kr6dSq6qqdS)zp
        Is this physical interface a member of a 'composite' virtual
        interface? (bond, bridge)
        rGTF)r^�type�dictr_)Z
composites�phyZ	composite�_rj�membersrirrr�is_composite_membersz NetplanApply.is_composite_memberc	Cs�|st�d�gStt|�t|��}tt|��|��}|D]H}zdddd|g}t�|�Wq<tjk
r�t�d�	|��Yq<Xq<|S)a%
        Calculate the delta of virtual links. And remove the links that were
        dropped from the YAML config, if they were not dropped by the backend
        already.
        We can make use of the netplan netdef ids, as those equal the interface
        name for virtual links.
        z;Cannot clear virtual links: no network interfaces provided.r(r)�deleter+zCould not delete interface {})
rN�warning�listr*�intersectionr=r\rV�warn�format)rgrhrdZdropped_interfacesZinterfaces_to_clearr)�cmdrrrr[s	
z NetplanApply.clear_virtual_linksc
Cs�i}t|j�}|j|jg}|��D]�\}}|r"t|t�s:q"|�d�}|sJq"|�d�}|sZq"t�||�rxt	�
d�|��q"t�
||�}	|	s�t	�d�||��q"|	|kr�t	�
d�|��q"|�dd�r�t	�d�||	|��q"d	|i||	<q"t	�
d
�|��|S)z�
        Go through the pending changes and pick what needs special handling.
        Only applies to non-critical interfaces which can be safely updated.
        zset-name�matchzSkipping composite member {}z0Cannot find unique matching interface for {}: {}z&Skipping correctly named interface: {}�criticalFzLCannot rename {} ({} -> {}) at runtime (needs reboot), due to being criticalr'zLink changes: {})rlZphysical_interfacesZbridgesZbondsr^�
isinstancer_rrprNrOrvrD�find_matching_ifacerr)
rGrbreZphysZcomposite_interfacesrmrjZnewnamerxZcurrent_iface_namerrrrY,s@


�z!NetplanApply.process_link_changesc
CsTzt|�WnBttfk
rN}z t�t|��|r>t�d�W5d}~XYnXdS�N�)rrr<rN�error�strr>r?)rbra�errrr7\sz!NetplanApply.process_sriov_configc
CsXzt|||�WnBttfk
rR}z t�t|��|rBt�d�W5d}~XYnXdSr|)r�OSErrorr<rNr~rr>r?)rbZovs_oldZovs_currentrar�rrrr8esz NetplanApply.process_ovs_cleanup)TFTN)T)T)
�__name__�
__module__�__qualname__rrr�staticmethodrpr[rYr7r8�
__classcell__rrrrr%s
G

/r)�__doc__rNr.r>rBr=r:�netplan.cli.utils�clirDZnetplan.configmanagerrrZnetplan.cli.sriovrZnetplan.cli.ovsrrF�NetplanCommandrrrrr�<module>s