Spamworldpro Mini Shell
Spamworldpro


Server : Apache/2.4.52 (Ubuntu)
System : Linux webserver 6.8.0-49-generic #49~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Nov 6 17:42:15 UTC 2 x86_64
User : www-data ( 33)
PHP Version : 8.1.2-1ubuntu2.21
Disable Function : NONE
Directory :  /lib/python3/dist-packages/cloudinit/net/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/cloudinit/net/__pycache__/ephemeral.cpython-310.pyc
o

}��f�>�@s�dZddlZddlZddlmZddlmZmZmZm	Z	m
Z
ddlmZddl
mZddlmZmZddlmZe�e�ZGdd�d�ZGd	d
�d
�ZGdd�d�ZGd
d�d�ZdS)z.Module for ephemeral network context managers
�N)�partial)�Any�Callable�Dict�List�Optional)�NoDHCPLeaseError�maybe_perform_dhcp_discovery)�ProcessExecutionErrorc@sLeZdZdZ		ddefdd�Zdd�Zdd	�Zd
d�Zdd
�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_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�interface_addrs_before_dhcpc	

Cs�t||||g�std�||||���zt�|�|_Wnty.}	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)
�selfrrr�prefix_or_maskrrrr�e�r �9/usr/lib/python3/dist-packages/cloudinit/net/ephemeral.py�__init__s8������
�zEphemeralIPv4Network.__init__c
Cs�z?z|��Wn!ty(}zdt|j�vrdt|j�vr�WYd}~nd}~ww|jr3|��WdS|jr=|��WdSWdStyN|�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__)rrr r r!�	__enter__Ms(�����zEphemeralIPv4Network.__enter__cCs|jD]}|�qdS)zTeardown anything we set up.N)r)r�	excp_type�
excp_value�excp_traceback�cmdr r r!r(qs
�zEphemeralIPv4Network.__exit__cCs: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)afPerform 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�upcS�g|]}|�d��qS�r�r��.0rr r r!�
<listcomp>�s
�z8EphemeralIPv4Network._bringup_device.<locals>.<listcomp>�ipv4cSr/r0r1r2r r r!r4�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�debugrrr�netinfo�netdev_inforrrr�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#vsl
��


�
����������z$EphemeralIPv4Network._bringup_devicec
CsJ|jD]\}}|jj�|j||�|j�dt|jjj|j||d��qdS)Nr��gateway)	rrr<�append_routerr�insertr�	del_route)r�net_addressrHr r r!r&�s����z+EphemeralIPv4Network._bringup_static_routesc	Cs�|jj��}d|vrt�d|j|���dS|jjj|j|j|j	d�|j
�dt|jjj
|j|j|j	d��|jjj|jd|jd�|j
�dt|jjj
|jd��dS)z<Perform the ip commands to fully setup the router if needed.�defaultz<Skip ephemeral route setup. %s already has default route: %sN)�source_addressrrG)rr<�get_default_router8r9r�strip�	add_routerrrrJrrK)r�outr r r!r'�s6����	
��z$EphemeralIPv4Network._bringup_router)NN)�__name__�
__module__�__qualname__�__doc__�dictr"r)r(r#r&r'r r r r!rs�
�0$Irc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�EphemeralIPv6Networkz�Context manager which sets up a ipv6 link local address

    The linux kernel assigns link local addresses on link-up, which is
    sufficient for link-local communication.
    cCs"|s	td�|���||_||_dS)z�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: IPv6 uses prefixes, not netmasks
        zCannot init network on {0}N)rrrr)rrrr r r!r"�s
zEphemeralIPv6Network.__init__cCs*t�|jd�dkr|jj�|j�dSdS)z�linux kernel does autoconfiguration even when autoconf=0

        https://www.kernel.org/doc/html/latest/networking/ipv6.html
        �	operstater.N)r�read_sys_netrrr<r>�rr r r!r)s�zEphemeralIPv6Network.__enter__cGsdS)z%No need to set the link to down stateNr �r�_argsr r r!r(szEphemeralIPv6Network.__exit__N)rSrTrUrVr"r)r(r r r r!rX�s

