%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/cloudinit/net/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/cloudinit/net/__pycache__/dhcp.cpython-312.pyc

�

\�`f�����ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZddl
mZddlmZmZmZmZmZmZddlZddlmZmZmZddlmZmZej<e�Z dZ!d	Z"d
Z#dZ$Gd�d
e%�Z&Gd�de&�Z'Gd�de&�Z(Gd�de&�Z)d d�Z*d�Z+d!d�Z,d!d�Z-Gd�dej\�Z/Gd�de/�Z0Gd�de/�Z1Gd�de/�Z2e1e0e2gZ3y)"�N)�suppress)�StringIO)�TimeoutExpired)�Any�Callable�Dict�List�Optional�Tuple)�subp�
temp_utils�util)�get_interface_mac�is_ib_interfacez/run/systemd/netif/leasesz/var/lib/dhclientz.+\.leases?$aN#!/bin/sh
log() {
    echo "udhcpc[$PPID]" "$interface: $2"
}
[ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1
case $1 in
    bound|renew)
    cat <<JSON > "$LEASE_FILE"
{
    "interface": "$interface",
    "fixed-address": "$ip",
    "subnet-mask": "$subnet",
    "routers": "${router%% *}",
    "static_routes" : "${staticroutes}"
}
JSON
    ;;
    deconfig)
    log err "Not supported"
    exit 1
    ;;
    leasefail | nak)
    log err "configuration failed: $1: $message"
    exit 1
    ;;
    *)
    echo "$0: Unknown udhcpc command: $1" >&2
    exit 1
    ;;
esac
c��eZdZdZy)�NoDHCPLeaseErrorz'Raised when unable to get a DHCP lease.N��__name__�
__module__�__qualname__�__doc__���4/usr/lib/python3/dist-packages/cloudinit/net/dhcp.pyrrAs��1rrc��eZdZdZy)�InvalidDHCPLeaseFileErrorz�Raised when parsing an empty or invalid dhclient.lease file.

    Current uses are DataSourceAzure and DataSourceEc2 during ephemeral
    boot to scrape metadata.
    NrrrrrrEs��rrc��eZdZdZy)�NoDHCPLeaseInterfaceErrorz7Raised when unable to find a viable interface for DHCP.NrrrrrrMs��Arrc��eZdZdZy)�NoDHCPLeaseMissingDhclientErrorz$Raised when unable to find dhclient.Nrrrrr r Qs��.rr c��|xs|j}|�tjd�t��|jj|||�S)aPerform 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.
    @return: A list of dicts representing dhcp options for each lease obtained
        from the dhclient discovery if run, otherwise an empty list is
        returned.
    z1Skip dhcp_discovery: Unable to find fallback nic.)�fallback_interface�LOG�debugr�dhcp_client�dhcp_discovery)�distro�nic�
dhcp_log_func�	interfaces    r�maybe_perform_dhcp_discoveryr+UsK���0�v�0�0�I����	�	�E�F�'�)�)����,�,�Y�
�v�N�Nrc�T�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)�dict�	configobj�	ConfigObjr)�contents r�networkd_parse_leaser2js!���	�#�#�H�W�$5�5�I�J�Jrc	��|�t}i}tjj|�s|Stj|�D]A}tt
jtjj||���||<�C|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_DIR�os�path�isdir�listdirr2r�load_text_file�join)�leases_d�ret�lfiles   r�networkd_load_leasesr>uss����&��
�C�
�7�7�=�=��"��
����H�%�
��)���������X�u� =�>�
��E�
�
��Jrc��|�t}t|��}t|j��D]\}}|j	|�s�||cSy)N)r;)r4r>�sorted�items�get)�keynamer;�leases�_ifindex�datas     r�networkd_get_option_from_leasesrG�sP����&��
!�8�
4�F� �����0�!���$��8�8�G����=� �!�rc
�.�eZdZdZdZd�Zed��Zed��Zede	fd��Z
ede	fd��Zejd	e	d
ee	effd��Zeejde	d
eee	e	ffd
���Zej		dd	e	deed
ee	effd��Zy)�
DhcpClient��
c�x�tj|j�|_|js
t	��y�N)r�which�client_name�dhcp_client_pathr )�selfs r�__init__zDhcpClient.__init__�s0�� $�
�
�4�+;�+;� <����$�$�1�3�3�%rc�N�tjd|jgddg��y)N�pkillr���rcs)rrO)�clss r�kill_dhcp_clientzDhcpClient.kill_dhcp_client�s���	�	�7�C�O�O�,�1�a�&�9rc��|j�tjd�}|D]}tj|��y)Nz/var/lib/dhcp/*)rY�globr5�remove)rX�files�files   r�clear_leaseszDhcpClient.clear_leases�s7�������	�	�+�,���	�D��I�I�d�O�	r�dhcp_interfacec�F�|jd|j|ddg��y)N�startrrUrV��manage_servicerO�rXr`r's   r�
start_servicezDhcpClient.start_service�s&������S�_�_�n�1�a�&�	�	
rc�D�|jd|jddg��y)N�stoprrUrVrcres   r�stop_servicezDhcpClient.stop_service�s�����f�c�o�o�A�q�6��Brr*�returnc��iS)z�Get the most recent lease from the ephemeral phase as a dict.

        Return a dict of dhcp options. The dict contains key value
        pairs from the most recent lease.
        r�rQr*s  r�get_newest_leasezDhcpClient.get_newest_lease�s	���	r�routesc��gS)ap
        parse classless static routes from string

        The tuple is composed of the network_address (including net length) and
        gateway for a parsed static route.

        @param routes: string containing classless static routes
        @returns: list of tuple(str, str) for all valid parsed routes until the
                  first parsing error.
        r)rns r�parse_static_routeszDhcpClient.parse_static_routes�s	���	rNr)c��iS)a�Run dhcp client on the interface without scripts or filesystem
        artifacts.

        @param interface: Name of the network interface on which to send a
            dhcp request
        @param dhcp_log_func: A callable accepting the client output and
            error streams.
        @param distro: a distro object for network interface manipulation
        @return: dict of lease options representing the most recent dhcp lease
            parsed from the dhclient.lease file
        r)rQr*r)r's    rr&zDhcpClient.dhcp_discovery�s	��$�	r�NN)rrrrO�timeoutrR�classmethodrYr_�strrfri�abc�abstractmethodrrrm�staticmethodr	rrpr
