%PDF- %PDF-
| Direktori : /snap/core18/current/usr/lib/python3/dist-packages/cloudinit/net/__pycache__/ |
| Current File : //snap/core18/current/usr/lib/python3/dist-packages/cloudinit/net/__pycache__/dhcp.cpython-36.pyc |
3
�Adp. � @ s� d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ d dlZd dl m
Z
mZ d dlm
Z
mZ eje�ZdZG dd� de�ZG dd � d e�ZG d
d� de�ZG dd
� d
e�Zddd�Zdd� Zddd�Zdd� Zddd�Zddd�Zdd� ZdS ) � N)�StringIO)�subp�util)�find_fallback_nic�get_devicelistz/run/systemd/netif/leasesc @ s e Zd ZdZdS )�NoDHCPLeaseErrorz'Raised when unable to get a DHCP lease.N)�__name__�
__module__�__qualname__�__doc__� r r �4/usr/lib/python3/dist-packages/cloudinit/net/dhcp.pyr s r c @ s 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.
N)r r r
r r r r r
r s r c @ s e Zd ZdZdS )�NoDHCPLeaseInterfaceErrorz7Raised when unable to find a viable interface for DHCP.N)r r r
r r r r r
r % s r c @ s e Zd ZdZdS )�NoDHCPLeaseMissingDhclientErrorz$Raised when unable to find dhclient.N)r r r
r r r r r
r ) s r c C sn | dkr(t � } | dkrDtjd� t� �n| t� krDtjd| � t� �tjd�}|sbtjd� 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.Zdhclientz7Skip dhclient configuration: No dhclient command found.) r �LOG�debugr r r Zwhichr �dhcp_discovery)Znic�
dhcp_log_funcZtmp_dirZ
dhclient_pathr r r
�maybe_perform_dhcp_discovery- s
r c C s� t jdt j�}g }tj| �}t|�dkr6tdj| ���xh|j|�D ]Z}g }xB|j d�D ]4}|j
� jdd�jdd�}|sxqV|j|j dd �� qVW |jt
|�� qBW |s�td
j| ���|S )a Parse the given dhcp lease file for the most recent lease.
Return a list of dicts of dhcp options. Each dict contains key value pairs
a specific lease in order from oldest to newest.
@raises: InvalidDHCPLeaseFileError on empty of unparseable leasefile
content.
zlease {(?P<lease>.*?)}\nr z&Cannot parse empty dhcp lease file {0}�;�"� zoption � � z1Cannot parse dhcp lease file {0}. No leases found)�re�compile�DOTALLr � load_file�lenr �format�findall�split�strip�replace�append�dict)�
lease_fileZlease_regexZdhcp_leasesZ
lease_contentZleaseZ
lease_options�liner r r
�parse_dhcp_lease_fileL s&