Your IP : 216.73.217.13


Current Path : /usr/lib/python3/dist-packages/cloudinit/net/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/cloudinit/net/__pycache__/activators.cpython-38.pyc

U

�Ad9'�@szUddlZddlmZmZddlmZmZmZmZm	Z	m
Z
ddlmZm
Z
ddlmZddlmZddlmZddlmZddlmZe�e�ZGdd�de�Zed	�d
d�ZGdd
�d
e�Z Gdd�de �Z!Gdd�de �Z"Gdd�de �Z#Gdd�de �Z$ddddgZ%e!e#e"e$d�Z&ee'e	e fe(d<ee'e
e'dfee	e d�dd�Z)d!eee'ee'e	e d�dd �Z*dS)"�N)�ABC�abstractmethod)�Dict�Iterable�List�Optional�Type�Union)�subp�util��	available)�NetworkStatec@seZdZdS)�NoActivatorExceptionN)�__name__�
__module__�__qualname__�rr�:/usr/lib/python3/dist-packages/cloudinit/net/activators.pyrsr��returncCsdt�d||�z*t�|�\}}t|�r4t�d||�WdStjk
r^t�td|�YdSXdS)Nz#Attempting command %s for device %sz(Running %s resulted in stderr output: %sTz#Running interface command %s failedF)�LOG�debugr
�lenZwarningZProcessExecutionErrorrZlogexc)�cmd�device_nameZ_out�errrrr�_alter_interfacesrc@s�eZdZeedeeed�dd���Zeeeed�dd���Z	eeeed�dd	���Z
eeeed
�dd��Z
eeed
�dd��Zeeeed
�dd��Zeeed
�dd��ZdS)�NetworkActivatorN��targetrcCs
t��dS)z>Return True if activator is available, otherwise return False.N��NotImplementedError�r rrrr
!szNetworkActivator.available�rrcCs
t��dS)zWBring up interface.

        Return True is successful, otherwise return False
        Nr!�rrrr�bring_up_interface'sz#NetworkActivator.bring_up_interfacecCs
t��dS)zYBring down interface.

        Return True is successful, otherwise return False
        Nr!r%rrr�bring_down_interface0sz%NetworkActivator.bring_down_interface��device_namesrcst�fdd�|D��S)zjBring up specified list of interfaces.

        Return True is successful, otherwise return False
        c3s|]}��|�VqdS�N)r&��.0�device��clsrr�	<genexpr>?sz7NetworkActivator.bring_up_interfaces.<locals>.<genexpr>��all�r/r)rr.r�bring_up_interfaces9sz$NetworkActivator.bring_up_interfaces��
network_statercCs|�dd�|��D��S)z\Bring up all interfaces.

        Return True is successful, otherwise return False
        cSsg|]}|d�qS��namer�r,�irrr�
<listcomp>Hsz<NetworkActivator.bring_up_all_interfaces.<locals>.<listcomp>)r4�iter_interfaces�r/r6rrr�bring_up_all_interfacesAs�z(NetworkActivator.bring_up_all_interfacescst�fdd�|D��S)zlBring down specified list of interfaces.

        Return True is successful, otherwise return False
        c3s|]}��|�VqdSr*)r'r+r.rrr0Qsz9NetworkActivator.bring_down_interfaces.<locals>.<genexpr>r1r3rr.r�bring_down_interfacesKsz&NetworkActivator.bring_down_interfacescCs|�dd�|��D��S)z^Bring down all interfaces.

        Return True is successful, otherwise return False
        cSsg|]}|d�qSr7rr9rrrr;Zsz>NetworkActivator.bring_down_all_interfaces.<locals>.<listcomp>)r?r<r=rrr�bring_down_all_interfacesSs�z*NetworkActivator.bring_down_all_interfaces)N)rrr�staticmethodrr�str�boolr
r&r'�classmethodrr4rr>r?r@rrrrr s"	rc@sNeZdZed
eeed�dd��Zeeed�dd��Zeeed�dd	��Z	dS)�IfUpDownActivatorNrcCs
t|d�S�z3Return true if ifupdown can be used on this system.r#)�
eni_availabler#rrrr
cszIfUpDownActivator.availabler$cCsd|g}t||�S)�bBring up interface using ifup.

        Return True is successful, otherwise return False
        Zifup�r�rrrrrr&hsz$IfUpDownActivator.bring_up_interfacecCsd|g}t||�S)rHZifdownrIrJrrrr'qsz&IfUpDownActivator.bring_down_interface)N)
