HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /proc/1991108/root/lib/python3/dist-packages/cloudinit/net/__pycache__/
Upload File :
Current File : //proc/1991108/root/lib/python3/dist-packages/cloudinit/net/__pycache__/ephemeral.cpython-311.pyc
�

܍~c�9����dZddlZddlZddlmZmZmZddlmZddl	m
Z
ddlmZm
Z
mZeje��ZGd�d��ZGd�d	��ZGd
�d��ZGd�d
��ZdS)z.Module for ephemeral network context managers
�N)�Any�Dict�List)�subp)�NoDHCPLeaseError�maybe_perform_dhcp_discovery�parse_static_routesc�Z�eZdZdZ			ddeeeffd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�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�x�t||||g��s%td�||||�����	tj|��|_n5#t$r(}td�|����|�d}~wwxYw||_||_||_||_	||_
||_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�net�ipv4_mask_to_net_prefix�prefixr�	interface�ip�	broadcast�router�
static_routes�cleanup_cmds)	�selfrr�prefix_or_maskrrrr�es	         �9/usr/lib/python3/dist-packages/cloudinit/net/ephemeral.py�__init__zEphemeralIPv4Network.__init__s���,�I�r�>�9�=�>�>�	��G�N�N��r�>�9�����
�
	��5�n�E�E�D�K�K���	�	�	���%�v�a�y�y����
�����	����&;��"�"������"������*���')����s�A�
B�#B�Bc�2�|jrAtj|j��r(t�d|jd��dS|���|jr|���dS|jr|�	��dSdS)z>Perform ephemeral network setup if interface is not connected.z=Skip ephemeral network setup, instance has connectivity to %s�urlN)
rr�has_url_connectivity�LOG�debug�_bringup_devicer�_bringup_static_routesr�_bringup_router�rs r�	__enter__zEphemeralIPv4Network.__enter__Ls����%�	��'��(B�C�C�
��	�	���.�u�5����
����������	#��'�'�)�)�)�)�)�
�[�	#�� � �"�"�"�"�"�	#�	#�c�F�|jD]}tj|d����dS)zTeardown anything we set up.T��captureN)rr)r�	excp_type�
excp_value�excp_traceback�cmds     r�__exit__zEphemeralIPv4Network.__exit__is6���$�	)�	)�C��I�c�4�(�(�(�(�(�	)�	)r)c
�V�tjddddd|�d|��d|jgd�	��d
S)z7Perform the ip command to remove the specified address.r�-family�inet�addr�del�/�devTr+N)rr)r�addressrs   r�_delete_addressz$EphemeralIPv4Network._delete_addressnsT���	������"�7�7�F�F�+����	
��	
�	
�	
�	
�	
�	
r)c��d�|j|j��}t�d|j||j��	tjddddd|d|jd	|jg
d
ddi�
��tjdddddd	|jdgd
���|j�	dddddd	|jdg��|j�	ddddd|d	|jg��dS#tj
$rH}dt|j��vr�t�d|j|j��Yd}~dSd}~wwxYw)z1Perform the ip comands to fully setup the device.z{0}/{1}z:Attempting setup of ephemeral network on %s with %s brd %srr3r4r5�addrr8T�LANG�C)r,�
update_env�link�set�upr+�downr6zFile existsz7Skip ephemeral network setup, %s already has address %sN)
rrrr"r#rrrr�append�ProcessExecutionError�str�stderr)r�cidrrs   rr$z$EphemeralIPv4Network._bringup_device~s����������5�5���	�	�H��N���N�		
�	
�	
�?	��I���������N���N���"�C�=�
�
�
�
�4
�I��������N��	��
�
�
�
�
��$�$��������N��	�
�
�
�
��$�$���������N�	�
�
�
�
�
��G�)�	�	�	��C���M�M�1�1���I�I�I�����
�
�
�
�
�
�
�
�
�����	���s�	-C)�)E�8=D;�;Ec	���|jD]f\}}g}|dkrd|g}tjdddd|g|zd|jgzd�	��|j�d
dddd|g|zd|jgz���gdS)Nz0.0.0.0�viar�-4�routerDr8Tr+rr6)rrrr�insert)r�net_address�gateway�via_args    rr%z+EphemeralIPv4Network._bringup_static_routes�s���%)�$6�	�	� �K���G��)�#�#� �'�*���I��t�W�h��<����$�.�)�*��	
�
�
�
�
��$�$���t�W�e�[�9����$�.�)�*�
�
�
�
�	�	r)c��tjgd�d���\}}d|vr5t�d|j|�����dStjddd	d
|jd|jd|jg	d���|j�d
ddd	d|jd|jd|jg	��tjddd	d
dd|jd|jg	d���|j�d
ddd	ddd|jg��dS)z<Perform the ip commands to fully setup the router if needed.)rrL�showz	0.0.0.0/0Tr+�defaultz<Skip ephemeral route setup. %s already has default route: %sNrrKrLr<r8�srcrr6rJ)	rr"r#r�striprrrrM)r�out�_s   rr&z$EphemeralIPv4Network._bringup_router�si����?�?�?��N�N�N���Q������I�I�N����	�	���
�
�
�

