%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__/network_state.cpython-312.pyc

�

�f����UddlZddlZddlZddlmZmZmZmZddlm	Z	m
Z
ddlmZm
Z
mZmZmZmZmZmZmZerddlmZej.e�ZdZdgd�iZgd�Zd	d
ddd
ddddddddddd�dddddddddd dd!�d"�Zeeeeeffed#<d$e d%dfd&�Z!d'�Z"Gd(�d)e#�Z$d*�Z%Gd+�d,�Z&Gd-�d.�Z'd/�Z(d6d0�Z)d1�Z*d2�Z+		d7d3e d4e,d%e&fd5�Z-y)8�N)�
TYPE_CHECKING�Any�Dict�Optional)�safeyaml�util)	�find_interface_name_from_mac�get_interfaces_by_mac�ipv4_mask_to_net_prefix�ipv6_mask_to_net_prefix�
is_ip_network�is_ipv4_network�is_ipv6_address�is_ipv6_network�net_prefix_to_ipv4_mask��Renderer���version�config�
network_state)�	addresses�dhcp4�dhcp4-overrides�dhcp6�dhcp6-overrides�gateway4�gateway6�
interfaces�match�mtu�nameservers�renderer�set-name�	wakeonlan�	accept-raz	ad-selectzarp-intervalz
arp-ip-targetzarp-validatez
down-delayzfail-over-mac-policyz	lacp-ratezmii-monitor-intervalz	min-links�mode�gratuitous-arp�primaryzprimary-reselect-policyzup-delayztransmit-hash-policy)zbond-ad-selectzbond-arp-intervalzbond-arp-ip-targetzbond-arp-validatezbond-downdelayzbond-fail-over-maczbond-lacp-ratezbond-miimonzbond-min-linksz	bond-modezbond-num-grat-arpzbond-primaryzbond-primary-reselectzbond-updelayzbond-xmit-hash-policyzageing-time�priorityz
forward-delayz
hello-timezmax-agez	path-costz
port-priority�stp)�
bridge_ageing�bridge_bridgeprio�	bridge_fd�bridge_gcint�bridge_hello�
bridge_maxage�bridge_maxwait�bridge_pathcost�bridge_portprio�
bridge_stp�bridge_waitport)�bond�bridge�NET_CONFIG_TO_V2�dikt�returnc�F�d|vsd|vrtjddd��yy)z8Warn about deprecations of v2 properties for all devicesrrz$The use of `gateway4` and `gateway6`z22.4zhFor more info check out: https://cloudinit.readthedocs.io/en/latest/topics/network-config-format-v2.html)�
deprecated�deprecated_version�
extra_messageN)r�	deprecate)r;s �=/usr/lib/python3/dist-packages/cloudinit/net/network_state.py�warn_deprecated_all_devicesrCVs.���T��Z�4�/����=�%�^�	
�0�c�L�t|�}|D]}|j|��|S�N)�set�discard)�expected�actual�missing�keys    rB�	diff_keysrMas+���(�m�G�����������NrDc��eZdZy)�InvalidCommandN)�__name__�
__module__�__qualname__�rDrBrOrOhs��rDrOc����fd�}|S)Nc�F���tj����fd��}|S)Nc�`���rt�|�}|rtd|�d������||g|��i|��S)NzCommand missing z of required keys )rMrO)�self�command�args�kwargs�missing_keys�func�
required_keyss     ��rB�	decoratorz7ensure_command_keys.<locals>.wrapper.<locals>.decoratornsE����(���@���(�'��8�����g�7��7��7�7rD)�	functools�wraps)r\r^r]s` �rB�wrapperz$ensure_command_keys.<locals>.wrapperms&���	����	�	8�
�	8��rDrS)r]ras` rB�ensure_command_keysrbls�����NrDc��eZdZefdedefd�Zedefd��Zed��Z	ed��Z
ed��Zed	��Zdd�Z
dd�Zd
�Zd�Zededdfd��Zy
)�NetworkStaterrc��tj|�|_||_|j	dd�|_d|_y)N�use_ipv6F)�copy�deepcopy�_network_state�_version�getrf�_has_default_route)rWrrs   rB�__init__zNetworkState.__init__s8��#�m�m�M�:�����
�%�)�)�*�e�<��
�"&��rDr<c� �|jdS)Nr)ri�rWs rBrzNetworkState.config�s���"�"�8�,�,rDc��|jSrF)rjros rBrzNetworkState.version�s���}�}�rDc�J�	|jddS#t$rgcYSwxYw)N�dnsr#�ri�KeyErrorros rB�dns_nameserverszNetworkState.dns_nameservers�s1��	��&�&�u�-�m�<�<���	��I�	����"�"c�J�	|jddS#t$rgcYSwxYw)Nrr�searchrsros rB�dns_searchdomainszNetworkState.dns_searchdomains�s1��	��&�&�u�-�h�7�7���	��I�	�rvc�\�|j�|j�|_|jSrF)rl�_maybe_has_default_routeros rB�has_default_routezNetworkState.has_default_route�s+���"�"�*�&*�&C�&C�&E�D�#��&�&�&rDNc#�K�|jjdi�}|j�D]}|�|���
||�s�|���y�w)Nr )rirk�values)rW�filter_func�ifaces�ifaces    rB�iter_interfaceszNetworkState.iter_interfaces�sK�����$�$�(�(��r�:���]�]�_�	 �E��"����u�%��K�	 �s�?A	�A	c#�vK�|jjdg�D]}|�||�s�|���|���y�w�N�routes�rirk)rWr�routes   rB�iter_routeszNetworkState.iter_routes�s@�����(�(�,�,�X�r�:�	�E��&��u�%��K���	�s�*9�9c��|j�D]}|j|�s�y|j�D]E}|jdg�D].}|jdg�D]}|j|�s�y�0�Gy)NT�subnetsr�F)r��_is_default_router�rk)rWr�r��subnets    rBr{z%NetworkState._maybe_has_default_route�s����%�%�'�	�E��%�%�e�,��	��)�)�+�	$�E��)�)�I�r�2�
$��#�Z�Z��"�5�$�E��-�-�e�4�#�$�
$�	$�
rDc�X�d}|jd�dk(xr|jd�|vS)N)z::z0.0.0.0�prefixr�network)rk)rWr��default_netss   rBr�zNetworkState._is_default_route�s0��(���I�I�h��1�$�M����9�)=��)M�	
rDc�4�i}d|vr|d|d<|d|ifi|��S)z�Instantiates a `NetworkState` without interpreting its data.

        That means only `config` and `version` are copied.

        :param network_state: Network state data.
        :return: Instance of `NetworkState`.
        rrrS)�clsrrZs   rB�to_passthroughzNetworkState.to_passthrough�s5�����
�%� -�i� 8�F�9���H�m�,�7��7�7rDrF)rPrQrR�NETWORK_STATE_VERSION�dict�intrm�propertyrrruryr|r�r�r{r��classmethodr�rSrDrBrdrd~s���2G�'�!�'�,/�'��-��-��-��������������'��'�
 ��	�
��8�4�8�N�8��8rDrdc��eZdZigggd�ddd�Zeddf	d)d�Zedefd��Zed��Z	e	jd	��Z	d
�Zd�Zd�Z
d
�Zd*d�Zd*d�Zd*d�Zedg�d��Zedg�d��Zegd��d��Zegd��d��Zeddg�d��Zedg�d��Zd�Zedg�d��Zedg�d��Zedg�d ��Zd!�Zd"�Zd#�Zd$�Z d%�Z!d+d&�Z"d,d'�Z#d(�Z$y)-�NetworkStateInterpreter�r#rxFN)r r�rrrfrc���||_||_tj|j�|_||j
d<d|_i|_||_|j|j|j|j|j|j|j|j |j"|j$|j&|j(|j*d�
|_y)NrF)
r8�bondsr9�bridges�	ethernets�
infiniband�loopback�
nameserver�physicalr��vlan�vlans�wifis)rj�_configrgrh�initial_network_stateri�_parsed�_interface_dns_map�	_renderer�handle_bond�handle_bonds�
handle_bridge�handle_bridges�handle_ethernets�handle_infiniband�handle_loopback�handle_nameserver�handle_physical�handle_route�handle_vlan�handle_vlans�handle_wifis�command_handlers)rWrrr$s    rBrmz NetworkStateInterpreter.__init__�s��� ��
����"�m�m�D�,F�,F�G���(.����H�%����(*���!����$�$��&�&��(�(��*�*��.�.��0�0��,�,��0�0��,�,��&�&��$�$��&�&��&�&�!
��rDr<c��ddlm}|jdk(rJt|j|�r4t
j
d�tj|j�St|j|j��S)Nrr�zPassthrough netplan v2 config�r)�cloudinit.net.netplanrrj�
isinstancer��LOG�debugrdr�r�ri)rW�NetplanRenderers  rBrz%NetworkStateInterpreter.network_state�sW��E��=�=�A��*�T�^�^�_�"M��I�I�5�6��.�.�t�|�|�<�<��D�/�/����G�GrDc�8�|jjd�S�Nrfr�ros rBrfz NetworkStateInterpreter.use_ipv6s���"�"�&�&�z�2�2rDc�>�|jjd|i�yr�)ri�update)rW�vals  rBrfz NetworkStateInterpreter.use_ipv6
s�����"�"�J��#4�5rDc�t�|j|j|jd�}tj|�S)Nr)rjr�rir�dumps)rW�states  rB�dumpzNetworkStateInterpreter.dumps1���}�}��l�l�!�0�0�
��
�~�~�e�$�$rDc�(�d|vr tjd�td��t|d}t	||�}|r%d|z}tj|�t|��|D�cgc]	}|dvs�|��c}D]}t||||��ycc}w)Nrz$Invalid state, missing version fieldzInvalid state, missing keys: %sr�)r��error�
ValueError�NETWORK_STATE_REQUIRED_KEYSrM�setattr)rWr�r]r[�msg�krLs       rB�loadzNetworkStateInterpreter.loads����E�!��I�I�<�=��C�D�D�3�E�)�4D�E�
� ���6���3�|�D�C��I�I�c�N��S�/�!� -�E�!���0D�A�E�	+�C��D�#�u�S�z�*�	+��Es�(	B�2Bc�@�tj|j�SrF)rr�riros rB�dump_network_statez*NetworkStateInterpreter.dump_network_state&s���~�~�d�1�1�2�2rDc�4�|j|jd�S)N)rr)rjr�ros rB�as_dictzNetworkStateInterpreter.as_dict)s���=�=�D�L�L�A�ArDc��|jdk(r|j|��d|_y|jdk(r|j|��d|_yy)Nr��skip_brokenTr�)rj�parse_config_v1r��parse_config_v2)rWr�s  rB�parse_configz$NetworkStateInterpreter.parse_config,sO���=�=�A��� � �[� �9��D�L�
�]�]�a�
�� � �[� �9��D�L� rDc�"�|jD] }|d}	|j|}	||��"|jj�D]*\}}d}	|jd|}|s�|\}	}
|	|
d�|d	<�,y#t$r}td|z�|�d}~wwxYw#t$rA|s�t
j
d|d��t
j|j��Y��wxYw#t$r }tdj|��|�d}~wwxYw)
N�typez"No handler found for  command '%s'�Skipping invalid command: %sT��exc_infor zINameserver specified for interface {0}, but interface {0} does not exist!r�rr)r�r�rt�RuntimeErrorrOr��warningr�r�r��itemsrir��format)rWr�rX�command_type�handler�e�	interfacerrr�r#rxs           rBr�z'NetworkStateInterpreter.parse_config_v14sD���|�|�	9�G�"�6�?�L�
��/�/��=��
	
9��� �	9�$#�5�5�;�;�=�	�N�I�s��E�
��+�+�L�9�)�D���&)�#��V�#.�$� ��e��	���
�"�8�<�G�����
��"�
9�"���K�K�6��$� ���I�I�d�5�5�7�8�
9���
� �8�8>��y�8I�����
�sA�A8�B�C%�8	B�B�B�AC"�!C"�%	D�.D	�	Dc��ddlm}t|j|�ry|jj�D]4\}}|dvr�	|j|}	||�|j|��6y#t$r}td|z�|�d}~wwxYw#t$rA|s�tjd|d��tj|j��Y��wxYw)Nrr)rr$z!No handler found for command '%s'r�Tr�)r�rr�r�r�r�r�rtr��
_v2_commonrOr�r�r�r�)rWr�r�r�rXr�r�s       rBr�z'NetworkStateInterpreter.parse_config_v2Ws���E��d�n�n�o�6��%)�\�\�%7�%7�%9�	9�!�L�'��6�6��
��/�/��=��


9��� �����(�	9��
�
�"�7�,�F�����
��"�
9�"���K�K�6��$� ���I�I�d�5�5�7�8�
9�s+�A0�B�0	B
�9B�B
�AC�C�namec�$�|j|�SrF�r��rWrXs  rBr�z'NetworkStateInterpreter.handle_loopbackss���#�#�G�,�,rDc��|jjdi�}|j|di�}|jdi�j�D]\}}|j||i��t	|jd��}|j
sJ|D]E}|jd�j
d�st|jd��s�>d|_n|jd	d
�}|�tj|�}|jdd
�}	|	�tj|	�}	|j|jd�|jd�|jd�d
d|jd�d
d
|||	d��|jdj|jd�|i�|j�y
)z�
        command = {
            'type': 'physical',
            'mac_address': 'c0:d6:9f:2c:e8:80',
            'name': 'eth0',
            'subnets': [
                {'type': 'dhcp4'}
             ],
            'accept-ra': 'true'
        }
        r r��paramsr�r��6�addressTr'Nr&�mac_address�inet�manualr")r�r�r�r�r(r"r��gatewayr�r'r&)rirkr�r��_normalize_subnetsrf�endswithrr�is_truer�)
rWrXr r��paramr�r�r��	accept_rar&s
          rBr�z'NetworkStateInterpreter.handle_physicalws����(�(�,�,�\�2�>�
����w�v���3��!�+�+�h��3�9�9�;�	'�J�E�3��L�L�%���&�	'�%�W�[�[��%;�<���}�}�!�
���:�:�f�%�.�.�s�3���J�J�y�)�8�%)�D�M��
��K�K��T�2�	�� ����Y�/�I��K�K��T�2�	�� ����Y�/�I�
������F�+����F�+�&�{�{�=�9�� ��{�{�5�)���"�&�&�
�	
�	
���L�)�0�0�'�+�+�f�2E�u�1M�N����!rD)r��vlan_id�	vlan_linkc��|jjdi�}|j|�|j|jd�i�}|jd�|d<|jd�|d<|j|d|i�y)z�
        auto eth0.222
        iface eth0.222 inet static
                address 10.10.10.1
                netmask 255.255.255.0
                hwaddress ether BC:76:4E:06:96:B3
                vlan-raw-device eth0
        r r�r�zvlan-raw-devicer�N)rirkr�r�)rWrXr r�s    rBr�z#NetworkStateInterpreter.handle_vlan�s����(�(�,�,�\�2�>�
����W�%����w�{�{�6�2�B�7��#*�;�;�{�#;��� �"�;�;�y�1��i�����5��=�%�0�1rD)r��bond_interfacesr�c��|j|�|jjd�}|j|jd�i�}|jd�j�D]\}}|j	||i��|j	ddi�|jdj	|d|i�|jd�D]�}||vr|dd�}|j|�|jjdi�}|j|�}|jd�|d	<|jd�j�D]\}}|j	||i��|jdj	||i���y
)aU
        #/etc/network/interfaces
        auto eth0
        iface eth0 inet manual
            bond-master bond0
            bond-mode 802.3ad

        auto eth1
        iface eth1 inet manual
            bond-master bond0
            bond-mode 802.3ad

        auto bond0
        iface bond0 inet static
             address 192.168.0.10
             gateway 192.168.0.1
             netmask 255.255.255.0
             bond-slaves none
             bond-mode 802.3ad
             bond-miimon 100
             bond-downdelay 200
             bond-updelay 200
             bond-lacp-rate 4
        r r�r�zbond-slaves�nonerr8)r�r�zbond-masterN)r�rirkr�r�)	rWrXr r�r�r��ifname�cmd�bond_ifs	         rBr�z#NetworkStateInterpreter.handle_bond�sw��6	
���W�%��(�(�,�,�\�:�
����w�{�{�6�2�B�7��!�+�+�h�/�5�5�7�	'�J�E�3��L�L�%���&�	'�
���m�V�,�-����L�)�0�0�%��-��1G�H��k�k�"3�4�	H�F��Z�'�"�"���
�$�$�S�)��,�,�0�0��r�B�J� �n�n�V�,�G�%,�[�[��%8�G�M�"�%�k�k�(�3�9�9�;�
-�
��s�����s�|�,�
-�����-�4�4�f�g�5F�G�	HrD�bridge_interfacesc��|jjdi�}|jd�D]}||vr�d|i}|j|��|jjdi�}|j|�|j|jd�i�}|d|d<|jdi�j�D]\}}|j	||i��|jd�}|�Lt|t�s<|dvrd	}n"|d
vrd}ntdj|�
���|j	d|i�|j	|d|i�y)a�
            auto br0
            iface br0 inet static
                    address 10.10.10.1
                    netmask 255.255.255.0
                    bridge_ports eth0 eth1
                    bridge_stp off
                    bridge_fd 0
                    bridge_maxwait 0

        bridge_params = [
            "bridge_ports",
            "bridge_ageing",
            "bridge_bridgeprio",
            "bridge_fd",
            "bridge_gcint",
            "bridge_hello",
            "bridge_hw",
            "bridge_maxage",
            "bridge_maxwait",
            "bridge_pathcost",
            "bridge_portprio",
            "bridge_stp",
            "bridge_waitport",
        ]
        r rr��bridge_portsr�r6N)�on�1rT)�off�0rFz2Cannot convert bridge_stp value ({stp}) to boolean)r,)	rirkr�r�r�r��boolr�r�)	rWrXr rrr�r�r�r6s	         rBr�z%NetworkStateInterpreter.handle_bridge�sg��>�(�(�,�,�\�2�>�
��k�k�"5�6�	&�F���#�����C�
� � ��%�	&��(�(�,�,�\�2�>�
����W�%����w�{�{�6�2�B�7�� '�(;� <��n��!�+�+�h��3�9�9�;�	'�J�E�3��L�L�%���&�	'��Y�Y�|�,�
��!�*�Z��*F��^�+�!�
���.�"�
� ��%�v�*�v�5���
�L�L�,�
�3�4����5��=�%�0�1rDc�&�|j|�yrFr�r�s  rBr�z)NetworkStateInterpreter.handle_infiniband5s�����W�%rDc���g}g}d|vr0|d}t|t�s|g}|D]}|j|��d|vr0|d}t|t�s|g}|D]}|j|��||fS)Nr�rx)r��list�append)rWrXr#rx�addrs�addr�paths�paths        rB�
_parse_dnsz"NetworkStateInterpreter._parse_dns9s�����������I�&�E��e�T�*�����
)���"�"�4�(�
)��w���H�%�E��e�T�*�����
$���
�
�d�#�
$��F�"�"rDr�c���|jjd�}|j|�\}}d|vr||f|j|d<y|dj	|�|dj	|�y)Nrrr�r#rx)rirkrr��extend)rWrXrrr#rxs     rBr�z)NetworkStateInterpreter.handle_nameserverJsw���!�!�%�%�e�,��"�o�o�g�6���V��'�!���=�D�#�#�G�K�$8�9�

�
��%�%�k�2���M� � ��(rDc�x�|jjd�}|j|�\}}||d�||d<y)Nr r�rr)rirkr)rWrXr��_ifacer#rxs      rB�_handle_individual_nameserverz5NetworkStateInterpreter._handle_individual_nameserverWs>���$�$�(�(��6��"�o�o�g�6���V�/:�f�M��u�
�e�rD�destinationc�R�|jdjt|��yr�)rir�_normalize_router�s  rBr�z$NetworkStateInterpreter.handle_route]s!�����H�%�,�,�-=�g�-F�GrDc�*�|j|d��y)a�
        v2_command = {
          bond0: {
            'interfaces': ['interface0', 'interface1'],
            'parameters': {
               'mii-monitor-interval': 100,
               'mode': '802.3ad',
               'xmit_hash_policy': 'layer3+4'}},
          bond1: {
            'bond-slaves': ['interface2', 'interface7'],
            'parameters': {
                'mode': 1,
            }
          }
        }

        v1_command = {
            'type': 'bond'
            'name': 'bond0',
            'bond_interfaces': [interface0, interface1],
            'params': {
                'bond-mode': '802.3ad',
                'bond_miimon: 100,
                'bond_xmit_hash_policy': 'layer3+4',
            }
        }

        r8��cmd_typeN��_handle_bond_bridger�s  rBr�z$NetworkStateInterpreter.handle_bondsbs��:	
� � ��6� �:rDc�*�|j|d��y)a�
        v2_command = {
          br0: {
            'interfaces': ['interface0', 'interface1'],
            'forward-delay': 0,
            'stp': False,
            'maxwait': 0,
          }
        }

        v1_command = {
            'type': 'bridge'
            'name': 'br0',
            'bridge_interfaces': [interface0, interface1],
            'params': {
                'bridge_stp': 'off',
                'bridge_fd: 0,
                'bridge_maxwait': 0
            }
        }

        r9r Nr"r�s  rBr�z&NetworkStateInterpreter.handle_bridges�s��.	
� � ��8� �<rDc��t�}|j�D�](\}}ddi}|jdi�}|jdd�}|s tj	d|t|��||d<|}|jd�}	|	r|	}n#|r!|r|j
�}
t|
�}|r|}||d	<|jd
d�}|rd
|i|d<dD]}
|
|vs�||
||
<�t|�|j|�}t|�d
kDr|jd|i�tj	d|�|j|���+y)a�
        ethernets:
          eno1:
            match:
              macaddress: 00:11:22:33:44:55
              driver: hv_netvsc
            wakeonlan: true
            dhcp4: true
            dhcp6: false
            addresses:
              - 192.168.14.2/24
              - 2001:1::1/64
            gateway4: 192.168.14.1
            gateway6: 2001:1::2
            nameservers:
              search: [foo.local, bar.local]
              addresses: [8.8.8.8, 8.8.4.4]
          lom:
            match:
              driver: ixgbe
            set-name: lom1
            dhcp6: true
            accept-ra: true
          switchports:
            match:
              name: enp2*
            mtu: 1280

        command = {
            'type': 'physical',
            'mac_address': 'c0:d6:9f:2c:e8:80',
            'name': 'eth0',
            'subnets': [
                {'type': 'dhcp4'}
             ]
        }
        r�r�r!�
macaddressNzHNetworkState Version2: missing "macaddress" info in config entry: %s: %sr�r%r��driverr�)r"r!r&r'rr�z!v2(ethernets) -> v1(physical):
%s)
r
r�rkr�r��str�lowerr	rC�_v2_to_v1_ipcfg�lenr�r�)rWrX�
ifaces_by_mac�eth�cfg�phy_cmdr!r�r��set_name�lcase_mac_address�macr'rLr�s               rBr�z(NetworkStateInterpreter.handle_ethernets�se��Z.�/�
��
�
��-	*�H�C���
��G��G�G�G�R�(�E��)�)�L�$�7�K���	�	�.����H�	�&1�G�M�"��D��w�w�z�*�H������$/�$5�$5�$7�!�2�3D�E����D�"�G�F�O��Y�Y�x��.�F��%-�v�$6���!�A�
,���#�:�#&�s�8�G�C�L�
,�
(��,��*�*�3�/�G��7�|�a�����	�7�3�4��I�I�:�G�D�� � ��)�[-	*rDc�^�|j�D]�\}}d||jd�|jd�d�}d|vr|d|d<t|�|j|�}t	|�dkDr|jd|i�tjd|�|j|���y	)
aq
        v2_vlans = {
            'eth0.123': {
                'id': 123,
                'link': 'eth0',
                'dhcp4': True,
            }
        }

        v1_command = {
            'type': 'vlan',
            'name': 'eth0.123',
            'vlan_link': 'eth0',
            'vlan_id': 123,
            'subnets': [{'type': 'dhcp4'}],
        }
        r��id�link)r�r�r�r�r"rr�zv2(vlans) -> v1(vlan):
%sN)	r�rkrCr*r+r�r�r�r�)rWrXr�r.�vlan_cmdr�s      rBr�z$NetworkStateInterpreter.handle_vlans�s���$!����	'�I�D�#����7�7�4�=� �W�W�V�_�	�H���|�"%�e�*����'��,��*�*�3�/�G��7�|�a������G� 4�5��I�I�2�H�=����X�&�	'rDc�.�tjd�y)NzOWifi configuration is only available to distros with netplan rendering support.)r�r�r�s  rBr�z$NetworkStateInterpreter.handle_wifiss�����
*�	
rDc�4�tjd|�|j�D]�\}}d|vr|jd�}|r|}d|vs�$|jd�jdg�}|jd�jdg�}ddi}t	|�dkDr|jd|i�t	|�dkDr|jd	|i�|jd
i�jd�}|rt
|�}	|	r|	}|j||���y)Nzv2_common: handling config:
%sr%r#rxrr�r�rr�r!r&)r�r�r�rkr+r�r	r)
rWr.r��dev_cfg�set_name_ifacerxrr�name_cmdr��real_if_names
          rBr�z"NetworkStateInterpreter._v2_common s���	�	�3�S�9�!�i�i�k�	D�N�E�7��W�$�!(���Z�!8��!�*�E���'� ���]�3�7�7��"�E���k�k�-�0�4�4�[�"�E��"�L�1���v�;��?��O�O�X�v�$6�7��s�8�a�<��O�O�Y��$4�5�-4�[�[��"�-E�-I�-I� �.���#?��#L�L�#� ,���2�2�8�U�C�-	DrDc
��
�td�tj|�j�D���
|j�D�]7\}}td�|j�D��}|jdi�}|j	dd�}|r||d<d|d||d	z|jd
�dt�
fd�|j�D��i}d
|vr|d
|d
<t|�|j
|�}	t|	�dkDr|jd|	i�tjd|||�|dk(r|j|���|dk(r|j|���tdj|����y)z(Common handler for bond and bridge typesc3�*K�|]\}}||f���
y�wrFrS��.0r��vs   rB�	<genexpr>z>NetworkStateInterpreter._handle_bond_bridge.<locals>.<genexpr>>s����
��q�!�Q��F�
�s�c3�:K�|]\}}|tvr||f���y�wrF)�NETWORK_V2_KEY_FILTER)r@rL�values   rBrBz>NetworkStateInterpreter._handle_bond_bridge.<locals>.<genexpr>Cs)����� �S�%��3�3��e���s��
parameterszgratuitious-arpNr)r�r��_interfacesr r�c3�2�K�|]\}}�||f���y�wrFrS)r@r�rA�v2key_to_v1s   �rBrBz>NetworkStateInterpreter._handle_bond_bridge.<locals>.<genexpr>Ss�����N�t�q�!��A���2�N�s�r"rr�zv2(%s) -> v1(%s):
%sr9r8z Unknown command type: {cmd_type}r )r�r:rkr��poprCr*r+r�r�r�r�r�r�r�)rWrXr!�	item_name�item_cfg�item_paramsr��
grat_value�v1_cmdr�rIs          @rBr#z+NetworkStateInterpreter._handle_bond_bridge:s�����
�/�3�3�H�=�C�C�E�
�
��$+�=�=�?�%	��I�x���$,�N�N�$4���K�!�_�_�\�2�6�F����$5�t�<�J��+5��'�(����	��=�(�(�,�,�|�*D��$�N�v�|�|�~�N�N�	�F��� � (����u�
�'��1��*�*�8�4�G��7�|�a���
�
�y�'�2�3��I�I�-�x��6�J��8�#��"�"�6�*��V�#�� � ��(� �6�=�=�!)�>����C%	rDc� �d�}g}|jd�r.ddi}||jdi�|�|j|�|jd�r5ddi}d|_||jdi�|�|j|�d}d}i}|jd	g�D]�}d
|d�}d|vr+d
|vrQ|�O|jd
�}|jd|i�n*d|vr&|�$|jd�}|jd|i�d|vra|s_|jd�jd	�}	|	r|	|d<|jd�jd�}
|
r|
|d<|j|�|j|���g}|jdg�D]]}|jt	|jd�|jd�|jd�|jd�d����_t|�rt|�r||dd<|S)z7Common ipconfig extraction from v2 to v1 subnets array.c��d|vr	|d|d<yy)Nzroute-metric�metricrS)�	overridesr�s  rB�_add_dhcp_overrideszDNetworkStateInterpreter._v2_to_v1_ipcfg.<locals>._add_dhcp_overridesls����*�#,�^�#<��x� �+rDrr�rrTrNr�static)r�r��:rr�rr#rurx�
dns_searchr��to�viarRr")rr�rRr"r)rkrrfr�rr+)
rWr.rTr�r�rrr#r�rrxr�r�s
             rBr*z'NetworkStateInterpreter._v2_to_v1_ipcfgis��	=����7�7�7���g�&�F�����(9�2� >��G��N�N�6�"��7�7�7���g�&�F� �D�M�����(9�2� >��G��N�N�6�"��������w�w�{�B�/�	#�G� �"��F�
�g�~���$��)9�"�w�w�z�2�H��M�M�9�h�"7�8���$��)9�"�w�w�z�2�H��M�M�9�h�"7�8���#�K��G�G�M�2�6�6�{�C�	��5>�K� 1�2�����/�3�3�H�=���06�K��-��
�
�k�*��N�N�6�"�1	#�4���W�W�X�r�*�
	�E��M�M� �',�y�y���#(�9�9�U�#3�"'�)�)�H�"5�$�y�y��/�	��	
�
	��w�<�C��K�#)�G�A�J�x� ��rD)r$zOptional[Renderer])T)r<NrF)%rPrQrRr�r�rmr�rdrrf�setterr�r�r�r�r�r�r�rbr�r�r�r�r�r�rr�rr�r�r�r�r�r�r�r#r*rSrDrBr�r��s�������
���	��&��)-�	
�'�	
�:�H�|�H��H��3��3��_�_�6��6�%�+� 3�B� �!�F9�8�&��"�-�#�-��&��"�4"�#�4"�l�9�:�2�;�2� �>�?�2H�@�2H�h�&�"5�6�7�>2�8�>2�@�&��"�&�#�&�#�"�)��%�
)�&�
)��)��%�N�&�N�
�-��)�H�*�H�;�>=�2\*�| '�D
�D�4-�^ArDr�c�V�tj|�}td�|j�D��}|j	d�dvr|jt
|d���|j	dg�D�cgc]
}t|���c}|d<d�}dD]}|||��
|Scc}w)	Nc3�0K�|]\}}|s�	||f���y�wrFrSr?s   rBrBz$_normalize_subnet.<locals>.<genexpr>�s����@�D�A�q�a�!�Q��@�s�
�	r�)rU�static6)r��
ip_address��address_keysr�c�b�||vr+t||t�s||j�||<yyyrF)r�r�split)�snetr�s  rB�listifyz"_normalize_subnet.<locals>.listify�s3���4�<�
�4��:�t� <��d��)�)�+�D��J�!=�<rD)rWru)rgrhr�r�rkr��_normalize_net_keysr)r��
normal_subnet�rrdr�s     rB�_normalize_subnetrh�s���
�]�]�6�
"�F��@�F�L�L�N�@�@�M�
�z�z�&��2�2�������
�	
�&,�Z�Z��"�%=�� !�����M�(��,�/�"���
�q�!�"����s�9B&c���|j�D��cic]\}}|s|dk(s�||��}}}d}|D]}|j|�s�|}n|s7ddj|��d|��}tj	|�t|��t
|j|��}t|�s%tj	d|�td|�d���t|�}	t|�}
|jd	�}d
|vr[|jd
�\}}
}|||<|	rt|�}nl|
rt|�}n^tj	d|�td|�d���d|vrt|d�}n&|r|
rt|�}n|r|	rt|�}n|	rdnd
}d|vr1t
|d�t
|�k7rtjd||�||d<|	r	d	|vr|d	=|S|
rt|d�|d	<|Scc}}w)a�Normalize dictionary network keys returning prefix and address keys.

    @param network: A dict of network-related definition containing prefix,
        netmask and address_keys.
    @param address_keys: A tuple of keys to search for representing the address
        or cidr. The first address_key discovered will be used for
        normalization.

    @returns: A dict containing normalized prefix and matching addr_key.
    rNz No config network address keys [�,z] found in z$Address %s is not a valid ip networkzAddress z is not a valid ip address�netmask�/r��@�z;Overwriting existing 'prefix' with '%s' in network info: %s)r�rk�joinr�r�r�r(r
rr�	partitionrrr�r�r)r�r`r�rA�net�addr_keyrL�messager�ipv6�ipv4rk�	addr_part�_�maybe_prefixr�s                rBrere�s��$�M�M�O�
;�D�A�q�q�A��F�1�a�4�
;�C�
;��H�����7�7�3�<��H�����H�H�\�"��
��	�	�	�'����!�!��s�w�w�x� �!�D�����	�	�8�$�?��8�D�6�)C�D�E�E��4� �D��4� �D��g�g�i� �G�
�d�{�%)�^�^�C�%8�"�	�1�l�!��H�
��,�\�:�F�
�,�\�:�F�
�I�I�<�d�C��x��v�-G�H�I�I�	�S���S��]�#��	�T�(��1��	�T�(��1�������3��3�s�8�}�-��V��<����I���	
�
�C��M������I���J�
�0��X��?��I���J��}<s
�G&�G&c�<�td�|j�D��}d|vr|d|d<|d=|jt|d���|j	d�}|r	t|�|d<|S|S#t$r }tdj|��|�d}~wwxYw)	a�normalize a route.
    return a dictionary with only:
       'type': 'route' (only present if it was present in input)
       'network': the network portion of the route as a string.
       'prefix': the network prefix for address as an integer.
       'metric': integer metric (only if present in input).
       'netmask': netmask (string) equivalent to prefix iff network is ipv4.
    c3�4K�|]\}}|dvs�||f���y�w))�NNrSr?s   rBrBz#_normalize_route.<locals>.<genexpr> s$������1�a�A�Z�,?��A���s��	rr�)r�rr_rRz(Route config metric {} is not an integerN)	r�r�r�rerkr�r��	TypeErrorr�)r��normal_routerRr�s    rBrrs����� �;�;�=���L���$�".�}�"=��Y����'������'A�	
