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 ejeZdZdZG dd d eZG d
d deZ G dd
d
eZ!G dd deZ"G dd deZ#dd Z$d$ddZ%dd Z&d%ddZ'd&ddZ(G dd de j)Z*G dd de*Z+G d d! d!Z,G d"d# d#e*Z-dS )' N)StringIO)AnyDictList)subp
temp_utilsutil)find_fallback_nicget_devicelistget_ib_interface_hwaddrget_interface_macis_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 < "$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 )InvalidDHCPLeaseFileErrorzRaised 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 )zdistros 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_priorityLOGdebugclient_namer r warning)distroclientZdhcp_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" c C s t tjt| ddS )zParse a systemd lease file content as in /run/systemd/netif/leases/
Parse this (almost) ini style file even though it says:
# This is private data. Do not parse.
Simply return a dictionary of key/values.F)Zlist_values)dict configobjZ ConfigObjr )Zcontentr r r networkd_parse_lease s r% c C sT | dkrt } i }tjj| s |S x.tj| D ] }ttjtjj| |||<