�F��	�������������

��
	
�
	
�
	
�
	
�	
�� � �
�������������

�
	
�
	
�
	
�	
�	������������

��
	
�
	
�
	
�
	
�	
�� � �
��d�G�U�I�u�d�n�M�	
�	
�	
�	
�	
r))NNN)�__name__�
__module__�__qualname__�__doc__rrFrrr(r1r:r$r%r&�r)rrrs��������� �04��+*�+*� $�C��H�~�+*�+*�+*�+*�Z#�#�#�:)�)�)�

�
�
� H�H�H�T���(7
�7
�7
�7
�7
r)rc�$�eZdZdZd�Zd�Zd�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.
    c�\�|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)rrr)rrs  rrzEphemeralIPv6Network.__init__s5���	M��9�@�@��K�K�L�L�L�"����r)c��tj|jd��dkr#tjdddd|jdgd���d	Sd	S)
z�linux kernel does autoconfiguration even when autoconf=0

        https://www.kernel.org/doc/html/latest/networking/ipv6.html
        �	operstaterBrr@rAr8Fr+N)r�read_sys_netrrr's rr(zEphemeralIPv6Network.__enter__)s_��
��D�N�K�8�8�D�@�@��I��v�u�e�T�^�T�B��
�
�
�
�
�
�A�@r)c��dS)z%No need to set the link to down stateNr\�r�_argss  rr1zEphemeralIPv6Network.__exit__4s���r)N)rXrYrZr[rr(r1r\r)rr^r^sK��������
#�
#�
#�	�	�	�4�4�4�4�4r)r^c�X�eZdZ				d
deeeffd�Zd�Zd�Zd�Z	d�Z
d�Zd	�ZdS)�EphemeralDHCPv4Nrc�Z�||_d|_d|_||_||_||_dS�N)�iface�_ephipv4�lease�
dhcp_log_funcr�tmp_dir)rrjrrmrns     rrzEphemeralDHCPv4.__init__9s4����
���
���
�*���%:��"�����r)c��|jr;tj|j��r"t�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rr!r"r#�obtain_leaser's rr(zEphemeralDHCPv4.__enter__Gs_���%�	��'��(B�C�C�
��	�	���.����
��� � �"�"�"r)c�.�|���dS)z Teardown sandboxed dhcp context.N)�
clean_network)rr-r.r/s    rr1zEphemeralDHCPv4.__exit__Ts���������r)c�l�|jrd|_|jsdS|j�ddd��dS)z@Exit _ephipv4 context to teardown of ip configuration performed.N)rlrkr1r's rrrzEphemeralDHCPv4.clean_networkXsB���:�	��D�J��}�	��F��
���t�T�4�0�0�0�0�0r)c�j�|jr|jSt|j|j|j��}|st���|d|_t�d|jd|jd|jd��ddddddgd	d
�}|�|��}|ds$tj
|d|d
��|d<|drt|d��|d<|jr
|j|d<tdi|��}|���||_|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-routes�routers)rrrrrrrrrrrr\)rlrrjrmrnrr"r#�extract_dhcp_options_mappingr�mask_and_ipv4_to_bcast_addrr	rrr(rk)r�leases�nmap�kwargs�ephipv4s     rrpzEphemeralDHCPv4.obtain_lease`sx���:�	��:��-��J��*�D�L�
�
���	%�"�$�$�$��B�Z��
��	�	�1��J�{�#��J��'��J�}�%�		
�	
�	
�%�!�+�,�1�)�� �

