Current File : //usr/lib/python3/dist-packages/cloudinit/net/__pycache__/ephemeral.cpython-312.pyc |
�
Ӈg V � �& � d Z ddlZddlZddlmZ ddlmZmZmZm Z m
Z
mZmZ ddl
mZ ddlmZ ddlmZmZ ddlmZ ddlmZmZ ej2 e� Z G d� d � Z G d
� d� Z G d� d
� Z G d� d� Zde ee ef dee fd�Z!y)z.Module for ephemeral network context managers
� N)�partial)�Any�Callable�Dict�List�Literal�Optional�Tuple)�NoDHCPLeaseError�maybe_perform_dhcp_discovery)�ProcessExecutionError)�UrlError�wait_for_urlc �@ � e Zd ZdZ d
defd�Zd� Zd� Zd� Zd� Z d � Z
y)�EphemeralIPv4Networka� Context manager which sets up temporary static network configuration.
No operations are performed if the provided interface already has the
specified configuration.
This can be verified with the connectivity_urls_data.
If unconnected, bring up the interface with valid ip, prefix and broadcast.
If router is provided setup a default route for that interface. Upon
context exit, clean up the interface leaving no configuration behind.
N�interface_addrs_before_dhcpc �� � t ||||g� st dj ||||� � � t j |� | _ || _ || _ || _ || _ || _
g | _ || _ | j � d| j
� �| _
|j | j i � | _ y# t $ r } t dj | � � | �d} ~ ww xY w)a� Setup context manager and validate call signature.
@param interface: Name of the network interface to bring up.
@param ip: IP address to assign to the interface.
@param prefix_or_mask: Either netmask of the format X.X.X.X or an int
prefix.
@param broadcast: Broadcast address for the IPv4 network.
@param router: Optionally the default gateway IP.
@param static_routes: Optionally a list of static routes from DHCP
z5Cannot init network on {0} with {1}/{2} and bcast {3}z4Cannot setup network, invalid prefix or netmask: {0}N�/)�all�
ValueError�format�net�ipv4_mask_to_net_prefix�prefix� interface�ip� broadcast�router�
static_routes�cleanup_cmds�distro�cidr�getr )
�selfr! r r �prefix_or_maskr r r r �es
�9/usr/lib/python3/dist-packages/cloudinit/net/ephemeral.py�__init__zEphemeralIPv4Network.__init__ s� � �* �I�r�>�9�=�>��G�N�N��r�>�9���
�
��5�5�n�E�D�K� #������"������*���,.�������w�w�i�q����
�.�� �+F�+J�+J��N�N�B�,
��(�� � ���%�v�a�y�� �
�� �s �B; �; C$�C�C$c �h � | j � | j r| j � y| j r| j � yy# t $ r9}dt |j � vrdt |j � vr� Y d}~�xd}~ww xY w# t $ r | j ddd� � w xY w)z�Set up ephemeral network if interface is not connected.
This context manager handles the lifecycle of the network interface,
addresses, routes, etc
zFile existszAddress already assignedN) �_bringup_devicer
�str�stderrr �_bringup_static_routesr �_bringup_router�__exit__)r$ r&