�
܍~cr � � � d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlmZm Z m
Z
ddd�Z ej e
� � Zdd �Zd
� Zdd�Zd� Zdd�Zd� ZdS )� N)�dmi)�log)�net)�subp�
url_helper�util�eth0�eth1)�public�privatec �v � |s*t | � � }t � d|� � |st d� � �d� t j dd� � t j dd� � � � }dd d
|d|g}ddd
d|dg}t j d� � st d� � � t j |� � t � d||� � t j |� � t � d|� � n+# t $ r t j t d||� � � w xY w|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 � �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' |