�

���2�2�4�8�8���k�"�	�"%�"A��'�(�&��,�#�#�F�;���/�"�	�&9���'�'�'�F�?�#��%�	I�.2�.H�F�*�+�&�0�0��0�0����������
��z�r)c���i}|���D]O\}}t|t��r|�|||���2|j�|��||<�P|Sri)�items�
isinstance�list�get_first_option_valuerl�get)rrz�result�internal_reference�lease_option_namess     rrwz,EphemeralDHCPv4.extract_dhcp_options_mapping�s�����6:�j�j�l�l�	P�	P�2�� 2��,�d�3�3�
P��+�+�&�(:�F�����.2�Z�^�^�<N�-O�-O��)�*�*��
r)c�t�|D]4}|�|��s|j�|��||<�5dSri)r�rl)r�internal_mappingr�r��different_namess     rr�z&EphemeralDHCPv4.get_first_option_value�sQ�� 2�	K�	K�O��:�:�.�/�/�
K�+/�:�>�>�/�+J�+J��'�(��	K�	Kr))NNNN)
rXrYrZrrFrrr(r1rrrprwr�r\r)rrgrg8s��������04����� $�C��H�~�����#�#�#����1�1�1�0�0�0�d	�	�	�K�K�K�K�Kr)rgc�6�eZdZdZ			d
dedefd�Zd�Zd	�ZdS)�EphemeralIPNetworkz9Marries together IPv4 and IPv6 ephemeral context managersFTN�ipv6�ipv4c�|�||_||_||_tj��|_d|_||_dS)N�)rr�r��
contextlib�	ExitStack�stack�	state_msgrn)rrr�r�rns     rrzEphemeralIPNetwork.__init__�s;��#�����	���	��)�+�+��
� �������r)c�4�	|jr3|j�t|j|j�����|jr,|j�t|j����n(#t$r}|jrd|_	n|�Yd}~nd}~wwxYw|S)N)rnzusing link-local ipv6)
r�r��
enter_contextrgrrnr�r^rr�)rrs  rr(zEphemeralIPNetwork.__enter__�s���
	��y�
��
�(�(�#�D�N�D�L�I�I�I�����y�
O��
�(�(�)=�d�n�)M�)M�N�N�N��� �	�	�	��y�
�!8���������������	����
�s�A-A0�0
B�:B�Bc�8�|j���dSri)r��closerds  rr1zEphemeralIPNetwork.__exit__�s���
�������r))FTN)rXrYrZr[�boolrr(r1r\r)rr�r��sp������C�C�
��������	�������&����r)r�)r[r��logging�typingrrr�
cloudinit.netr�	cloudinitr�cloudinit.net.dhcprrr	�	getLoggerrXr"rr^rgr�r\r)r�<module>r�sq������������"�"�"�"�"�"�"�"�"�"������������������������g���!�!��
�
�
�
�
�
�
�
�D4�4�4�4�4�4�4�4�DjK�jK�jK�jK�jK�jK�jK�jK�Z%�%�%�%�%�%�%�%�%�%r)