�
܍~cp. � �0 � d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ d dlZd dl m
Z
mZ d dlm
Z
mZ ej e� � ZdZ G d� de� � Z G d� d e� � Z G d
� de� � Z G d� d
e� � Zdd�Zd� Zdd�Zd� Zdd�Zdd�Zd� ZdS )� N)�StringIO)�subp�util)�find_fallback_nic�get_devicelistz/run/systemd/netif/leasesc � � e Zd ZdZdS )�NoDHCPLeaseErrorz'Raised when unable to get a DHCP lease.N��__name__�
__module__�__qualname__�__doc__� � �4/usr/lib/python3/dist-packages/cloudinit/net/dhcp.pyr r s � � � � � �1�1�1�1r r c � � e Zd ZdZdS )�InvalidDHCPLeaseFileErrorz�Raised when parsing an empty or invalid dhclient.lease file.
Current uses are DataSourceAzure and DataSourceEc2 during ephemeral
boot to scrape metadata.
Nr
r r r r r s � � � � � �� � � r r c � � e Zd ZdZdS )�NoDHCPLeaseInterfaceErrorz7Raised when unable to find a viable interface for DHCP.Nr
r r r r r % s � � � � � �A�A�A�Ar r c � � e Zd ZdZdS )�NoDHCPLeaseMissingDhclientErrorz$Raised when unable to find dhclient.Nr
r r r r r ) s � � � � � �.�.�.�.r r c � � | �9t � � } | �(t � d� � t � � �n9| t � � vr)t � d| � � t � � �t j d� � }|s(t � d� � t � � �t || |� � S )aJ Perform dhcp discovery if nic valid and dhclient command exists.
If the nic is invalid or undiscoverable or dhclient command is not found,
skip dhcp_discovery and return an empty dict.
@param nic: Name of the network interface we want to run dhclient on.
@param dhcp_log_func: A callable accepting the dhclient output and error
streams.
@param tmp_dir: Tmp dir with exec permissions.
@return: A list of dicts representing dhcp options for each lease obtained
from the dhclient discovery if run, otherwise an empty list is
returned.
Nz1Skip dhcp_discovery: Unable to find fallback nic.z8Skip dhcp_discovery: nic %s not found in get_devicelist.�dhclientz7Skip dhclient configuration: No dhclient command found.) r �LOG�debugr r r �whichr �dhcp_discovery)�nic�
dhcp_log_func�tmp_dir�
dhclient_paths r �maybe_perform_dhcp_discoveryr" |