File: //usr/lib/python3/dist-packages/cloudinit/sources/helpers/__pycache__/digitalocean.cpython-38.pyc
U
Ӈg� � @ s� d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZmZ ddd�Z e�
e�Zddd �Z
d
d� Zddd
�Zdd� Zddd�Zdd� ZdS )� N)�dmi)�net)�
url_helper�utilZeth0Zeth1)�publicZprivatec C s� |st | �}t�d|� |s$td��d�t�dd�t�dd��}z,| j�||� | j� |� t�d||� W n& t
k
r� t�td ||� � Y nX |S )
z�Bring up NIC using an address using link-local (ip4LL) IPs.
On DigitalOcean, the link-local domain is per-droplet routed, so there
is no risk of collisions. However, to be more safe, the ip4LL
address is random.
z,selected interface '%s' for reading metadatazPunable to find interfaces to access themeta-data server. This droplet is broken.z169.254.{0}.{1}/16� � r � z&brought device '%s' up with address %szRip4LL address assignment of '%s' to '%s' failed. Droplet networking will be broken)
�get_link_local_nic�LOG�debug�RuntimeError�format�randomZrandint�net_opsZadd_addrZlink_up� Exceptionr �logexc)�distro�nicZaddr� r �H/usr/lib/python3/dist-packages/cloudinit/sources/helpers/digitalocean.py�assign_ipv4_link_local s0 �
��r c s. � fdd�t �� D �}|sd S t|dd� d�S )Nc s g | ]}� j �|�r|�qS r )Z
networkingZis_physical)�.0�f�r r r �
<listcomp>9 s �z&get_link_local_nic.<locals>.<listcomp>c S s t �| d�S )NZifindex)�cloudnetZread_sys_net_int)�dr r r �<lambda>@ � z$get_link_local_nic.<locals>.<lambda>)�key)r Zget_devicelist�min)r Znicsr r r r
8 s
�r
c
C sp |st �d� dS t �d� z| j�|� t �d|� W n2 tk
rj } zt�t d||� W 5 d}~X Y nX dS )zwRemove the ip4LL address. While this is not necessary, the ip4LL
address is extraneous and confusing to users.
zLno link_local address interface defined, skipping link local address cleanupNzcleaning up ipv4LL addresszremoved ip4LL addresses from %sz)failed to remove ip4LL address from '%s'.)r r r Z
flush_addrr r r )r r �er r r �del_ipv4_link_localC s �
r# c C sV dd� }g }t �� }t�d|� | D �]}| | d }t�d|� |�d�}||krdtd||f ��|�|�}|�dd �} t�| |�}
|
|kr�t�d
| |||
� nd}t�|||� d||
d
�}g }
dD ]>}|�|d�}|s�q�||�}| dks�d|kr�|d= |
�|� q�|
|d<