rr&rrrrIrI�s*���K��G�4�
�:��:������
�3�
��
�
�C�#�C��C�	����#��$�s�C�x�.���������C��D��s�C�x��,A�����	���-1��	��� ��)��

�c�3�h����rrIc	����eZdZdZ�fd�Zededeeee	ffd��Z
ed��Zdedeee	ffd�Z		dded	e
edeee	ffd
�Zededeeeeffd��Zede
efd
��Zdefd�Z�xZS)�IscDhclient�dhclientc�0��t�|��d|_y)Nz/run/dhclient.lease��superrR�
lease_file�rQ�	__class__s �rrRzIscDhclient.__init__�s���
����/��r�
lease_contentrjc��tjdtj�}g}t|�dk(rgS|j	|�D]�}g}|jd�D]V}|j
�jdd�jdd�}|s�6|j|jdd���Xt|�}|jd	�}|rtj|�|d	<|j|���|S)
z�parse the content of a lease file

        @param lease_content: a string containing the contents of an
            isc-dhclient lease
        @return: a list of leases, most recent last
        zlease {(?P<lease>.*?)}\nr�;�"rJzoption � rU�unknown-245)
�re�compile�DOTALL�len�findall�split�strip�replace�appendr.rBrz�get_ip_from_lease_value)r��lease_regex�dhcp_leases�lease�
lease_options�line�options�opt_245s        r�parse_leaseszIscDhclient.parse_leases�s����j�j�!<�b�i�i�H��"$���}���"��I� �(�(��7�
	(�E��M����C�(�
=���z�z�|�+�+�C��4�<�<�Y��K���!�(�(����C��);�<�	
=�
�=�)�G��k�k�-�0�G��)4�)L�)L��*��
�&�
���w�'�
	(��rc	�P�|jdd�}t|�dkDrad}|jd�D]}t|�dk(rd|z}||z
}�tjdt|jdd�d��}n|j
d	�}tj|�S)
N�\rJ��:rU�0z>L�zutf-8)	r�r�r��struct�pack�int�encode�socket�	inet_ntoa)�fallback_lease_value�unescaped_value�
hex_string�hex_pair�packed_bytess     rr�z#IscDhclient.get_ip_from_lease_values���.�6�6�t�R�@�����!�#��J�+�1�1�#�6�
'���x�=�A�%�"�X�~�H��h�&�
�
'�"�;�;��c�*�,�,�S�"�5�r�:��L�+�1�1�'�:�L�����-�-rr*c���tt�5tj|j�}|r!|j|�}|r|dcddd�Sddd�iS#1swYiSxYw)a�Get the most recent lease from the ephemeral phase as a dict.

        Return a dict of dhcp options. The dict contains key value
        pairs from the most recent lease.

        @param interface: an interface string - not used in this class, but
            required for function signature compatibility with other classes
            that require a distro object
        @raises: InvalidDHCPLeaseFileError on empty or unparsable leasefile
            content.
        ���N)r�FileNotFoundErrorrr9rr�)rQr*r1r�s    rrmzIscDhclient.get_newest_leasesf���'�
