File: //usr/share/netplan/netplan_cli/cli/commands/__pycache__/apply.cpython-310.pyc
o
t��foT � @ s� d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl m
Z
ddlmZm
Z
ddlmZ ddlmZmZmZ d Zd
ZG dd� de
j�ZdS )
znetplan apply command line� N� )�utils� )�
ConfigManager�ConfigurationError)�apply_sriov_config)�OvsDbServerNotRunning�OvsDbServerNotInstalled�apply_ovs_cleanupznetplan-ovs-cleanup.service� c sx e Zd Z� fdd�Zdd� Zddd �Zed
d� �Zeg fdd
��Zede fdd��Z
eddd��Zeddd��Z� Z
S )�NetplanApplyc s( t � jdddd� d| _d| _d | _d S )N�applyz.Apply current netplan config to running systemT)�
command_id�description�leafF)�super�__init__�
sriov_only�only_ovs_cleanup�state��self�� __class__� �4/usr/share/netplan/netplan_cli/cli/commands/apply.pyr , s �
zNetplanApply.__init__c C sP | j jdddd� | j jdddd� | j jddd � | j| _| �� | �� d S )
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_commandr r r r �run4 s
�
��zNetplanApply.runTFNc ( C sV t � }|r|| _| jrt�||� d S | jr t�|dd|� d S dtjv r[t �
d�}|d u r2td��t�
|ddddd dd
g�}|dkrY|rKt�|� n|dkrStd
��td| ��d S d}tt�d��} t�d�}
||
v rr|
�|� t|
�}t�d�}t�|t�� �}
t|�}g }d }dtjv r�|�ddg� tj}|�t�� � |r�tj
||d�dkr�|r�t�tj� ntd��t�� }tt�d��}|s�| r�d}t�d�}||v r�|�|� t|�}|s�|r�d}t�d�}|
�t�||�� t|�}|s�|r�d}|�rt�� |�r)t �!d� t�||||� dg}t�"d��r |�#dd� tj$d||d� nt �!d� d}|�rrt �!d � t�%� �rqd!|
v �rGt�&d!�}|D ] }||
v�rR�qIzt�'d"d#|g� W �qI tj(�yi Y �qIw tj)d|d� nt �!d$� t�� }|�*� t�+||�}| j�r�t | j�}|�*� |j,�-� }|j,�-� }t�.|||� t�� }|D ]<}t �!d%|� z"tj/d&d'd(d)| gtj0tj0d*� tj/d&d+d)| gtj0tj0d*� W �q� tj(�y� t �!d,|� Y �q�w t�� }|�1� D ]X\}} | �2d-�}!|!�rEt3|!�t4k�rt �5d.�6|!|�� �q�||v �r!|!|v �r!t �!d/�6||!�� �q�tj/d0d1d2d3|d4gtj0tj0d*� tj/d0d1d2d3|d-| �2d-�gtj0tj0d*� �q�t�/g d5�� t�/d&d6g� t�||� tj7�8d7��rit�$d8d9g� |�r�d:d;� t�d<�D �}"d=d;� t�d>�D �}#z
t�9� t�:t�;� � W n tj(�y� t �5d?� tj$d@dAgdd� Y nw tj$d8t<gdd� tj$d8|"|# dd� |�r%t�||�}$|$D ]}t�=|� �q�t j>dBddC� tj)d8|d� d!|$v �r�d}|�rg dD�}%t?dE�D ]'}&tj@|%dddF�}'|'jAdGk�rtB�CdH� �q�dItD|'jE�v �r ntB�CdJ� �q�d!|$v �r'|�r)t�F|� d S d S d S d S )KNF�SNAP�busctlzmissing busctl utility�callz--quietz--systemzio.netplan.Netplanz/io/netplan/Netplan�Applyr � 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-*�NETPLAN_PROFILE�valgrindz--leak-check=full)�stderrz(the configuration could not be generatedTzDnetplan generated networkd configuration changed, reloading networkdznetplan-wpa-*.serviceznetplan-wpa@*.service�stop)�syncz2no netplan generated networkd configuration exists� z9netplan generated NM configuration changed, restarting NM�lo�device�
disconnectz,no netplan generated NM configuration existsz%netplan triggering .link rules for %s�udevadmztest-builtin�net_setup_linkz/sys/class/net/)�stdoutr- �testz#Ignoring device without syspath: %s�namez5Interface name {} is too long. {} will not be renamedz+Interface rename {} -> {} already happened.�ip�link�set�dev�down)r4 �triggerz--attr-match=subsystem=net�settlez*/run/systemd/system/netplan-regdom.service�startznetplan-regdom.servicec S s g | ]}t j�|��qS r )�os�path�basename��.0�fr r r �
<listcomp> s z.NetplanApply.command_apply.<locals>.<listcomp>z1/run/systemd/system/*.wants/netplan-wpa-*.servicec S s&