관리-도구
편집 파일: ephemeral.cpython-39.opt-1.pyc
a '�Dg 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�Ze ee ef ee d�dd�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 @ sH e Zd ZdZded�dd�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�s$td�||||���zt�|�| _W n4 tyh } ztd�| ��| �W Y d} ~ n d} ~ 0 0 || _|| _|| _|| _ || _ 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�netZipv4_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# �;/usr/lib/python3.9/site-packages/cloudinit/net/ephemeral.py�__init__ s6 ������zEphemeralIPv4Network.__init__c C s� zrz| � � W nB tyP } z*dt|j�vr<dt|j�vr<� W Y d}~n d}~0 0 | jrb| �� n| jrp| �� W n" ty� | �ddd� � Y n0 dS )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"