���
�
�h�
'�F�
�	�%(��[�L��"�
��<���	�	��:�A�A�&�I���
��	�s� A2�2	B�;B�Bc�F�|sg}|D�cgc]
}t|���c}Scc}wrF)rh)r��ss  rBr�r�8s$�����*1�2�Q��a� �2�2��2s��
net_configr�c���d}|jd�}|jd�}|dk(r|}|r.|�,t|||��}|j|��|j}|st	d|����|S)zfParses the config, returns NetworkState object

    :param net_config: curtin network config dict
    Nrrr�)rrr$r�zpNo valid network_state object created from network config. Did you specify the correct version? Network config:
)rkr�r�rr�)r�r�r$r�rr�nsis       rB�parse_net_config_datar�>s���
�E��n�n�Y�'�G�
�^�^�H�
%�F��!�|����6�%�%��F�X�
��	���[��1��!�!����
E��l�
�
�	
��LrD)rS)TN).rgr_�logging�typingrrrr�	cloudinitrr�
cloudinit.netr	r
rrr
rrrr�cloudinit.net.rendererr�	getLoggerrPr�r�r�rDr:r(�__annotations__r�rCrM�	ExceptionrOrbrdr�rhrerr�r
r�rSrDrB�<module>r�s]�����5�5�$�
�
�
��/��g����!�����-�����(&�+�-�+�&�4�%�-�%��-�!�!:�"�!7�
�$'�'�$��$�"��&�*����%/��$�s�D��c��N�*�+��D
�d�
�t�
��	�Y�	��$S8�S8�lV�V�r�:I�X�D3��
�������	rD

Zerion Mini Shell 1.0