(�	+��)�)�$�/�/�:�G��"�/�/��8���&�r�?�	+�	+�	+��	�
	+��	�s�9A�A'r)c	��tjd|�d}d}d}t|j|z�}t|jdz�}t	t
�5t
j|�t
j|j�ddd�|jj|�t|�ridt|�ddz}	d|�d	|	�d
�}
tjd��}tjj!||d
z�}t#j$||
�	t'j&|j)|j*|j|||��\}}
t#j6||jg|d��}|r.tj9ddj!d�|D���iSd}d}d}d}t;|�D]�}	t#j<|�j?�}t|�}|jA|�}|dk(r>tjd|�t
jB|tDjF�d}n,tKjL|���tj|�|stjOd||d�|�	|||
�|jQ|�}|r|StS��#1swY��6xYw#t&j,$rB}tjd|j.|j0|j2�t4|�d}~wwxYw#t
$r	d|�d�}Y��tH$r	d|�d�}Y��wxYw)a�Run dhclient on the interface without scripts/filesystem artifacts.

        @param interface: Name of the network interface on which to send a
            dhcp request
        @param dhcp_log_func: A callable accepting the dhclient output and
            error streams.
        @param distro: a distro object for network interface manipulation
        @return: dict of lease options representing the most recent dhcp lease
            parsed from the dhclient.lease file
        �!Performing a dhcp discovery on %sz/run/dhclient.pidN�{�G�z�?�z20:%s�$zinterface "z" {send dhcp-client-identifier z;}T��	needs_exez-dhclient.confz3dhclient exited with code: %s stderr: %r stdout: %r)�maxwait�naplenz+dhclient did not produce expected files: %sz, c3�ZK�|]#}tjj|����%y�wrM)r5r6�basename)�.0�fs  r�	<genexpr>z-IscDhclient.dhcp_discovery.<locals>.<genexpr>{s����?�!�"�'�'�*�*�1�-�?�s�)+�unknownFrJrUzkilling dhclient with pid=%s�No PID file found at z, dhclient is still running�PID file contained [z], dhclient is still runningzCdhclient(pid=%s, parentpid=%s) failed to daemonize after %s secondsg$@)*r#r$r�rsrr�r5r\r�net_ops�link_uprrr
