Server IP : 209.38.156.173 / Your IP : 216.73.216.122 [ Web Server : Apache/2.4.52 (Ubuntu) System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.1.2-1ubuntu2.22 Disable Function : NONE Domains : 2 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /usr/lib/python3/dist-packages/cloudinit/net/__pycache__/ |
Upload File : |
o x[h V � @ s� d Z ddlZddlZddlmZ ddlmZmZmZm Z m Z mZmZ ddl mZ ddlmZ ddlmZmZ ddlmZ ddlmZmZ e�e�ZG dd � d �ZG d d� d�ZG dd � d �ZG dd� d�Zde ee ef dee fdd�Z!dS )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 @ sL e Zd ZdZ ddefdd�Zdd� Zdd � Zd d� Zdd � Z dd� 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_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 C s� t ||||g�std�||||���zt�|�| _W n ty. } ztd�| ��| �d} ~ ww || _|| _|| _|| _ || _ g | _|| _| j� d| j� �| _ |�| ji �| _dS )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 �e� r$ �9/usr/lib/python3/dist-packages/cloudinit/net/ephemeral.py�__init__ s8 ������ �zEphemeralIPv4Network.__init__c C s� z?z| � � W n! ty( } zdt|j�vrdt|j�vr� W Y d}~nd}~ww | jr3| �� W dS | jr=| �� W dS W dS tyN | �ddd� � 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# r$ r$ r% � __enter__N s( �����zEphemeralIPv4Network.__enter__c C s | j D ]}|� qdS )zTeardown anything we set up.N)r )r! � excp_type� excp_value�excp_traceback�cmdr$ r$ r% r, r s �zEphemeralIPv4Network.__exit__c C s: t �d| j| j| j� t�� �| ji �}|�d�}| j�d�}| j dd� |�di �D �v }| j dd� | j�di �D �v }|rHt �d| j| j � n| j j�| j| j| j� |r^t �d| j� n | j jj | jd d � |rrt �d| j� n| j�t| j jj| jd d �� |r�t �d| j � d S | j�t| j jj| j| j�� d S )af Perform the ip commands to fully set up the device. Dhcp clients behave differently in how they leave link state and ip address assignment. Attempt assigning address and setting up link if needed to be done. Set cleanup_cmds to return the interface state to how it was prior to execution of the dhcp client. z:Attempting setup of ephemeral network on %s with %s brd %s�upc S � g | ]}|� d ��qS �r �r ��.0r r$ r$ r% � <listcomp>� s �z8EphemeralIPv4Network._bringup_device.<locals>.<listcomp>�ipv4c S r3 r4 r5 r6 r$ r$ r% r8 � s ��z1Skip adding ip address: %s already has address %sz9Skip bringing up network link: interface %s is already up�inet)�familyzLNot queueing link down: link [%s] was up prior before receiving a dhcp leasezSNot queueing address removal: address %s was assigned before receiving a dhcp leaseN)�LOG�debugr r r �netinfo�netdev_infor r r r �net_ops�add_addr�link_upr �appendr � link_down�del_addr)r! �interface_addrs_after_dhcp�has_link�had_link�has_ip�had_ipr$ r$ r% r'