rXc@s^eZdZ			ddeeeeffdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dS)�EphemeralDHCPv4N�connectivity_url_datacCs2||_d|_d|_||_||_||_t��|_dS�N)	�iface�_ephipv4�lease�
dhcp_log_funcr_rr:r;r)rrrar_rdr r r!r"szEphemeralDHCPv4.__init__cCs,|jrt�|j�rt�d|j�dS|��S)zUSetup sandboxed dhcp context, unless connectivity_url can already be
        reached.z:Skip ephemeral DHCP setup, instance has connectivity to %sN)r_r�has_url_connectivityr8r9�obtain_leaser[r r r!r)'s�zEphemeralDHCPv4.__enter__cCs|��dS)z Teardown sandboxed dhcp context.N)�
clean_network)rr*r+r,r r r!r(4szEphemeralDHCPv4.__exit__cCs$d|_|jr|j�ddd�dSdS)z@Exit _ephipv4 context to teardown of ip configuration performed.N)rcrbr(r[r r r!rg8s�zEphemeralDHCPv4.clean_networkcCs�|jr|jSt|j|j|j�|_|jst��t�d|jd|jd|jd�ddddgd�dd�}|�|�}|d	sGt	�
|d
|d�|d	<|drV|jj�|d�|d<t
|jfd
|ji|��}|��||_|jS)a9Perform dhcp discovery in a sandboxed environment if possible.

        @return: A dict representing dhcp options on the most recent lease
            obtained from the dhclient discovery if run, otherwise an error
            is raised.

        @raises: NoDHCPLeaseError if no leases could be obtained.
        z#Received dhcp lease on %s for %s/%srz
fixed-addresszsubnet-maskzbroadcast-address)zrfc3442-classless-static-routeszclassless-static-routesrzunknown-121�routers)rrrrrrrrrrr)rcr	rrardrr8r9�extract_dhcp_options_mappingr�mask_and_ipv4_to_bcast_addr�dhcp_client�parse_static_routesrrr)rb)r�nmap�kwargs�ephipv4r r r!rf>sT	���

�������zEphemeralDHCPv4.obtain_leasecCsDi}|��D]\}}t|t�r|�|||�q|j�|�||<q|Sr`)�items�
isinstance�list�get_first_option_valuercr)rrm�result�internal_reference�lease_option_namesr r r!rius
�z,EphemeralDHCPv4.extract_dhcp_options_mappingcCs(|D]}|�|�s|j�|�||<qdSr`)rrc)r�internal_mappingrvrt�different_namesr r r!rs�s

��z&EphemeralDHCPv4.get_first_option_value)NNN)rSrTrUrrr$rr"r)r(rgrfrirsr r r r!r^s�
�
7r^c@s8eZdZdZ		d
dedefdd�Zdd	�Zd
d�ZdS)�EphemeralIPNetworkahCombined ephemeral context manager for IPv4 and IPv6

    Either ipv4 or ipv6 ephemeral network may fail to initialize, but if either
    succeeds, then this context manager will not raise exception. This allows
    either ipv4 or ipv6 ephemeral network to succeed, but requires that error
    handling for networks unavailable be done within the context.
    FT�ipv6r5cCs,||_||_||_t��|_d|_||_dS)N�)rr5rz�
contextlib�	ExitStack�stack�	state_msgr)rrrrzr5r r r!r"�s

zEphemeralIPNetwork.__init__c
Cs|js|js|Sg}d}|jr>z|j�t|j|j��d}Wnttfy=}zt	�
d|�|�|�WYd}~nd}~ww|jrvz|j�t|j|j��d}|sT|jsWd|_
Wntyu}zt	�
d|�|�|�WYd}~nd}~ww|s�t	�d�|d�|S)NFTzFailed to bring up %s for ipv4.zusing link-local ipv6zFailed to bring up %s for ipv6.zGFailed to bring up EphemeralIPNetwork. Datasource setup cannot continuer)r5rzr~�
enter_contextr^rrr
rr8�infor?rXr�error)r�
exceptions�ephemeral_obtainedrr r r!r)�sR������
����zEphemeralIPNetwork.__enter__cGs|j��dSr`)r~�closer\r r r!r(�szEphemeralIPNetwork.__exit__N)FT)rSrTrUrV�boolr"r)r(r r r r!ry�s��
�,ry)rVr|�logging�	functoolsr�typingrrrrr�
cloudinit.netr�cloudinit.netinfor:�cloudinit.net.dhcprr	�cloudinit.subpr
�	getLoggerrSr8rrXr^ryr r r r!�<module>s
f q

Spamworldpro Mini