�get_tmp_ancestorr6r:r�
write_filer�build_dhclient_cmdrP�ProcessExecutionError�	exit_code�stderr�stdoutr�wait_for_files�warning�ranger9r��
get_proc_ppid�kill�signal�SIGKILL�
ValueError�time�sleep�errorrmr)rQr*r)r'�pid_file�config_file�
sleep_time�sleep_cyclesr��dhcp_client_identifier�interface_dhclient_content�tmp_dir�out�errr��missing�ppid�
daemonized�pid_content�	debug_msg�_�pidr�s                       rr&zIscDhclient.dhcp_discovery$s"�� 	�	�	�5�y�A�
'�����
��4�<�<�*�4�5���d�l�l�Q�&�'���'�
(�	'��I�I�h���I�I�d�o�o�&�	'�	�����y�)�
�9�%��+�I�6�r�s�;�;�
#��4�6�
'�
!�1�1�D�A�G��'�'�,�,�w�	�<L�0L�M�K��O�O�K�)C�D�	.��y�y��)�)��)�)��O�O������H�C��2�%�%�
�t���'���
����K�K�=��	�	�?�w�?�?�
��I����
����	��|�$�	!�A�
�"�1�1�(�;�A�A�C���+�&���+�+�C�0���1�9��I�I�<�c�B��G�G�C����0�!%�J���J�J�z�"�+	!�.
�I�I�i� ���I�I�����
��$��#�s�#��%�%�i�0����L�'�)�)�Q	'�	'��H�)�)�	.��I�I�E����������	
�#��-��	.��D%�
�+�H�:�60�0���
�*�;�-�80�0��
�s<�5K�)?K�.L*�K�L'�%=L"�"L'�*M�;M�Mrnc
���|jd��tjd��D�cgc]}|s�|��	}}g}�fd�}d}t|�D�]�\}}||kr�
t	|�}|tdd�vrhd}t
||d�|kr|||t
||d��|cSd	j||d
z|dz�}	d	j||dz||z�}
||z}�n�|tdd�vrld
}t
||d�|kr|||t
||d��|cSd	j||d
z|dzdgz�}	d	j||dz||z�}
||z}�nb|tdd�vrld}t
||d�|kr|||t
||d��|cSd	j||d
z|dzddgz�}	d	j||dz||z�}
||z}n�|td
d�vrld}t
||d�|kr|||t
||d��|cSd	j||d
z|dzgd�z�}	d	j||dz||z�}
||z}nn|dk(rOd}t
||d�|kr|||t
||d��|cSd}	d	j||d
z||z�}
||z}ntjd|�|cS|j|	�d|��|
f����|Scc}w)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�z[, .]c�L��d|�d|�d|�d���}tj|�y)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: )r#r�)�cidr�required�remain�msg�rfc3442s    �r�_trunc_errorz5IscDhclient.parse_static_routes.<locals>._trunc_error�s%���
��6�7�4�
�
�I�I�c�Nrr��!�	N�.rU���r�r����r�)r�r�r�z0.0.0.0zSParsed invalid net length "%s".  Verify DHCP rfc3442-classless-static-routes value.�/)�rstripr�r��	enumerater�r�r�r:r#r�r�)rn�tok�tokens�
static_routesr��current_idx�idx�
net_length�req_toks�net_address�gatewayr�s           @rrpzIscDhclient.parse_static_routes�sR���B�-�-��$��!#���(�G�!<�D�#��#�D��D�/1�
�	���!�&�)�8	�H�C���[� ���S��J��U�2�r�]�*����v�c�d�|�$�x�/� ��X�s�6�#�$�<�7H�I�(�(�!�h�h�v�c�A�g��a��'@�A���(�(�6�#��'�C�(�N�#C�D��!�H�n���u�R��}�,����v�c�d�|�$�x�/� ��X�s�6�#�$�<�7H�I�(�(�!�h�h�v�c�A�g��a��'@�C�5�'H�I���(�(�6�#��'�C�(�N�#C�D��!�H�n���u�Q��|�+����v�c�d�|�$�x�/� ��X�s�6�#�$�<�7H�I�(�(�!�h�h�v�c�A�g��a��'@�C��:�'M�N���(�(�6�#��'�C�(�N�#C�D��!�H�n���u�Q��{�*����v�c�d�|�$�x�/� ��X�s�6�#�$�<�7H�I�(�(�!�h�h��3��7�S�1�W�-��?����(�(�6�#��'�C�(�N�#C�D��!�H�n���q�����v�c�d�|�$�x�/� ��X�s�6�#�$�<�7H�I�(�(�'���(�(�6�#��'�C�(�N�#C�D��!�H�n���	�	�=���
%�$�� � �'��4�g�>�
�m8	�t���OEs
�K�Kc��d}|j|jfttffD]�\}}|s�	g}	t	j
|�}d}|D]b}tj||�s�tjj||�}tjj|�}||kDs�_|}|}�d|s��|cSy#t$rY��wxYw)z�Get the latest lease file from a distro-managed dhclient

        Doesn't consider the ephemeral timeframe lease.

        @param distro: used for distro-specific lease location and filename
        @return: The most recent lease file, or None
        Ng�)�dhclient_lease_directory�dhclient_lease_file_regex�DHCLIENT_FALLBACK_LEASE_DIR�DHCLIENT_FALLBACK_LEASE_REGEXr5r8r�r��searchr6r:�getmtime)	r'�latest_file�	directory�regex�lease_files�latest_mtime�fname�abs_path�mtimes	         r�!get_newest_lease_file_from_distroz-IscDhclient.get_newest_lease_file_from_distros�����
�/�/��0�0�
�)�*G�H�!
�	#��I�u����K�
� �j�j��3�� �L�$�
+���y�y���.���7�7�<�<�	�5�9�����(�(��2���<�'�#(�L�"*�K�
+��"�"�;	#�<��#%�
��
�s�B:�:	C�C�keyc���|j|�}|rOtj|�}|r7t|j	|��D]}|j|�}|s�|cSyyy)a8Get a key from the latest lease from distro-managed dhclient

        Doesn't consider the ephemeral timeframe lease.

        @param lease_dir: distro-specific lease to check
        @param lease_file_regex: distro-specific regex to match lease name
        @return: The most recent lease file, or None
        N)rrr9�reversedr�rB)rQr'rrr1r��servers       r�get_key_from_latest_leasez%IscDhclient.get_key_from_latest_leaseBsh���;�;�F�C�
���)�)�*�5�G��%�d�&7�&7��&@�A�&�E�"�Y�Y�s�^�F��%�
�&��rrr)rrrrOrRrxrur	rrr�r�rmr
rr&rrprr�
__classcell__�r�s@rrzrz�s����K�0���C��D��c�3�h��,@����6�
.��
.��#��$�s�C�x�.��.-1��	E*��E*� ��)�E*�

�c�3�h��E*�N�h�C�h�D��s�C�x��,A�h��h�T�)�X�c�]�)��)�V&�S�&rrzc	���eZdZdZdZ		ddedeedeee	ffd�Z
eded	e
deefd
��Zedededefd��Zdedeee	ffd
�Zededeeeeffd��Zy)�Dhcpcd�dhcpcdi,Nr*r)rjc�B�tjd|�d}t|j|z�}g}|jj|�	t
|�rdg}|jdddddg|�|�}tj||j�	�\}}	|�	|||	�|j|�}
|
r�tjg|�d��jj�}d
}d}
d
}t|�D]�}	tj|�j�}t|�}|j|�}
|
r>tjd||
�t!j"|
t$j&�|
S	|
cStj|�|
St3d��#t($rtjd|
�Y|
St*$r	d|�d�}Ynt,$r	d|�d�}YnwxYwt/j0|���	#t4$rB}tjd|j|j6|j�t2|�d
}~wtj8$rB}tjd|j:|j6|j�t2|�d
}~wwxYw)a�Run dhcpcd on the interface without scripts/filesystem artifacts.

        @param interface: Name of the network interface on which to send a
            dhcp request
        @param dhcp_log_func: A callable accepting the client output and
            error streams.
        @param distro: a distro object for network interface manipulation
        @return: dict of lease options representing the most recent dhcp lease
            parsed from the dhclient.lease file
        r�r�z
