�
�fE � � � d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZmZm Z ddd�Z
ej e� Z
dd�Zd � Zdd
�Zd� Zdd�Zd
� Zy)� N)�dmi)�net)�subp�
url_helper�util�eth0�eth1)�public�privatec �> � |s!t | � }t j d|� |st d� �dj t j dd� t j dd� � }dd d
|d|g}ddd
d|dg}t j d� st d� � t j |� t j d||� t j |� t j d|� |S # t $ r t j t d||� � w xY w)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 � �ip�addr�add�dev�link�set�upz4No 'ip' command available to configure ip4LL addressz#assigned ip4LL address '%s' to '%s'zbrought device '%s' upzRip4LL address assignment of '%s' to '%s' failed. Droplet networking will be broken)�get_link_local_nic�LOG�debug�RuntimeError�format�random�randintr �which� Exceptionr �logexc)�distro�nicr �ip_addr_cmd�ip_link_cmds �H/usr/lib/python3/dist-packages/cloudinit/sources/helpers/digitalocean.py�assign_ipv4_link_localr& |