File: //snap/core20/2669/lib/python3/dist-packages/cloudinit/net/__pycache__/dhcp.cpython-38.pyc
U
Ӈg֏ � @ s� d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl m
Z
d dlmZ d dl
mZ d dlmZmZmZmZmZmZ d dlZd dlmZmZmZ d dlmZmZ e�e�Z dZ!d Z"d
Z#dZ$G dd
� d
e%�Z&G dd� de&�Z'G dd� de&�Z(G dd� de&�Z)d%ee*ef d�dd�Z+dd� Z,d&dd�Z-d'dd�Z.G dd� de j/�Z0G dd � d e0�Z1G d!d"� d"e0�Z2G d#d$� d$e0�Z3e2e1e3gZ4dS )(� N)�suppress)�StringIO)�TimeoutExpired)�Any�Callable�Dict�List�Optional�Tuple)�subp�
temp_utils�util)�get_interface_mac�is_ib_interfacez/run/systemd/netif/leasesz/var/lib/dhclientz.+\.leases?$aN #!/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 �4/usr/lib/python3/dist-packages/cloudinit/net/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.
Nr r r r r r E s r c @ s e Zd ZdZdS )�NoDHCPLeaseInterfaceErrorz7Raised when unable to find a viable interface for DHCP.Nr r r r r r M s r c @ s e Zd ZdZdS )�NoDHCPLeaseMissingDhclientErrorz$Raised when unable to find dhclient.Nr r r r r r Q s r ��returnc C s2 |p| j }|dkr"t�d� 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.)Zfallback_interface�LOG�debugr Zdhcp_client�dhcp_discovery)�distroZnic�
dhcp_log_func� interfacer r r �maybe_perform_dhcp_discoveryU s
r# c C s t tjt| �dd��S )z�Parse 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 )�contentr r r �networkd_parse_leasel s r'