--clientid�
--ipv4onlyz--waitipz--persistentz--noarpz--script=/bin/true)rsNz-PFrJz!killing dhcpcd with pid=%s gid=%sz9Process group id [%s] has already exited, nothing to killr�z, dhcpcd is still runningr�z], dhcpcd is still runningzNo lease foundz8dhcpcd timed out after %s seconds: stderr: %r stdout: %r�1dhcpcd exited with code: %s stderr: %r stdout: %r)r#r$r�rsr�r�rrPrrmr�r�r�rr9�
get_proc_pgidr5�killpgr�r��ProcessLookupErrorr�r�r�r�rrr�r�r�)rQr*r)r'r�r��infiniband_argument�commandr�r�r�r�r��gidr�r�r�r�s                  rr&zDhcpcd.dhcp_discoveryYs��� 	�	�	�5�y�A��
��4�<�<�*�4�5�� ��	�����y�)�[	.��y�)�'3�n�#��%�%�����$�
	�%�	��	�G��y�y������H�C���(��c�3�'��)�)�)�4�E�� �9�9�%5�w�%5��%5�6�=�=�C�C�E��"�����	��|�,� )�A�%�&*�&9�&9�(�&C�&I�&I�&K��!�+�.��$�2�2�3�7����I�I� C�S�#���I�I�c�6�>�>�:�!�.��9�0 %��; )�@�I�I�i�(���"�#3�4�4��/.���	�	�.���
� ��-��3�H�:�>6�6�"�&��2�;�-�@6�6�"����J�J�z�*���	.��I�I�J��
�
�������	
�#��-���)�)�	.��I�I�C����������	
�#��-��	.�st�B+H�;A<F"�7H�;H�?H�H�"G&�H�G&�H�G&�#H�%G&�&H�	J�	=I�J�=J�JrF�dhcp_option_numberc�\�d}dtdtfd�}|||�D]\}}||k(s�|cSy)aVget a specific option from a binary lease file

        This is required until upstream dhcpcd supports unknown option 245
        upstream bug: https://github.com/NetworkConfiguration/dhcpcd/issues/282

        @param data: Binary lease data
        @param number: Option number to return
        @return: the option (bytes) or None
        ��rF�indexc3�K�t|�|dzk\r<||}|d|z}|d|zd|z|z}||f��d|z|z}t|�|dzk\r�;yy�w)z�options are variable length, and consist of the following format

            option number: 1 byte
            option length: 1 byte
            option data: variable length (see length field)
            r�rUN)r�)rFr'�code�length�options     r�iter_optionsz>Dhcpcd.parse_unknown_options_from_packet.<locals>.iter_options�sq�����d�)�u�q�y�(��E�{���a�%�i����a�%�i�!�e�)�f�*<�=���F�l�"��F�
�U�*���d�)�u�q�y�(�s�AA�AN)�bytesr�)rFr$�INDEXr,r)r+s      r�!parse_unknown_options_from_packetz(Dhcpcd.parse_unknown_options_from_packet�sK��.��	+�u�	+�S�	+�)��u�5�	�L�D�&��)�)��
�	�r�
lease_dumpc	��tjd||�	t|j�j	dd�jd�D�cgc]}d|vr|jdd����c}�}|s&d}tj
||�t||z��	||d<|j�D��cic]\}}|j	dd
�|��}}}ddd�}|j�D]\}	}
|	|vs�|j|	�||
<� tjd|�d��}tj|d�}|rtj |�|d<|Scc}w#t$r"}tj
d	|�t|�d
}~wwxYwcc}}w)a`parse the output of dhcpcd --dump

        map names to the datastructure we create from dhclient

        example dhcpcd output:

        broadcast_address='192.168.15.255'
        dhcp_lease_time='3600'
        dhcp_message_type='5'
        dhcp_server_identifier='192.168.0.1'
        domain_name='us-east-2.compute.internal'
        domain_name_servers='192.168.0.2'
        host_name='ip-192-168-0-212'
        interface_mtu='9001'
        ip_address='192.168.0.212'
        network_number='192.168.0.0'
        routers='192.168.0.1'
        subnet_cidr='20'
        subnet_mask='255.255.240.0'
        z)Parsing dhcpcd lease for interface %s: %r�'rJ�
�=rU)�maxsplitz;No valid DHCP lease configuration found in dhcpcd lease: %rzError parsing dhcpcd lease: %rNr*r��-z
fixed-addressr�)z
ip-addresszclassless-static-routesz/var/lib/dhcpcd/z.lease�r�)r#r$r.r�r�r�r�rr�rA�popr�load_binary_filerr/r�r�)
r0r*�ar�r�r�r�value�name_map�source�destination�dhcp_messager�s
             r�parse_dhcpcd_leasezDhcpcd.parse_dhcpcd_lease�s���,	�	�	�7��J�	
�
	7��(�-�-�/�7�7��R�@�F�F�t�L����a�x��G�G�C�!�G�,���E��0���	�	�#�z�*�/��j�0@�A�A�
�'��k��AF���
�N�*�#�u����S�#�&��-�N��N�*�'6�
��$,�>�>�#3�	7��F�K����%*�Y�Y�v�%6��k�"�	7��,�,��y�k��0�
���:�:�<��M���#)�#3�#3�G�#<�E�-� ����U���	7��I�I�6�
�C�+��6��	7��Os/�6E�E�-/E�5F	�E�	F�$F�Fc�.�	|jtj|jdd|g�j|�S#tj$rB}t
j
d|j|j|j�t|�d}~wwxYw)z�Return a dict of dhcp options.

        @param interface: which interface to dump the lease from
        @raises: InvalidDHCPLeaseFileError on empty or unparsable leasefile
            content.
        z--dumpleaserrN)
r@rrPr�r�r#r$r�r�r)rQr*r�s   rrmzDhcpcd.get_newest_leaseEs���	.��*�*��	�	��-�-�%�$�!�	���&��
�

���)�)�	.��I�I�C����������	
�#��-��	.�s�<?�B�=B�Brnc��|j�}|r&t|ddd�|ddd��D�cgc]}|��c}Stjd|�gScc}w)a�
        classless static routes as returned from dhcpcd --dumplease 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.

        @param routes: string containing classless static routes
        @returns: list of tuple(str, str) for all valid parsed routes until the
                  first parsing error.

        e.g.:

        sr=parse_static_routes(
            "0.0.0.0/0 10.0.0.1 168.63.129.16/32 10.0.0.1"
        )
        sr=[
            ("0.0.0.0/0", "10.0.0.1"),
            ("169.63.129.16/32", "10.0.0.1"),
        ]
        Nr�rUz'Malformed classless static routes: [%s])r��zipr#r��rnr��is   rrpzDhcpcd.parse_static_routesbsX��.����
��"�=��1��#5�}�Q�T��T�7J�K�L�!�A�L�L����=�v�F��	��Ms�	Arr)rrrrOrsrur
rrrr&rxr-r�r/r@rmr	rrprrrrrUs����K��G�
-1��	u.��u.� ��)�u.�

�c�3�h��u.�n�)��)�),�)�	�%��)��)�V�F�s�F�s�F�t�F��F�P.�#�.�$�s�C�x�.�.�:��C��D��s�C�x��,A���rrc	���eZdZdZ�fd�Z		d
dedeedeee	ffd�Z
dedeee	ffd�Zedede
eeeffd	��Z�xZS)�Udhcpc�udhcpcc�0��t�|��d|_yrMr}r�s �rrRzUdhcpc.__init__�s���
������rr*r)rjc���tjd|�tjd��}tj
j
||dz�|_tt�5t	j|j�ddd�|jj|�tj
j
|d�}tj|td�|j dd	d
|d|dd
ddg}t#|�r>|j%ddj't)|�ddj+dd��g�	t-j,|d|jid��\}}|�	|||�|j9|�S#1swY��xYw#t,j.$rB}	tjd|	j0|	j2|	j4�t6|	�d}	~	wwxYw)arRun udhcpc on the interface without scripts or filesystem artifacts.

        @param interface: Name of the network interface on which to run udhcpc.
        @param dhcp_log_func: A callable accepting the udhcpc output and
            error streams.
        @return: A list of dicts of representing the dhcp leases parsed from
            the udhcpc lease file.
        r�Tr�z.lease.jsonN�
udhcpc_scripti�z-O�staticroutesz-iz-sz-nz-qz-fz-vz-xz	0x3d:20{}r�r�rJ�
LEASE_FILE)�
update_env�capturez1udhcpc exited with code: %s stderr: %r stdout: %r)r#r$r
r�r5r6r:rrr�r\r�r�rr��
UDHCPC_SCRIPTrPr�extend�formatrr�rr�r�r�r�rrm)
rQr*r)r'r�rK�cmdr�r�r�s
          rr&zUdhcpc.dhcp_discovery�s���	�	�	�5�y�A��-�-��=���'�'�,�,�w�	�M�0I�J���
�'�
(�	'��I�I�d�o�o�&�	'�	�����y�)������W�o�>�
����
�}�e�<�
�!�!�����������
��$�9�%��J�J���&�&�)�)�4�R�S�9�A�A�#�r�J���
�	.��y�y���t��� ?���H�C���$��#�s�#��$�$�Y�/�/�i	'�	'��P�)�)�	.��I�I�C����������	
�#��-��	.�s$�$ F�'F�F�G(�&=G#�#G(c�f�tjtj|j��S)a�Get the most recent lease from the ephemeral phase as a dict.

        Return a dict of dhcp options. The dict contains key value
        pairs from the most recent lease.

        @param interface: an interface name - not used in this class, but
            required for function signature compatibility with other classes
            that require a distro object
        @raises: InvalidDHCPLeaseFileError on empty or unparsable leasefile
            content.
        )r�	load_jsonr9rrls  rrmzUdhcpc.get_newest_lease�s"���~�~�d�1�1�$�/�/�B�C�Crrnc��|j�}|r&t|ddd�|ddd��D�cgc]}|��c}SgScc}w)Nr�rU)r�rCrDs   rrpzUdhcpc.parse_static_routes�sG������
��"�=��1��#5�}�Q�T��T�7J�K�L�!�A�L�L��	��Ms�	;rr)rrrrOrRrur
rrrr&rmrxr	rrprrs@rrGrG�s�����K��-1��	F0��F0� ��)�F0�

�c�3�h��F0�PD�#�D�$�s�C�x�.�D���C��D��s�C�x��,A���rrGrrrM)4rvr[�loggingr5r�r�r�r�r��
contextlibr�ior�
subprocessr�typingrrrr	r
rr/�	cloudinitrr
r�
cloudinit.netrr�	getLoggerrr#r4rrrP�	Exceptionrrrr r+r2r>rG�ABCrIrzrrG�ALL_DHCP_CLIENTSrrr�<module>rbs�����	�	�
�
�
����%�=�=��,�,�<��g����!��1��1�� /���
�B2�y�2�� 0��B� 0�B�/�&6�/�O�*K��&�H����H�Vu&�*�u&�pi�Z�i�X	c�Z�c�L�K��0�r

Zerion Mini Shell 1.0