File manager - Edit - /usr/lib/python3/dist-packages/cloudinit/net/__pycache__/ephemeral.cpython-310.pyc
Back
o o@�d�: � @ s� d Z ddlZddlZddlmZmZmZmZ ddlm Z ddl mZ ddlm Z mZmZ e�e�ZG dd� d�ZG dd � d �ZG d d� d�ZG dd � d �ZdS )z.Module for ephemeral network context managers � N)�Any�Dict�List�Optional)�subp)�IscDhclient�NoDHCPLeaseError�maybe_perform_dhcp_discoveryc @ sZ e Zd ZdZ ddeeeef fdd�Zdd� Z dd � Z d d� Zdd � Zdd� Z dS )�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_url_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�connectivity_url_datac C s� t ||||g�std�||||���zt�|�| _W n ty. } ztd�|��|�d}~ww || _|| _|| _|| _ || _ || _g | _dS )aX 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 connectivity_url_data: Optionally, a URL to verify if a usable connection already exists. @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�prefixr � interface�ip� broadcast�router� static_routes�cleanup_cmds) �selfr r �prefix_or_maskr r r r �e� r �9/usr/lib/python3/dist-packages/cloudinit/net/ephemeral.py�__init__ s0 ������ zEphemeralIPv4Network.__init__c C s� | j rt�| j �rt�d| j d � dS z| �� | jr#| �� W dS | jr-| � � W dS W dS t jyD t�d� | � ddd� � w )z>Perform ephemeral network setup if interface is not connected.z=Skip ephemeral network setup, instance has connectivity to %s�urlNzHError bringing up EphemeralIPv4Network. Datasource setup cannot continue)r r �has_url_connectivity�LOG�debug�_bringup_devicer �_bringup_static_routesr �_bringup_routerr �ProcessExecutionError�error�__exit__�r r r r � __enter__L s* ����zEphemeralIPv4Network.__enter__c C s | j D ] }tj|dd� qdS )zTeardown anything we set up.T��captureN)r r )r � excp_type� excp_value�excp_traceback�cmdr r r r'