3 \�me9T � @ sl d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlm Z d dl mZmZm Z d dlZd dlmZmZmZ d dlmZmZmZmZmZ eje�ZdZdZG dd � d e�ZG d d� de�Z G dd � d e�Z!G dd� de�Z"G dd� de�Z#dd� Z$d$dd�Z%dd� Z&d%dd�Z'd&dd�Z(G dd� de j)�Z*G dd� de*�Z+G d d!� d!�Z,G d"d#� d#e*�Z-dS )'� N)�StringIO)�Any�Dict�List)�subp� temp_utils�util)�find_fallback_nic�get_devicelist�get_ib_interface_hwaddr�get_interface_mac�is_ib_interfacez/run/systemd/netif/leasesaN #!/bin/sh log() { echo "udhcpc[$PPID]" "$interface: $2" } [ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1 case $1 in bound|renew) cat <<JSON > "$LEASE_FILE" { "interface": "$interface", "fixed-address": "$ip", "subnet-mask": "$subnet", "routers": "${router%% *}", "static_routes" : "${staticroutes}" } JSON ;; deconfig) log err "Not supported" exit 1 ;; leasefail | nak) log err "configuration failed: $1: $message" exit 1 ;; *) echo "$0: Unknown udhcpc command: $1" >&2 exit 1 ;; esac c @ s e Zd ZdZdS )�NoDHCPLeaseErrorz'Raised when unable to get a DHCP lease.N)�__name__� __module__�__qualname__�__doc__� r r �/usr/lib/python3.6/dhcp.pyr A 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 E 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 M s r c @ s e Zd ZdZdS )�NoDHCPLeaseMissingDhclientErrorz$Raised when unable to find dhclient.N)r r r r r r r r r Q s r c @ s e Zd ZdZdS )�NoDHCPLeaseMissingUdhcpcErrorz)Raised when unable to find udhcpc client.N)r r r r r r r r r U s r c C sZ xN| j D ]D}y|� }tjd|j� |S ttfk rJ tjd|j� Y qX qW t� �dS )z�distros set priority list, select based on this order which to use If the priority dhcp client isn't found, fall back to lower in list. zDHCP client selected: %szDHCP client not found: %sN)Zdhcp_client_priority�LOG�debug�client_namer r �warning)�distro�clientZdhcp_clientr r r �select_dhcp_clientY s r c C sZ |dkr(t � }|dkrDtjd� t� �n|t� krDtjd|� t� �t| �}|j||| �S )a 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. @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.)r r r r r r �dhcp_discovery)r Znic� dhcp_log_funcr r r r �maybe_perform_dhcp_discoveryk s r"