HEX
Server: nginx/1.24.0
System: Linux nowruzgan 6.8.0-57-generic #59-Ubuntu SMP PREEMPT_DYNAMIC Sat Mar 15 17:40:59 UTC 2025 x86_64
User: babak (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: //usr/share/netplan/netplan_cli/cli/__pycache__/state_diff.cpython-312.pyc
�

nG�f"q���ddlmZddlZddlZddlmZddlmZddlm	Z	m
Z
mZddlm
Z
mZGd�dej�ZGd	�d
�Zy)�)�defaultdictN)�AbstractSet)�NetplanRoute)�SystemConfigState�NetplanConfigState�DEVICE_TYPES)�is_valid_macaddress�route_table_lookupc��eZdZd�Zy)�DiffJSONEncoderc��t|t�r|j�Stjj||�S�N)�
isinstancer�to_dict�json�JSONEncoder�default)�self�objs  �0/usr/share/netplan/netplan_cli/cli/state_diff.pyrzDiffJSONEncoder.defaults3���c�<�(��;�;�=� ����'�'��c�2�2�N)�__name__�
__module__�__qualname__r�rrrrs��3rrc��eZdZdZdedefd�Zdefd�Zd*de	defd�Z
defd	�Zd
e	de	dedefd�Z
d
ededdfd�Zdedefd�Zdedefd�Zde	de	fd�Zd
ededdfd�Zd
ededdfd�Zd
ededdfd�Zd
ededdfd�Zdede	ddfd�Zd
ededdfd�Zdedefd�Zd eed!ee	d
edefd"�Zdefd#�Zdeddfd$�Zdefd%�Z d&edefd'�Z!d(e	defd)�Z"y)+�NetplanDiffStatez�
    DiffState is mainly responsible for getting both system's and Netplan's configuration
    state, compare them and provide a data-structure containing the differences it found.
    �system_state�
netplan_statec�.�||_||_i|_yr)rr�route_lookup_table_names)rrrs   r�__init__zNetplanDiffState.__init__+s��(���*���(*��%r�returnc��dii}|j�}|j�}tt|j	��t|j	��z�}|D]
}i|d|<�|j�D]\}}|d|j
|��|j�D]\}}|d|j
|��|S)z�
        Return the states of both the system and Netplan in a common representation
        that makes it easier to compare them.
        �
interfaces)�_get_system_interfaces�_get_netplan_interfaces�set�list�keys�items�update)r�
full_state�system_interfaces�netplan_interfaces�all_interfaces�	interface�configs       r�get_full_statezNetplanDiffState.get_full_state1s���
�"�
�
�!�7�7�9��!�9�9�;���T�"3�"8�"8�":�;�d�CU�CZ�CZ�C\�>]�]�^��'�	5�I�24�J�|�$�Y�/�	5�"3�!8�!8�!:�	?��I�v��|�$�Y�/�6�6�v�>�	?�"4�!9�!9�!;�	?��I�v��|�$�Y�/�6�6�v�>�	?��rr1c��|j�}|j|jdi��}|r|j|�x}r||i}ni}|j�}|j	||�|j�D]�\}}|jdi�jd�}|jdi�jd�}|j
|||�}|j||�|j||�|j||�|j||�|j||�|j||�|dj|���tt|dj�d����|d<|S)a�
        Compare the configuration of interfaces currently found in the system against Netplan configuration.
        A number of heuristics are used to eliminate configuration that is automatically set in the system,
        such as certain routes and IP addresses. That is necessary because this configuration will not be found
        in Netplan. For example, if Netplan is enabling DHCP on an interface and not defining any extra IP addresses,
        we don't count the IPs automatically assigned to the interface as a difference. We do though count the eventual
        absence of addresses that should be assigned by DHCP as a difference.
        r%r�id�indexc�*�|djd�S)N�r6)�get)�ifaces r�<lambda>z+NetplanDiffState.get_diff.<locals>.<lambda>qs��[`�ab�[c�[g�[g�ho�[p�r��key)r3�_get_comparable_interfacesr9�_create_new_report�_analyze_missing_interfacesr+�_create_new_iface�_analyze_ip_addresses�_analyze_nameservers�_analyze_search_domains�_analyze_mac_addresses�_analyze_routes�_analyze_parent_linksr,�dict�sorted)	rr1r-r%r2�report�	netdef_idr6r:s	         r�get_diffzNetplanDiffState.get_diffKsx���(�(�*�
��4�4�Z�^�^�L�RT�5U�V�
��#���	�2�2�v�2�'��0�
��
��(�(�*���(�(���;�!+�!1�!1�!3�	/��I�v��
�
�>�2�6�:�:�4�@�I��J�J�~�r�2�6�6�w�?�E��*�*�9�i��G�E��&�&�v�u�5��%�%�f�e�4��(�(���7��'�'���6�� � ���/��&�&�v�u�5��<� �'�'��.�	/� $�F�6�,�+?�+E�+E�+G�Mp�$q�r��|���
rc��iiid�S)N)r%�missing_interfaces_system�missing_interfaces_netplanr)rs rr?z#NetplanDiffState._create_new_reportts���)+�*,�
�	
rrKr6c��||||iid�iS)N)r6�namer5rrr)rrKr1r6s    rrAz"NetplanDiffState._create_new_iface{s#����!�� "�!#��
�	
rr2r:Nc�r�t|j��d}|jdi�jdg�D�chc]}|��}}|j|�}|jdi�jdd�}|jdi�jdd�}|jdi�jdg�}t	�}	|jdi�jdi�j�D�]\}
}t
j|
�}|jd	g�}d
|vrd|vr|	j|
�d|vr~|jrrt|jtj�rd|vr|	j|
�t|jtj�rd
|vr|	j|
�d
|vs��t|jtj�rd}t|jtj�s��d}��|j|	�}
|	j|�}|rd||dd<|rd||dd<|r+||djdtt!|��i�|
r,||djdtt!|
��i�yycc}w)Nrr�	addresses�dhcp4F�dhcp6�
link_localr�flags�dhcp�link�ipv4�ipv6T�missing_dhcp4_address�missing_dhcp6_address�missing_addresses)r)r*r9�_normalize_ip_addressesr(r+�	ipaddress�ip_interface�add�
is_link_localr�ip�IPv4Address�IPv6Address�
differencer,rI)rr2r:rQrd�netplan_ipsr\r]rV�
system_ips�addr�	addr_datarW�present_only_in_netplan�present_only_in_systems               rrBz&NetplanDiffState._analyze_ip_addresses�s~���E�J�J�L�!�!�$��$*�J�J���$C�$G�$G��UW�$X�Y�b�r�Y��Y��2�2�;�?�� &�
�
�?�B� ?� C� C�G�U� S�� &�
�
�?�B� ?� C� C�G�U� S���Z�Z���4�8�8��r�J�
��U�
�%�z�z�.�"�=�A�A�+�r�R�X�X�Z�	2�O�D�)��'�'��-�B��M�M�'�2�.�E��U�"�v�U�':����t�$�
���2�#3�#3��b�e�e�Y�%:�%:�;��j�@X��N�N�4�(��b�e�e�Y�%:�%:�;��j�@X��N�N�4�(�����b�e�e�Y�%:�%:�;�,1�)��b�e�e�Y�%:�%:�;�,1�)�/	2�2#.�"8�"8��"D��!+�!6�!6�{�!C�� �CG�E�$�K��'�(?�@� �CG�E�$�K��'�(?�@�!��$�K��(�/�/�#�T�&�1G�*H�%I�1�
�#��$�K��'�.�.�#�T�&�1H�*I�%J�0�
�#��]Zs�	J4r%c���i}|j�D]O\}}|jd��|jd���)|jdi�jd�s�K|||<�Q|S)a� In order to compare interfaces, they must exist in the system AND in Netplan.
            Here we filter out interfaces that don't have a system_state, a netplan_state
            or a netdef ID.

            There is a special case where the interface will have a system_state and a netdef_id
            but will be missing in Netplan. That will happen when the user removes the interface
            only from Netplan but doesn't run netplan apply.
        rrr5)r+r9)rr%�filteredr1r2s     rr>z+NetplanDiffState._get_comparable_interfaces�ss����!+�!1�!1�!3�	)��I�v��z�z�.�)�1�V�Z�Z��5P�5X���:�:�n�b�1�5�5�d�;��"(�H�Y��	)��rrSc�l�t�}|D]$}|j|�}|j|��&|S)zm Apply some transformations to IP addresses so their representation
        will match the system's.
        )r(�_compress_ipv6_addressrb)rrS�new_ips_setrds    rr_z(NetplanDiffState._normalize_ip_addresses�s>���e���	 �B��,�,�R�0�B��O�O�B��	 ��r�addressc��	tj|�}d|vr|jSt|j�S#t
$r|cYSwxYw)z�
        Compress IPv6 addresses to match the system representation
        Example: 1:2:0:0::123/64 -> 1:2::123/64
                 1:2:0:0::123 -> 1:2::123
        If "address" is not an IPv6Address, return the original value
        �/)r`ra�with_prefixlen�strrd�
ValueError)rrsrjs   rrqz'NetplanDiffState._compress_ipv6_address�sL��	��)�)�'�2�D��g�~��*�*�*��t�w�w�<����	��N�	�s�$<�<�A
�	A
c�6�t|j��d}t|jdi�jdg��}t|jdi�jdg��}|jdi�jdg�}|D�cgc]+}|jdk(s�|j
s� |j
��-}}|D�	chc]	}	|	|vs�|	��}}	|s�|jdi�jd�r<|D�	chc]1}	t
tj|	�tj�s|	��3}}	|jdi�jd�r<|D�	chc]1}	t
tj|	�tj�s|	��3}}	|j|�}
|j|�}|r"||djd	t|�i�|
r#||djd	t|
�i�yycc}wcc}	wcc}	wcc}	w)
Nrr�nameservers_addressesr�routes�rarTrU�missing_nameservers_addresses)
r)r*r(r9�protocol�viarr`�
ip_addressrerfrgr,)rr2r:rQ�netplan_nameservers�system_nameservers�
system_routes�r�	ra_routes�nsrlrms            rrCz%NetplanDiffState._analyze_nameservers�s
���E�J�J�L�!�!�$��"�&�*�*�_�b�"A�"E�"E�F]�_a�"b�c�� ����N�B�!?�!C�!C�D[�]_�!`�a���
�
�>�2�6�:�:�8�R�H�
�$1�R�q�Q�Z�Z�4�5G�A�E�E�Q�U�U�R�	�R�+=�U�R��9�AT�b�U��U�#��z�z�/�2�.�2�2�7�;�3E�&j�R�-7�	�8L�8L�R�8P�R[�Rg�Rg�-h�')�&j�"�&j��z�z�/�2�.�2�2�7�;�3E�&j�R�-7�	�8L�8L�R�8P�R[�Rg�Rg�-h�')�&j�"�&j�#6�"@�"@�AS�"T��!3�!>�!>�?R�!S��!��$�K��(�/�/�/��6L�1M�1�
�#��$�K��'�.�.�/��6M�1N�0�
�#��3S��U��&j��&js*�H�.H�;H�	H�H�6H�#6Hc�Z�t|j��d}t|jdi�jdg��}t|jdi�jdg��}|sL|jdi�jd�s!|jdi�jd�r
t�}|j	|�}|j	|�}|r"||djdt|�i�|r#||djdt|�i�yy)Nrr�nameservers_searchrrTrU�missing_nameservers_search)r)r*r(r9rgr,)rr2r:rQ�netplan_search_domains�system_search_domainsrlrms        rrDz(NetplanDiffState._analyze_search_domainss ���E�J�J�L�!�!�$��!$�V�Z�Z���%D�%H�%H�I]�_a�%b�!c�� #�F�J�J�~�r�$B�$F�$F�G[�]_�$`� a��&��z�z�/�2�.�2�2�7�;�v�z�z�/�[]�?^�?b�?b�cj�?k�(+��%�"8�"C�"C�DY�"Z��!6�!A�!A�BX�!Y��!��$�K��(�/�/�,�d�3I�.J�1�
�#��$�K��'�.�.�,�d�3J�.K�0�
�#rc�X�t|j��d}|jdi�jd�}|jdi�jd�}|rt|�sy|r<|r9||k7r3||dj	d|i�||dj	d|i�yyyy)Nrr�
macaddressr�missing_macaddress)r)r*r9r	r,)rr2r:rQ�system_macaddress�netplan_macaddresss      rrEz'NetplanDiffState._analyze_mac_addresses.s����E�J�J�L�!�!�$��"�J�J�~�r�:�>�>�|�L��#�Z�Z���<�@�@��N���&9�:L�&M���!3� �$6�6��d��N�+�2�2�(�*<�4���d��O�,�3�3�(�*;�5��	7�"4�rc���t|j��d}t|jdi�jdg��}t|jdi�jdg��}|j	|�}|jdi�jdi�D�cgc]}|��}}|j|||�}|j
|�}|j
|�}	|	r3||djdt|	d���D�
cgc]}
|
��c}
i�|r4||djdt|d	���D�
cgc]}
|
��c}
i�yycc}wcc}
wcc}
w)
Nrrr{rrS�missing_routesc��|jSr��to�r�s rr;z2NetplanDiffState._analyze_routes.<locals>.<lambda>Ps
��cd�cg�cg�rr<c��|jSrr�r�s rr;z2NetplanDiffState._analyze_routes.<locals>.<lambda>Us
��de�dh�dh�r)	r)r*r(r9�_normalize_routes�_filter_system_routesrgr,rI)rr2r:rQ�netplan_routesr�rd�system_addressesrlrm�routes           rrFz NetplanDiffState._analyze_routesAs[���E�J�J�L�!�!�$���V�Z�Z���<�@�@��2�N�O���F�J�J�~�r�:�>�>�x��L�M�
��/�/��?��*0���N�B�)G�)K�)K�K�Y[�)\�]�2�B�]��]��2�2�=�BR�TZ�[�
�"0�";�";�M�"J��!.�!9�!9�.�!I��!��$�K��(�/�/� �f�=S�Yg�6h�"i�U�5�"i�1�
�#��$�K��'�.�.� �f�=T�Zh�6i�"j�U�5�"j�0�
�#��^��#j��
#ks�(	E�	E
�	E
rJc�����jjD�chc]}|��}}�jjD�chc]}|js�|j��}}|j|�}t
t�fd�|��}g}�jjD],}|j|vs�|j|j��.t|�}t|�}�rt�fd�|�}t�fd�|�}�jj�}|D]O}�jjj|�j}	dtj|	d�i|d|<�Q|D]J}|j|�jdd�|j|�jd�d�|d	|<�Lycc}wcc}w)
Nc�h���jjj|�jdk7S)N�wifis)r�netdefsr9�type)�irs �rr;z>NetplanDiffState._analyze_missing_interfaces.<locals>.<lambda>_s*���T�-?�-?�-G�-G�-K�-K�A�-N�-S�-S�W^�-^�rc���|�k(Srr�r�r1s �rr;z>NetplanDiffState._analyze_missing_interfaces.<locals>.<lambda>js���A��N�rc���|�k(Srrr�s �rr;z>NetplanDiffState._analyze_missing_interfaces.<locals>.<lambda>ks���1�	�>�rr��otherrNr6)r�r6rO)rr�r�interface_listrKrgr)�filter�appendrQrI�get_datar9r�r)
rrJr1r:r/�system_interfaces_netdef_ids�netplan_only�system_onlyr�
iface_types
` `       rr@z,NetplanDiffState._analyze_missing_interfacesXs����15�1C�1C�1K�1K�L��e�L��L�EI�EV�EV�Ee�Ee�'y�E�in�ix�ix����'y�$�'y�)�4�4�5Q�R���F�#^�`l�m�n�����&�&�5�5�	/�E����&8�8��"�"�5�:�:�.�	/��l�+���[�)���!�":�L�I�L� �!9�;�G�K��(�(�1�1�3��!�	�E��+�+�3�3�7�7��>�C�C�J���(�(��W�=�:�F�.�/��6�	�!�	�E�$�(�(��/�3�3�F�G�D�%�)�)�%�0�4�4�W�=�;�F�/�0��7�	��9M��'ys�	G�G	�G	c�b�t|j��d}|jdi�jd�|jdi�jd�g}|jdi�jd�|jdi�jd�g}|jdi�jd�|jdi�jd�g}|jdi�jdg�|jdi�jdg�g}|ddgk7r1|d|d	k7r&|dr|d||dd
<|d	r|d	||dd
<|ddgk7r1|d|d	k7r&|dr|d||dd<|d	r|d	||dd<|ddgk7r1|d|d	k7r&|dr|d||dd<|d	r|d	||dd<|gggk7rZt|d�}t|d	�}	||	k7r8|	|z
x}
rt|
�||dd
<||	z
x}rt|�||dd
<yyyy)z�
        Analyse if interfaces such as bonds, bridges and VRFs are correctly attached to their
        members and vice versa.
        rr�bondr�bridge�vrfr%Nr8�missing_bond_link�missing_bridge_link�missing_vrf_link�missing_interfaces)r)r*r9r()rr2r:rQr�r�r�r%�system�netplan�missing_system�missing_netplans            rrGz&NetplanDiffState._analyze_parent_links{s���
�E�J�J�L�!�!�$���
�
�>�2�.�2�2�6�:�F�J�J��XZ�<[�<_�<_�`f�<g�h���*�*�^�R�0�4�4�X�>��
�
�?�\^�@_�@c�@c�dl�@m�n���z�z�.�"�-�1�1�%�8�&�*�*�_�VX�:Y�:]�:]�^c�:d�e���j�j���4�8�8��r�J�F�J�J�Wf�hj�Lk�Lo�Lo�p|�A�MB�C�
��D�$�<��D��G�t�A�w�$6��A�w�DH��G��d��O�,�-@�A��A�w�CG��7��d��N�+�,?�@��d�D�\�!�f�Q�i�6�!�9�&<��a�y�FL�Q�i��d��O�,�-B�C��a�y�EK�A�Y��d��N�+�,A�B��4��,��3�q�6�S��V�#3��1�v�CF�q�6��d��O�,�-?�@��1�v�BE�a�&��d��N�+�,>�?��"�b��!���A��'�F��*�Q�-�(�G��� �%,�v�%5�5�>�5�HL�^�H\�E�$�K��/�0D�E�&,�w�&6�6�?�6�IM�o�I^�E�$�K��0�1E�F�7�	!�	"rr{c��t�}|D]�}|jtjk(r|j	d�|_|j|j�|_|j|j�|_|j|j�|_|jdk7r5|jjd�}|ddk(s|ddk(r
|d|_|j|���|S)zo Apply some transformations to Netplan routes so their representation
        will match the system's.
        �mainrrur8�32�128r)r(�tabler�_TABLE_UNSPEC_�$_default_route_tables_name_to_numberrqr��	from_addrr�splitrb)rr{�new_routes_setr��	ip_prefixs     rr�z"NetplanDiffState._normalize_routes�s�������	&�E��{�{�l�9�9�9�"�G�G��O����2�2�5�8�8�<�E�H�"�9�9�%�/�/�J�E�O��3�3�E�I�I�>�E�I��x�x�9�$�!�H�H�N�N�3�/�	��Q�<�4�'�9�Q�<�5�+@�(��|�E�H����u�%�#	&�&�rr�r�c��|D�cgc]*}ttj|�j���,}}t	td�|��}|D�cgc]*}ttj|�j���,}}|jdi�jdg�}t�}|D�]�}	|	jdk(r9|	jdk7r*tj|	j�js�L|	jdk(s|	jdk(r�k|	jdk7rStj|	j�}
|
jr(|	jdk(rd	|vr��|	jd
k(rd|vr��|	jdk(rH|	jd
k(r9|	j|vs)tj|	j�jr��$|	jdk(r |	jdk(r|	jdk(r��S|	jdk(r|	j|vs|	j|vr���|j!|	����|Scc}wcc}w)a�
        Some routes found in the system are installed automatically/dynamically without
        being configured in Netplan.
        Here we implement some heuristics to remove these routes from the list we want
        to compare. We do that because these type of routes will probably never be found in the
        Netplan configuration so there is no point in comparing them against Netplan.
        c��|dk7S)Nz	fe80::/64r)�ns rr;z8NetplanDiffState._filter_system_routes.<locals>.<lambda>�s��q�K�/?�rrrVrYrrXr|�
r[�rZ�host�local�	multicastzff00::/8)rwr`ra�networkr)r�rdr9r(�scoper�rcr~�familyr��is_loopbackrb)rr�r�r2rd�local_networksrSrVr{r��route_tos           rr�z&NetplanDiffState._filter_system_routes�s���M]�]�b�#�i�4�4�R�8�@�@�A�]��]��f�%?��P�Q��BR�S�B�S��/�/��3�6�6�7�S�	�S��Z�Z���4�8�8��r�J�
����"� 	�E��{�{�f�$����Y�)>�y�G]�G]�^c�^f�^f�Gg�Gu�Gu���~�~��'�5�>�>�T�+A���x�x�9�$�$�1�1�%�(�(�;���)�)��|�|�r�)�f�
�.B� ��|�|�q�(�V�z�-A� ����v�%�%�*�*��*?��X�X��*�i�.D�.D�U�X�X�.N�.Z�.Z���|�|�r�!�e�j�j�K�&?�E�H�H�PZ�DZ���|�|�r�!�u�x�x�>�'A�U�X�X�QZ�EZ���J�J�u��A 	�B�
��O^��Ts�/I�/I
c��|jj�}i}|jjj	�D�]0\}}i}dd|ii||<||d}tj|jd�|d<|j|d<|j|d<|j|d<|jD�cgc]}|��}}|rWi|d<|D]M}i}	|jr|j|	d	<|jr|j|	d
<d|	i|dt|�<�Ot|j �x}
r|
|d<t|j"�x}r||d
<t|j$�x}r||d<|j&x}
r|
|d<|j(j
d�x}r|j*|d<|j(j
d�x}r|j*|d<|j(j
d�x}r|j*|d<||vrUd}|j	�D])\}}|j
d�x}s�||k(s� d}||||<�+|r��
|j-|��� |j-|���3|j/|�|Scc}w)Nrr5r�r�rTrUrVrS�label�lifetimerWrzr�r{r�r�r�r�FT)rr�rr�r+rr9r�rTrUrVrSr�r�rwr)�nameserver_addresses�nameserver_searchr{r��linksr5r,�_netplan_state_find_parents)rr.r%r1r2r:�	iface_refrjrSrW�nameservers�searchr{�macr�r�r��
found_somer=�valuerKs                     rr'z(NetplanDiffState._get_netplan_interfaces�s��� �-�-�6�6�8���
�!%�!3�!3�!;�!;�!A�!A�!C�A	)��I�v��E� /�$�	�1B�C�E�)���i�(��9�I� ,� 0� 0����g� F�I�f��!'���I�g��!'���I�g��&,�&7�&7�I�l�#�*0�*:�*:�;�$��;�I�;��)+�	�+�&�%�I�D��E��z�z�)-����g���}�}�,0�M�M��j�)�9@�%�8H�I�k�*�3�t�9�5�
I�#�6�#>�#>�?�?�{�?�5@�	�1�2��f�6�6�7�7�v�7�28�	�.�/��f�m�m�,�,�v�,�&,�	�(�#��'�'�'�s�'�*-�	�,�'����)�)�(�3�3�v�3�&,�i�i�	�(�#��|�|�'�'��/�/�t�/�$(�G�G�	�&�!��l�l�&�&�u�-�-�s�-�#&�6�6�	�%� �� 1�1�#�
�"3�"9�"9�";�?�J�C��$)�I�I�d�O�3�y�3�$�	�1�)-�J�.3�I�.>�J�s�O�	?�"��%�%�e�,��!�!�%�(�CA	)�F	
�(�(��4����o<s�9	Jc��tt�}|j�D]�\}}|djd�x}r||j	|�|djd�x}r||j	|�|djd�x}s�q||j	|���|j�D]\}}t|�||dd<�y)z* Associates interfaces with their parents rr�r�r�r%N)rr(r+r9rbr))rr%�parentsr1r2rY�memberss       rr�z,NetplanDiffState._netplan_state_find_parents8s����c�"��!+�!1�!1�!3�	-��I�v��o�.�2�2�8�<�<�t�<���
�!�!�)�,��o�.�2�2�6�:�:�t�:���
�!�!�)�,��o�.�2�2�5�9�9�t�9���
�!�!�)�,�
	-�#*�-�-�/�	Q��I�w�CG��=�J�y�!�/�2�<�@�	Qrc��i}|jj�j�D�]�\}}|dk(r�
|jd�}dd|ii||<|jd�x}r|||dd<||d}|jd�x}r||d<i}|jdg�D]k}	t	|	j��d}
|	j|
�jd�}|
�d	|��}d
|	j|
�jd
g�i||<�m|r||d<|jd�x}
r|
|d<|jd
�x}r||d<|jd�x}r"|D�cgc]}|j
|���c}|d<|jd�x}r||d<|jd�x}r||d<|jd�x}r||d<|jd�x}r||d<|jd�x}s���||d<���|Scc}w)Nznetplan-global-stater�rr5r6rSr�prefixrurW�
dns_addressesrz�
dns_searchr�r{r�r%r�r�r�)rr�r+r9r)r*�_system_route_to_netplan)rr%r1r2�device_typerKr�r6rSrjrdr��	full_addrr�r�r{r�r��uplink_interfacesr�r�r�s                      rr&z'NetplanDiffState._get_system_interfacesFsa���
�!%�!2�!2�!;�!;�!=�!C�!C�!E�/	'��I�v��2�2�� �*�*�V�,�K�%3�f�k�5J�$K�J�y�!�"�J�J�t�,�,�y�,�>G�
�9�%�n�5�d�;�"�9�-�n�=�I��
�
�7�+�+�u�+�%*�	�'�"��I��
�
�;��3�
P���$�)�)�+�&�q�)�����"��)�)�(�3��!�d�!�F�8�,�	�(/����"��1A�1A�'�2�1N�'O�	�)�$�
P��)2�	�+�&�$�j�j��9�9�{�9�5@�	�1�2����L�1�1�v�1�28�	�.�/����H�-�-�v�-�Y_�&`�PU�t�'D�'D�U�'K�&`�	�(�#��j�j��.�.�s�.�*-�	�,�'�$*�J�J�|�$<�<� �<�*;�	�,�'��z�z�&�)�)�t�)�$(�	�&�!����H�-�-�v�-�&,�	�(�#��j�j��'�'�s�'�#&�	�%� �_/	'�b���#'as� G=�system_routec���i}|jd�x}r||d<|jd�x}r||d<|jd�x}r||d<|jd�x}r||d<|jd�x}r||d<|jd�x}r||d<|jd�x}	r|	|d<|jd	�x}
r|
|d	<|jd
�x}r|j|�|d
<tdi|��S)Nr�r�r�fromr��metricr�r�r~r�r)r9r�r)rr�r�r�r�rr�r�r��
route_typer~r�s            rr�z)NetplanDiffState._system_route_to_netplan|s9����!�%�%�h�/�/�6�/�$�E�(�O��!�!�$�'�'�2�'��E�$�K��"�"�5�)�)�3�)��E�%�L�$�(�(��0�0�9�0�!*�E�+��!�%�%�h�/�/�6�/�$�E�(�O� �$�$�W�-�-�5�-�"�E�'�N�%�)�)�&�1�1�:�1�&�E�&�M�#�'�'�
�3�3�8�3� (�E�*�� �$�$�W�-�-�5�-�!�F�F�u�M�E�'�N��$�e�$�$rrQc��|j�rt|�S|jst�|_|jj	|d�S)Nr)�isdigit�intr!r
r9)rrQs  rr�z5NetplanDiffState._default_route_tables_name_to_number�sB���<�<�>��t�9���,�,�,>�,@�D�)��,�,�0�0��q�9�9r)�)#rrr�__doc__rrr"rHr3rwrLr?r�rArBr>r(r_rqrCrDrErFr@rGr�rrr)r�r'r�r&r�r�rrrrr%s����
+�%6�+�GY�+����4'�#�'�t�'�R
�D�
�	
�3�	
�3�	
�s�	
�t�	
�3�D�3��3�$�3�j�T��d��,	��	��	�
�c�
�c�
�)�4�)��)��)�V�d��4��D��0�T��$��4��&�d��4��D��.!�$�!�3�!�4�!�F&_�D�&_��&_�$�&_�P�����40�;�|�3L�0�`d�eh�`i�0�sw�0�|�0�dG��G�RQ�d�Q�t�Q�4��4�l%�T�%�l�%�0:��:��:rr)�collectionsrr`r�typingr�netplan.netdefr�netplan_cli.cli.staterrr�netplan_cli.cli.utilsr	r
rrrrrr�<module>r�s=��$$����'�U�U�I�3�d�&�&�3�v	:�v	:r