HOME


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

܍~cp.��0�ddlZddlZddlZddlZddlZddlZddlmZddlZddl	m
Z
mZddlm
Z
mZeje��ZdZGd�de��ZGd�d	e��ZGd
�de��ZGd�d
e��Zdd�Zd�Zdd�Zd�Zdd�Zdd�Zd�ZdS)�N)�StringIO)�subp�util)�find_fallback_nic�get_devicelistz/run/systemd/netif/leasesc��eZdZdZdS)�NoDHCPLeaseErrorz'Raised when unable to get a DHCP lease.N��__name__�
__module__�__qualname__�__doc__���4/usr/lib/python3/dist-packages/cloudinit/net/dhcp.pyr	r	s������1�1�1�1rr	c��eZdZdZdS)�InvalidDHCPLeaseFileErrorz�Raised when parsing an empty or invalid dhclient.lease file.

    Current uses are DataSourceAzure and DataSourceEc2 during ephemeral
    boot to scrape metadata.
    Nr
rrrrrs���������rrc��eZdZdZdS)�NoDHCPLeaseInterfaceErrorz7Raised when unable to find a viable interface for DHCP.Nr
rrrrr%s������A�A�A�Arrc��eZdZdZdS)�NoDHCPLeaseMissingDhclientErrorz$Raised when unable to find dhclient.Nr
rrrrr)s������.�.�.�.rrc��|�9t��}|�(t�d��t���n9|t	��vr)t�d|��t���tjd��}|s(t�d��t���t|||��S)aJPerform dhcp discovery if nic valid and dhclient command exists.

    If the nic is invalid or undiscoverable or dhclient command is not found,
    skip dhcp_discovery and return an empty dict.

    @param nic: Name of the network interface we want to run dhclient on.
    @param dhcp_log_func: A callable accepting the dhclient output and error
        streams.
    @param tmp_dir: Tmp dir with exec permissions.
    @return: A list of dicts representing dhcp options for each lease obtained
        from the dhclient discovery if run, otherwise an empty list is
        returned.
    Nz1Skip dhcp_discovery: Unable to find fallback nic.z8Skip dhcp_discovery: nic %s not found in get_devicelist.�dhclientz7Skip dhclient configuration: No dhclient command found.)	r�LOG�debugrrr�whichr�dhcp_discovery)�nic�
dhcp_log_func�tmp_dir�
dhclient_paths    r�maybe_perform_dhcp_discoveryr"-s����{��!�!���;��I�I�I�J�J�J�+�-�-�-��

�N�$�$�	$�	$��	�	�F��	
�	
�	
�(�)�)�)��J�z�*�*�M��0��	�	�K�L�L�L�-�/�/�/��-��m�<�<�<rc��tjdtj��}g}tj|��}t|��dkr"t
d�|�����|�|��D]�}g}|�	d��D]j}|�
���dd���dd��}|s�A|�|�	dd	�����k|�t|������|s"t
d
�|�����|S)aParse the given dhcp lease file for the most recent lease.

    Return a list of dicts of dhcp options. Each dict contains key value pairs
    a specific lease in order from oldest to newest.

    @raises: InvalidDHCPLeaseFileError on empty of unparseable leasefile
        content.
    zlease {(?P<lease>.*?)}\nrz&Cannot parse empty dhcp lease file {0}�;�"�zoption � �z1Cannot parse dhcp lease file {0}. No leases found)�re�compile�DOTALLr�	load_file�lenr�format�findall�split�strip�replace�append�dict)�
lease_file�lease_regex�dhcp_leases�
lease_content�lease�
lease_options�lines       r�parse_dhcp_lease_filer<LsU���*�8�"�)�D�D�K��K��N�:�.�.�M�
�=���Q���'�4�;�;�J�G�G�
�
�	
��$�$�]�3�3�0�0���
��K�K��$�$�	5�	5�D��:�:�<�<�'�'��R�0�0�8�8��B�G�G�D��
��� � ����C��!3�!3�4�4�4�4����4�
�.�.�/�/�/�/��
�'�?�F�F��
�
�
�
�	
�
�rc
�*�t�d|��d}d}tjt��5tj|��tj|��ddd��n#1swxYwYtjdddd|d	gd
���|dd
d|d||ddg
}tj|d
���\}}tj	||gdd���}|r:t�
dd�d�|D������gSd}	d}
tdd��D]�}tj
|�����}	t|��}
tj|
��}	|	dkr>t�d|
��tj|
t$j��d
}
n&n#t($rYnwxYwt+jd����|
st�d||	d��|�|||��t1|��S) a�Run dhclient on the interface without scripts or filesystem artifacts.

    @param dhclient_cmd_path: Full path to the dhclient used.
    @param interface: Name of the network interface on which to dhclient.
    @param dhcp_log_func: A callable accepting the dhclient output and error
        streams.

    @return: A list of dicts of representing the dhcp leases parsed from the
        dhclient.lease file or empty list.
    z!Performing a dhcp discovery on %sz/run/dhclient.pidz/run/dhclient.leaseN�ip�link�set�dev�upT)�capturez-1z-vz-lfz-pfz-sfz	/bin/true�g{�G�z�?)�maxwait�naplenz+dhclient did not produce expected files: %sz, c3�TK�|]#}tj�|��V��$dS�N)�os�path�basename)�.0�fs  r�	<genexpr>z!dhcp_discovery.<locals>.<genexpr>�s2����;�;�a�b�g�&�&�q�)�)�;�;�;�;�;�;r�unknownFri�r(zkilling dhclient with pid=%szCdhclient(pid=%s, parentpid=%s) failed to daemonize after %s secondsg$@)rr�
contextlib�suppress�FileNotFoundErrorrI�removerr�wait_for_files�warning�join�ranger,r1�int�
get_proc_ppid�kill�signal�SIGKILL�
ValueError�time�sleep�errorr<)�dhclient_cmd_path�	interfacer�pid_filer5�cmd�out�err�missing�ppid�
daemonized�_�pid_content�pids              rrrns����I�I�1�9�=�=�=�
#�H�&�J�
�	�.�	/�	/���
�	�(����
�	�*����������������������	�I�t�V�U�E�9�d�;�T�J�J�J�J����
��
���
���C��y��d�+�+�+�H�C���!�	�:���$����G������9��I�I�;�;�7�;�;�;�;�;�	
�	
�	
��	��D��J�
�1�d�^�^�
�
���n�X�.�.�4�4�6�6��
	��k�"�"�C��%�c�*�*�D��q�y�y��	�	�8�#�>�>�>����V�^�,�,�,�!�
���	��	�	�	�	��D�	����	
�
�4������
��	�	�
����	
�	
�	
�� ��
�c�3���� ��,�,�,s#�)A.�.A2�5A2�F4�4
G�Gc�b�ttjt|��d�����S)z�Parse a systemd lease file content as in /run/systemd/netif/leases/

    Parse this (almost) ini style file even though it says:
      # This is private data. Do not parse.

    Simply return a dictionary of key/values.F)�list_values)r4�	configobj�	ConfigObjr)�contents r�networkd_parse_leaserr�s*���	�#�H�W�$5�$5�5�I�I�I�J�J�Jrc	��|�t}i}tj�|��s|Stj|��D]D}tt
jtj�||������||<�E|S)z�Return a dictionary of dictionaries representing each lease
    found in lease_d.i

    The top level key will be the filename, which is typically the ifindex.)	�NETWORKD_LEASES_DIRrIrJ�isdir�listdirrrrr,rV)�leases_d�ret�lfiles   r�networkd_load_leasesrz�s�����&��
�C�
�7�=�=��"�"���
���H�%�%�
�
��)��N�2�7�<�<��%�8�8�9�9�
�
��E�
�
��Jrc���|�t}t|���}t|�����D]$\}}|�|��r
||cS�%dS)N)rw)rtrz�sorted�items�get)�keynamerw�leases�_ifindex�datas     r�networkd_get_option_from_leasesr��sn����&��
!�8�
4�
4�
4�F� ������0�0�!�!���$��8�8�G���	!���=� � � �	!��4rc
�d����d���d�tjd���D��}g}�fd�}d}t|��D�]`\}}||kr�
t	|��}|tdd��vr�d}t
||d	���|kr&|||t
||d	�����|cSd
�||dz|dz���}	d
�||dz||z���}
||z}�n�|td
d��vr�d}t
||d	���|kr&|||t
||d	�����|cSd
�||dz|dz�dgz��}	d
�||dz||z���}
||z}�n�|tdd
��vr�d}t
||d	���|kr&|||t
||d	�����|cSd
�||dz|dz�ddgz��}	d
�||dz||z���}
||z}�n9|tdd��vr�d}t
||d	���|kr&|||t
||d	�����|cSd
�||dz|dz�gd�z��}	d
�||dz||z���}
||z}n�|dkrnd}t
||d	���|kr&|||t
||d	�����|cSd}	d
�||dz||z���}
||z}nt�	d|��|cS|�
|	�d|��|
f����b|S)a�parse rfc3442 format and return a list containing tuple of strings.

    The tuple is composed of the network_address (including net length) and
    gateway for a parsed static route.  It can parse two formats of rfc3442,
    one from dhcpcd and one from dhclient (isc).

    @param rfc3442: string in rfc3442 format (isc or dhcpd)
    @returns: list of tuple(str, str) for all valid parsed routes until the
              first parsing error.

    E.g.
    sr=parse_static_routes("32,169,254,169,254,130,56,248,255,0,130,56,240,1")
    sr=[
        ("169.254.169.254/32", "130.56.248.255"), ("0.0.0.0/0", "130.56.240.1")
    ]

    sr2 = parse_static_routes("24.191.168.128 192.168.128.1,0 192.168.128.1")
    sr2 = [
        ("191.168.128.0/24", "192.168.128.1"), ("0.0.0.0/0", "192.168.128.1")
    ]

    Python version of isc-dhclient's hooks:
       /etc/dhcp/dhclient-exit-hooks.d/rfc3442-classless-routes
    r$c��g|]}|�|��Srr)rL�toks  r�
<listcomp>z'parse_static_routes.<locals>.<listcomp>s��
@�
@�
@�c�C�
@�c�
@�
@�
@rz[, .]c�X��d|�d|�d|�d���}t�|��dS)Nz5RFC3442 string malformed.  Current route has CIDR of z and requires z significant octets, but only z< remain. Verify DHCP rfc3442-classless-static-routes value: )rr`)�cidr�required�remain�msg�rfc3442s    �r�_trunc_errorz)parse_static_routes.<locals>._trunc_errors=����
�t�t�X�X�X�v�v�v�w�w�
0�	�	�	�	�#�����rr��!�	N�.r(rD����0����)r�r�r�z0.0.0.0zSParsed invalid net length "%s".  Verify DHCP rfc3442-classless-static-routes value.�/)�rstripr)r0�	enumeraterXrWr-rVrr`r3)r��tokens�
static_routesr��current_idx�idxr��
net_length�req_toks�net_address�gateways`          r�parse_static_routesr��s^���4�n�n�S�!�!�G�
@�
@�R�X�h��8�8�
@�
@�
@�F��M�������K��f�%�%�4M�4M���S��������X�X�
���r�2���&�&��H��6�#�$�$�<� � �8�+�+���Z��3�v�c�d�d�|�3D�3D�E�E�E�$�$�$�$��(�(�6�#��'�C�!�G�*;�#<�=�=�K��h�h�v�c�A�g��h��&>�?�@�@�G���.�K�K�
�5��R�=�=�
(�
(��H��6�#�$�$�<� � �8�+�+���Z��3�v�c�d�d�|�3D�3D�E�E�E�$�$�$�$��(�(�6�#��'�C�!�G�*;�#<��u�#D�E�E�K��h�h�v�c�A�g��h��&>�?�@�@�G���.�K�K�
�5��B�<�<�
'�
'��H��6�#�$�$�<� � �8�+�+���Z��3�v�c�d�d�|�3D�3D�E�E�E�$�$�$�$��(�(�6�#��'�C�!�G�*;�#<��S�z�#I�J�J�K��h�h�v�c�A�g��h��&>�?�@�@�G���.�K�K�
�5��A�;�;�
&�
&��H��6�#�$�$�<� � �8�+�+���Z��3�v�c�d�d�|�3D�3D�E�E�E�$�$�$�$��(�(�6�#��'�C�!�G�*;�#<����#N�O�O�K��h�h�v�c�A�g��h��&>�?�@�@�G���.�K�K�
�1�_�_��H��6�#�$�$�<� � �8�+�+���Z��3�v�c�d�d�|�3D�3D�E�E�E�$�$�$�$�#�K��h�h�v�c�A�g��h��&>�?�@�@�G���.�K�K��I�I�9��
�
�
�
!� � � �������j�j�A�7�K�L�L�L�L��r)NNNrH)rP�loggingrIr)r[r^�iorro�	cloudinitrr�
cloudinit.netrr�	getLoggerrrrt�	Exceptionr	rrrr"r<rrrrzr�r�rrr�<module>r�s�����������	�	�	�	�	�	�	�	�
�
�
�
��������������� � � � � � � � �;�;�;�;�;�;�;�;��g���!�!��1��2�2�2�2�2�y�2�2�2������ 0����B�B�B�B�B� 0�B�B�B�/�/�/�/�/�&6�/�/�/�=�=�=�=�>���DX-�X-�X-�X-�vK�K�K�����&����^�^�^�^�^r