rrrrArrBrCr
r&r'rrrrrE^srEc@sHeZdZed
ed�dd��Zeeed�dd��Zeeed�dd	��ZdS)�NetworkManagerActivatorNrcCs
t|d�S)z9Return true if NetworkManager can be used on this system.r#)�nm_availabler#rrrr
|sz!NetworkManagerActivator.availabler$cCsbddlm}||�}ddd|g}t||�r:dddd|g}ntdddg|�dddd	|g}t||�S)
zdBring up connection using nmcli.

        Return True is successful, otherwise return False
        r)�
conn_filename�nmcliZ
connection�load�up�filename�reloadZifname)�cloudinit.net.network_managerrMr)rrMrQrrrrr&�s
z*NetworkManagerActivator.bring_up_interfacecCsddd|g}t||�S)zeBring down interface using nmcli.

        Return True is successful, otherwise return False
        rNr-Z
disconnectrIrJrrrr'�sz,NetworkManagerActivator.bring_down_interface)N)	rrrrArCr
rBr&r'rrrrrK{srKc@s�eZdZddgZeded�dd��Zeeed�dd	��Zee	eed
�dd��Z
eeed
�dd��Zeeed�dd��Z
ee	eed
�dd��Zeeed
�dd��ZdS)�NetplanActivator�netplanZapplyNrcCs
t|d�S)z2Return true if netplan can be used on this system.r#)�netplan_availabler#rrrr
�szNetplanActivator.availabler$cCst�d�ttjd�S��YApply netplan config.

        Return True is successful, otherwise return False
        zBCalling 'netplan apply' rather than altering individual interfacesr2�rrrrT�NETPLAN_CMDr%rrrr&�s�z#NetplanActivator.bring_up_interfacer(cCst�d�ttjd�SrWrY�r)rrrr4�s�z$NetplanActivator.bring_up_interfacesr5cCsttjd�S�rXr2�rrTrZ�r6rrrr>�sz(NetplanActivator.bring_up_all_interfacescCst�d�ttjd�SrWrYr%rrrr'�s�z%NetplanActivator.bring_down_interfacecCst�d�ttjd�SrWrYr[rrrr?�s�z&NetplanActivator.bring_down_interfacescCsttjd�Sr\r]r^rrrr@�sz*NetplanActivator.bring_down_all_interfaces)N)rrrrZrArCr
rBr&rr4rr>r'r?r@rrrrrT�srTc@s\eZdZed
ed�dd��Zeeed�dd��Zeeed�d	d
��Z	eeed�dd��Z
dS)�NetworkdActivatorNrcCs
t|d�SrF)�networkd_availabler#rrrr
�szNetworkdActivator.availabler$cCsdddd|g}t||�S)�1Return True is successful, otherwise return False�ip�link�setrPrIrJrrrr&�sz$NetworkdActivator.bring_up_interfacer5cCsddddg}t|d�S)raZ	systemctlZrestartzsystemd-networkdzsystemd-resolvedr2rI)r6rrrrr>�sz)NetworkdActivator.bring_up_all_interfacescCsdddd|g}t||�S)rarbrcrdZdownrIrJrrrr'�sz&NetworkdActivator.bring_down_interface)N)rrrrArCr
rBr&rr>r'rrrrr_�sr_�enirU�network-manager�networkd)rerUrfrg�NAME_TO_ACTIVATOR)�priorityr rcs>dd�|D�}|rtd|��dd�|D�}�fdd�|D�S)NcSsg|]}|tkr|�qSr)�DEFAULT_PRIORITYr9rrrr;sz$search_activator.<locals>.<listcomp>z0Unknown activators provided in priority list: %scSsg|]}t|�qSr)rh)r,r8rrrr;scsg|]}|���r|�qSrr)r,Z
activator_clsr#rrr;s
�)�
ValueError)rir �unknownZactivator_classesrr#r�search_activators�
�rmcCs\|dkrt}t||�}|sBd}|r2|dkr2d|}td||f��|d}t�d||�|S)N��/z
 in target=%szBNo available network activators found%s. Searched through list: %srz.Using selected activator: %s from priority: %s)rjrmrrr)rir �foundZtmsgZselectedrrr�select_activators&
���rq)NN)+Zlogging�abcrr�typingrrrrrr	Z	cloudinitr
rZcloudinit.net.enir
rGZcloudinit.net.netplanrVrSrLZcloudinit.net.network_staterZcloudinit.net.networkdr`Z	getLoggerrr�	ExceptionrrCrrrErKrTr_rjrhrB�__annotations__rmrqrrrr�<module>sL 
>!I��	

��
