404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@18.224.70.66: ~ $
3

\�meS9�@s�dZddlZddlZddlmZddlmZmZmZm	Z	m
Z
ddljZddl
mZmZmZddlmZeje�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)�IscDhclient�NoDHCPLeaseError�maybe_perform_dhcp_discovery)�ProcessExecutionErrorc@sTeZdZdZdeeeefd�dd�Zdd�Z	dd	�Z
d
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)�connectivity_url_datac	
Cs�t||||g�s$tdj||||���ytj|�|_Wn2tk
rf}	ztdj|	��|	�WYdd}	~	XnX||_||_||_||_	||_
||_g|_||_
dS)aXSetup 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�netZipv4_mask_to_net_prefix�prefixr
�	interface�ip�	broadcast�router�
static_routes�cleanup_cmds�distro)
�selfrrr�prefix_or_maskrrr
r�e�r�/usr/lib/python3.6/ephemeral.py�__init__ s&zEphemeralIPv4Network.__init__cCs||jr(tj|j�r(tjd|jd�dSy*|j�|jrB|j�n|jrP|j	�Wn$t
k
rv|jddd��YnXdS)z>Perform ephemeral network setup if interface is not connected.z=Skip ephemeral network setup, instance has connectivity to %sZurlN)r
r�has_url_connectivity�LOG�debug�_bringup_devicer�_bringup_static_routesr�_bringup_routerr�__exit__)rrrr�	__enter__Os
zEphemeralIPv4Network.__enter__cCsx|jD]
}|�qWdS)zTeardown anything we set up.N)r)r�	excp_type�
excp_value�excp_traceback�cmdrrrr&qszEphemeralIPv4Network.__exit__cCs�dj|j|j�}tjd|j||j�y|jjj	|j||j�WnDt
k
r�}z(dt|j�kr`�tjd|j|j�WYdd}~XnPX|jjj
|jdd�|jjt|jjj|jdd��|jjt|jjj|j|��dS)z1Perform the ip comands to fully setup the device.z{0}/{1}z:Attempting setup of ephemeral network on %s with %s brd %szFile existsz7Skip ephemeral network setup, %s already has address %sNZinet)Zfamily)rrrr!r"rrr�net_opsZadd_addrr�str�stderr�link_upr�appendrZ	link_downZdel_addr)rZcidrrrrrr#vs.
z$EphemeralIPv4Network._bringup_devicec	CsNxH|jD]>\}}|jjj|j||�|jjdt|jjj|j||d��qWdS)Nr)�gateway)	rrr,Zappend_routerr�insertr�	del_route)rZnet_addressr1rrrr$�sz+EphemeralIPv4Network._bringup_static_routescCs�|jjj�}d|kr,tjd|j|j��dS|jjj|j|j|j	d�|j
jdt|jjj
|j|j|j	d��|jjj|jd|jd�|j
jdt|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)Zsource_addressr)r1)rr,Zget_default_router!r"r�stripZ	add_routerrrr2rr3)r�outrrrr%�s*
z$EphemeralIPv4Network._bringup_router)NNN)�__name__�
__module__�__qualname__�__doc__rrr-rrr'r&r#r$r%rrrrrs		&"!rc@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"|stdj|���||_||_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)rrrrrrr�szEphemeralIPv6Network.__init__cCs&tj|jd�dkr"|jjj|j�dS)z�linux kernel does autoconfiguration even when autoconf=0

        https://www.kernel.org/doc/html/latest/networking/ipv6.html
        Z	operstateZupN)rZread_sys_netrrr,r/)rrrrr'�szEphemeralIPv6Network.__enter__cGsdS)z%No need to set the link to down stateNr)r�_argsrrrr&�szEphemeralIPv6Network.__exit__N)r7r8r9r:rr'r&rrrrr;�s
r;c@sXeZdZdeeeefd�dd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dS)�EphemeralDHCPv4N)r
cCs(||_d|_d|_||_||_||_dS)N)�iface�_ephipv4�lease�
dhcp_log_funcr
r)rrr>r
rArrrr�szEphemeralDHCPv4.__init__cCs,|jr$tj|j�r$tjd|j�dS|j�S)zUSetup sandboxed dhcp context, unless connectivity_url can already be
        reached.z:Skip ephemeral DHCP setup, instance has connectivity to %sN)r
rr r!r"�obtain_lease)rrrrr'�szEphemeralDHCPv4.__enter__cCs|j�dS)z Teardown sandboxed dhcp context.N)�
clean_network)rr(r)r*rrrr&szEphemeralDHCPv4.__exit__cCs d|_|jr|jjddd�dS)z@Exit _ephipv4 context to teardown of ip configuration performed.N)r@r?r&)rrrrrCszEphemeralDHCPv4.clean_networkcCs�|jr|jSt|j|j|j�}|s(t��|d|_tjd|jd|jd|jd�ddddddgd	d
�}|j|�}|ds�t	j
|d|d
�|d<|dr�tj|d�|d<|j
r�|j
|d<t|jf|�}|j�||_|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-addresszrfc3442-classless-static-routeszclassless-static-routesZrouters)rrrrrrrrrrr
���)r@r
rr>rAr	r!r"�extract_dhcp_options_mappingrZmask_and_ipv4_to_bcast_addrrZparse_static_routesr
rr'r?)rZleases�nmap�kwargsZephipv4rrrrBs@	


zEphemeralDHCPv4.obtain_leasecCsHi}x>|j�D]2\}}t|t�r0|j|||�q|jj|�||<qW|S)N)�items�
isinstance�list�get_first_option_valuer@�get)rrG�resultZinternal_reference�lease_option_namesrrrrFGs
z,EphemeralDHCPv4.extract_dhcp_options_mappingcCs,x&|D]}|j|�s|jj|�||<qWdS)N)rMr@)rZinternal_mappingrOrNZdifferent_namesrrrrLRs

z&EphemeralDHCPv4.get_first_option_value)NNN)r7r8r9rrr-rrr'r&rCrBrFrLrrrrr=�s	
2r=c@s2eZdZdZdeed�dd�Zdd�Zd	d
�ZdS)
�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)�ipv6�ipv4cCs,||_||_||_tj�|_d|_||_dS)N�)rrRrQ�
contextlib�	ExitStack�stack�	state_msgr)rrrrQrRrrrrcs
zEphemeralIPNetwork.__init__cCs|jp
|js|Sg}d}|jrzy|jjt|j|j��d}Wn<ttfk
rx}zt	j
d|�|j|�WYdd}~XnX|jr�y0|jjt|j|j��d}|s�|jr�d|_
Wn8tk
r�}zt	j
d|�|j|�WYdd}~XnX|�st	jd�|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)rRrQrV�
enter_contextr=rrrr	r!�infor0r;rW�error)r�
exceptionsZephemeral_obtainedrrrrr'qs>


zEphemeralIPNetwork.__enter__cGs|jj�dS)N)rV�close)rr<rrrr&�szEphemeralIPNetwork.__exit__N)FT)r7r8r9r:�boolrr'r&rrrrrPZs
	,rP)r:rTZlogging�	functoolsrZtypingrrrrrZ
cloudinit.netrZcloudinit.net.dhcprr	r
Zcloudinit.subprZ	getLoggerr7r!rr;r=rPrrrr�<module>s

; k

Filemanager

Name Type Size Permission Actions
__init__.cpython-36.opt-1.pyc File 33.43 KB 0644
__init__.cpython-36.pyc File 33.43 KB 0644
activators.cpython-36.opt-1.pyc File 9.52 KB 0644
activators.cpython-36.pyc File 9.52 KB 0644
bsd.cpython-36.opt-1.pyc File 5.74 KB 0644
bsd.cpython-36.pyc File 5.74 KB 0644
cmdline.cpython-36.opt-1.pyc File 7.2 KB 0644
cmdline.cpython-36.pyc File 7.2 KB 0644
dhcp.cpython-36.opt-1.pyc File 15.98 KB 0644
dhcp.cpython-36.pyc File 15.98 KB 0644
eni.cpython-36.opt-1.pyc File 12.89 KB 0644
eni.cpython-36.pyc File 12.89 KB 0644
ephemeral.cpython-36.opt-1.pyc File 10.51 KB 0644
ephemeral.cpython-36.pyc File 10.51 KB 0644
freebsd.cpython-36.opt-1.pyc File 2.54 KB 0644
freebsd.cpython-36.pyc File 2.54 KB 0644
netbsd.cpython-36.opt-1.pyc File 1.69 KB 0644
netbsd.cpython-36.pyc File 1.69 KB 0644
netplan.cpython-36.opt-1.pyc File 11.91 KB 0644
netplan.cpython-36.pyc File 11.91 KB 0644
network_manager.cpython-36.opt-1.pyc File 12.83 KB 0644
network_manager.cpython-36.pyc File 12.83 KB 0644
network_state.cpython-36.opt-1.pyc File 27.57 KB 0644
network_state.cpython-36.pyc File 27.57 KB 0644
networkd.cpython-36.opt-1.pyc File 8.21 KB 0644
networkd.cpython-36.pyc File 8.21 KB 0644
openbsd.cpython-36.opt-1.pyc File 2.18 KB 0644
openbsd.cpython-36.pyc File 2.18 KB 0644
renderer.cpython-36.opt-1.pyc File 1.82 KB 0644
renderer.cpython-36.pyc File 1.82 KB 0644
renderers.cpython-36.opt-1.pyc File 1.53 KB 0644
renderers.cpython-36.pyc File 1.53 KB 0644
sysconfig.cpython-36.opt-1.pyc File 23.07 KB 0644
sysconfig.cpython-36.pyc File 23.07 KB 0644
udev.cpython-36.opt-1.pyc File 1.22 KB 0644
udev.cpython-36.pyc File 1.31 KB 0644