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

�

�f�K���ddlZddlZddlZddlZddlZddlZddlmZmZddl	m
Z
mZmZm
Z
ddlmZmZmZmZmZddlmZmZdZdZej2e�Zd�Zdd	ed
efd�Zd�Zdd
�Z Gd�dejB�Z!dd�Z"y)�N)�Optional�cast)�features�safeyaml�subp�util)�IPV6_DYNAMIC_TYPES�
SYS_CLASS_NET�get_devicelist�renderer�subnet_is_ipv6)�NET_CONFIG_TO_V2�NetworkStatez/etc/netplan/50-cloud-init.yamls4# This is the initial network config.
# It can be overwritten by cloud-init or console-conf.
network:
    version: 2
    ethernets:
        all-en:
            match:
                name: "en*"
            dhcp4: true
        all-eth:
            match:
                name: "eth*"
            dhcp4: true
c�H��t�fd�|j�D��S)Nc3�N�K�|]\}}|j��r||f���y�w�N)�
startswith)�.0�key�value�matchs   ��7/usr/lib/python3/dist-packages/cloudinit/net/netplan.py�	<genexpr>z,_get_params_dict_by_match.<locals>.<genexpr>+s-�������S�%��>�>�%� �

�e���s�"%)�dict�items)�configrs `r�_get_params_dict_by_matchr*s#�����"�L�L�N����r�entryc	�x�d%d�}|�g}g}g}g}g}|jdg�}	|	�g}	|	D�],}
|
jd�}|jd�r|dk(r|dz
}|j|di��D|tvr|jddi��`|d	vs�ed
|
jd�z}d|
vr|d
|
jd�zz
}|
jd�rx|
jd�dd�}
	t	j
|
d�}t	j|d��}||vrtjd|
d|�d|
d<|j|
�d|
vr|||
jdg��z
}d|
vr|||
jdg��z
}d|
vr5d}t|
�rd|vrd}|j||
jd�i�|
jdg�D]s}|jd��d|jd���}|jd�|d�}
d|vr#|
jd|jdd�i�|j|
��u|j|���/d|vr?|jd�}|r$|d|k7rtjd||d|�n|d|d<t|�d kDr|jd!|i�t|�d kDr|jd|i�t|�d kDrd!|i}|jd"|i�t|�d kDr8|jd"i�}|jd#|i�|jd"|i�d$|vr<|d$�6|jd$tj|jd$��i�yyy#t$r&}tjd|
d||�Yd}~��d}~wwxYw)&a�This method parse a cloudinit.net.network_state dictionary (config) and
       maps netstate keys/values into a dictionary (entry) to represent
       netplan yaml. (config v1 -> netplan)

    An example config dictionary might look like:

    {'mac_address': '52:54:00:12:34:00',
     'name': 'interface0',
     'subnets': [
        {'address': '192.168.1.2/24',
         'mtu': 1501,
         'type': 'static'},
        {'address': '2001:4800:78ff:1b:be76:4eff:fe06:1000",
         'mtu': 1480,
         'netmask': 64,
         'type': 'static'}],
      'type: physical',
      'accept-ra': 'true'
    }

    An entry dictionary looks like:

    {'set-name': 'interface0',
     'match': {'macaddress': '52:54:00:12:34:00'},
     'mtu': 1501}

    After modification returns

    {'set-name': 'interface0',
     'match': {'macaddress': '52:54:00:12:34:00'},
     'mtu': 1501,
     'address': ['192.168.1.2/24', '2001:4800:78ff:1b:be76:4eff:fe06:1000"],
     'ipv6-mtu': 1480}

    c�Z�|rt|t�s|S||vr|j|�S|gS)zT
        Helper to convert strings to list of strings, handle single string
        )�
isinstance�str�split)�obj�tokens  r�_listifyz$_extract_addresses.<locals>._listifyWs:���*�S�#�.��J��C�<��9�9�U�#�#���
rN�subnets�type�dhcp�4T�dhcp6)�static�static6z%s�address�prefixz/%d�gateway�default)�via�toF)�strictzAGateway %s is not contained within subnet %s, adding on-link flagzon-linkzDFailed to check whether gateway %s is contained within subnet %s: %s�dns_nameservers�
dns_search�mtuzipv6-mtu�routes�network�/�metric�dzZNetwork config: ignoring %s device-level mtu:%s because ipv4 subnet-level mtu:%s provided.r�	addresses�nameservers�searchz	accept-ra)� )�getr�updater	�	ipaddress�
ip_address�
ip_network�LOG�debug�
ValueError�warning�appendr
�lenr�is_true)rr�ifnamerr'r>r9r?�
searchdomainsr(�subnet�sn_type�addr�	new_route�subnet_gateway�subnet_network�e�mtukey�route�to_net�	entry_mtu�nss                      r�_extract_addressesr\2s���J������I�
�F��K��M��j�j��B�'�G������;#���*�*�V�$�����f�%��&� ��3����L�L�'�4��)�
�*�
*��L�L�'�4��)�
�-�
-��&�*�*�Y�/�/�D��6�!����
�
�8� 4�4�4���z�z�)�$�!�:�:�i�0�#��	��%.�%9�%9�&��:K�%L�N�%.�%9�%9�$�u�%M�N�&�^�;��	�	�3�"�9�-� �	�04�	�)�,��
�
�i�(� �F�*��x��
�
�3D�b�(I�J�J���v�%���&�*�*�\�2�*F�!G�G�
������!�&�)�j�H�.D�'�F����f�f�j�j��&7�8�9����H�b�1�
)��$)�I�I�i�$8�%�)�)�H�:M�N�� �9�9�Y�/� ��	��u�$��$�$�h��	�	�(�C�0H�%I�J��
�
�i�(�
)�
���T�"�w;#�z
����I�I�e�$�	�����)�3��K�K�6���u�
��
�"�%�=�E�%�L�
�9�~���
���k�9�-�.�
�6�{�Q��
���h��'�(�
�;��!���;�
'��
���m�R�(�)�
�=��A��
�Y�Y�}�b�
)��
�	�	�8�]�+�,�
���m�R�(�)��f����!4�!@�
���k�4�<�<��
�
�;�0G�#H�I�J�"A���k"���K�K�=��y�)�������s�#AN
�
	N9�N4�4N9c
���t|j�D��cgc]\}}|jdd�|k(r|��c}}�}t|�dkDr|j	d|i�yycc}}w)Nzbond-masterr�
interfaces)�sortedrrBrLrC)r^r�bond_master�name�cfg�bond_slave_namess      r�_extract_bond_slaves_by_namerd�sq��� *�/�/�1�	
���s��w�w�}�d�+�{�:�
�	
������q� �
���l�$4�5�6�!��
	
s�!A%
c���tj|d�}tjj	|�sytj|�}|tk7rydD�cgc]}tj||���}}|D�cgc]$}tjj	|�s�#|��&}}tjd||�|g|zD]}tj|��ycc}wcc}w)Nz etc/netplan/00-snapd-config.yaml)z-run/systemd/network/10-netplan-all-en.networkz.run/systemd/network/10-netplan-all-eth.networkz#run/systemd/generator/netplan.stampz9removing known config '%s' and derived existing files: %s)r�target_path�os�path�isfiler�load_binary_file�KNOWN_SNAPD_CONFIGrGrH�unlink)�target�tpath�content�f�derived�existings      r�_clean_defaultrs�s���
���V�%G�H�E�
�7�7�>�>�%� ���#�#�E�*�G��$�$��
��
�	
�����#��G��#�8�a�b�g�g�n�n�Q�&7��8�H�8��I�I�C�
����W�x�
���
�	�	�!������9s�C �=$C%�"C%c��eZdZdZddgZddgZdd�Zed��Z		dde	d	e
ed
dfd�Zdde
d
e
fd�Zdd�Zde	d
efd�Zy)�RendererzBRenders network information in a /etc/netplan/network.yaml format.�netplan�generate�infoNc��|si}|jdt�|_|jdd�|_|jdd�|_|jdd�|_|jdd�|_y)N�netplan_path�netplan_header�postcmdsF�
clean_defaultTr)rB�CLOUDINIT_NETPLAN_FILErzr{�	_postcmdsr}�	_features)�selfrs  r�__init__zRenderer.__init__�si����F�"�J�J�~�7M�N���$�j�j�)9�4�@������J��6���#�Z�Z���>������J��5��rc��|j�S	tj|jd��\}}tj|�}|dd|_|jS|jS#tj
$rY|jSttf$r+}tjd|�Yd}~|jSd}~wwxYw)NT��capturez
netplan.iorz-Failed to list features from netplan info: %s)
r�r�NETPLAN_INFOr�	load_yaml�ProcessExecutionError�	TypeError�KeyErrorrGrH)r��	info_blob�_errrxrVs     rrzRenderer.features�s����>�>�!�	
N�"&�)�)�D�,=�,=�t�"L��	�4��~�~�i�0��!%�l�!3�J�!?����~�~��t�~�~���
�-�-�
���~�~���x�(�
N��	�	�I�1�M�M��~�~���
N�s�AA,�,C�C�C�C�
network_state�	templates�returnc��tjjtj|�|j
�}t
jtjj|��|j|�}|jr|jnd}|jd�s|dz
}||z}d}tjj|�rgt
jtj|j!���}t#|d�5}	t
j|	�}
ddd�|
k(rd}t$j&rdnd}|s>tjj|�rt
j(|�}||z|k(r|}t
j*|||��|j,rt/|�	�|j1|j2|�
�|j5|j2��y#1swY��xYw)N��
F�rbTi�i�)�mode)rm)�run�same_content)r�)rgrh�joinrrfrzr�
ensure_dir�dirname�_render_contentr{�endswith�exists�hash_buffer�io�BytesIO�encode�openr�NETPLAN_CONFIG_ROOT_READ_ONLY�get_permissions�
write_filer}rs�_netplan_generater�_net_setup_link)
r�r�r�rm�fpnplanro�headerr��hashed_contentrp�hashed_original_contentr��current_modes
             r�render_network_statezRenderer.render_network_states����'�'�,�,�t�/�/��7��9J�9J�K�����������0�1��&�&�}�5��)-�(;�(;��$�$������t�$��d�N�F��7�"����
�7�7�>�>�'�"�!�-�-�b�j�j����9I�.J�K�N��g�t�$�
>��*.�*:�*:�1�*=�'�
>��!8�8�#�� �>�>�u�E��������w� 7��/�/��8�L��d�"�l�2�#�������t�4�����&�)����4�>�>���M��������0�!
>�
>�s�G<�<Hr�r�c��|stjd�y|rtjd�ytj|jd��y)Nz!netplan generate postcmd disabledzEskipping call to `netplan generate`. reason: identical netplan configTr�)rGrHr�NETPLAN_GENERATE)r�r�r�s   rr�zRenderer._netplan_generate8sB����I�I�9�:����I�I�4�
�
��	�	�$�'�'��6rc�v�|stjd�ygd�}t}td�D]\}	t	�D]K}t
jjt|z�s�*tj|t|zgzd���Mytd�|�#tj$r}|}Yd}~��d}~wwxYw)z�To ensure device link properties are applied, we poke
        udev to re-evaluate networkd .link files and call
        the setup_link udev builtin command
        z'netplan net_setup_link postcmd disabledN)�udevadmztest-builtin�net_setup_link�Tr�zQ'udevadm test-builtin net_setup_link' unable to run successfully for all devices.)rGrH�	Exception�rangerrgrh�islinkr
rr��RuntimeError)r�r��	setup_lnk�last_exception�_�ifacerVs       rr�zRenderer._net_setup_linkDs���
��I�I�?�@��A�	�#���q��	"�A�
#�+�-��E��w�w�~�~�m�e�&;�<��	�	�%���)>�(?�?����
�	"��0��"�
"���-�-�
#�!"���
#�s�3B�&$B�B8�,B3�3B8c	� 
�|jdk(r9tjd�tjd|j
idd��Si}i}i}i}i}g}|jjdg�}|j}	|j}
|j�D�]�}|jd�}ttd�|j���}
|
jd	�}|d
k(rv||
jdd�d�}|d�0|
jd
d�}|�d|j�i|d<n|d=|d=t|
|||j �|j#||i���|dk(�r!i}i}t%tt'jd��}dD]]}t)|
|�}|j�D]<\}}|j|j+dd��}|��*|j#||i��>�_t-|�dkDr|j#d|i�|
jd
�r|
d
j�|d<|
jd�}|dk(r
t/|||�t|
|||j �|j#||i����|dk(�r\|
jd�}t1t3j2|��}d|i}d}t)|
|�}i}t%tt'jd��} |j�D]n\}}| j|�}|��|j#||i�|dvs�2i}!|D]#}"|"j5�\}#}$t7|$�|!|#<�%|j#||!i��pt-|�dkDr|j#d|i�|
jd
�r|
d
j�|d<t|
|||j �|j#||i���N|dk(s��U|
jd�|
jd�d�}%|
jd
d�}|�|j�|%d<t|
|%||j �|j#||%i����|	s|
rE|	|
d �}&|||||fD]6}'|'j�D]!\}(})d!|)vsd"|)vr�|)j#d!|&i��#�8d#�}*|j9d$�||*d%|�z
}||*d&|�z
}||*d'|�z
}||*d(|�z
}||*d)|�z
}d*j;|�S)+N�zV2 to V2 passthroughr:F)�explicit_start�explicit_endr^rac��|dduS)N��)�its r�<lambda>z*Renderer._render_content.<locals>.<lambda>}s��2�a�5��+<�rr)�physicalr)�set-namer�mac_address�
macaddressr��bond)�bond_zbond-r��-r�
parameterszbond-slaves�none�bridge�bridge_ports�bridge_)z	path-costz
port-priority�vlan�vlan_idzvlan-raw-device)�id�link)r>r@r?r>c�r�|r4tj||iddd��}tj|d�}|gSgS)NFT)r�r��noaliasz    )r�dumps�textwrap�indent)ra�section�dump�txts    r�_render_sectionz1Renderer._render_content.<locals>._render_section�sA����~�~��7�O�#(�!&� �	���o�o�d�G�4���u���Irznetwork:
    version: 2
�	ethernets�wifis�bonds�bridges�vlansr�)�versionrGrHrr�r�_network_staterBr6�dns_searchdomains�iter_interfacesr�filterr�lowerr\rrCrrr�replacerLrdr_�copyr$�intrKr�)+r�r�r�r�r�r�r�ror^r?rOrrN�ifcfg�if_type�eth�macaddrr��bond_config�v2_bond_mapr�bond_params�paramr�newname�slave_interfacesr��portsr��match_prefix�params�	br_config�
v2_bridge_map�newvalue�val�port�portvalr��nscfgr��_namerbr�s+                                           rr�zRenderer._render_contentcsB��� � �A�%��I�I�,�-��>�>��M�0�0�1�$�"��
��	�����������"�1�1�5�5�l�B�G�
�#�3�3��%�7�7�
�#�3�3�5�d	-�F��Z�Z��'�F��� <�f�l�l�n�M�N�E��i�i��'�G��*�$�!'�"�Y�Y�w��5����w�<�'�#�i�i�
�t�<�G��*�(4�g�m�m�o�'F��G����L��
�O�"�5�#�v�t�}�}�E�� � �&�#��/��F�"��� ��#�4�)9�)=�)=�f�)E�F��0�=�E�";�E�5�"I�K�*5�*;�*;�*=�=����"-�/�/�%�-�-��S�2I�"J��"�?�$�#�*�*�G�U�+;�<�	=�=��{�#�a�'��K�K��{� ;�<��9�9�]�+�).�}�)=�)C�)C�)E�D��&�#(�9�9�]�#;� �#�v�-�0��T�6�J�"�5�$���
�
�F����f�d�^�,��H�$�$�y�y��8���t�y�y��6�7�� �%� ��
 )��2�5�,�G���	�!%�T�+;�+?�+?��+I� J�
�'-�l�l�n�>�N�U�E�+�/�/��6�G��� ��$�$�g�u�%5�6��"@�@�#%��#(�:�C�.1�i�i�k�O�T�7�-0��\�H�T�N�:�"�(�(�'�8�)<�=�>��y�>�A�%��M�M�<��";�<��9�9�]�+�+0��+?�+E�+E�+G�F�<�(�"�5�&�&�$�-�-�H������/�0��F�"� �)�)�I�.�!�I�I�&7�8��� �)�)�M�4�8���&�)0����D��&�"�5�$���
�
�F����f�d�^�,�Id	-�P�-�"-��G�E�%�u�e�W�e�D�
7��")�-�-�/�7�J�E�3�$��+�{�#�/E� ��J�J�
�u�5�6�7�
7�
	�	���3�4��?�;�	�:�:���?�7�E�2�2���?�7�E�2�2���?�9�g�6�6���?�7�E�2�2���w�w�w��rr)NN)FF)F)�__name__�
__module__�__qualname__�__doc__r�r�r��propertyrrrrr��boolr�r�r#r�r�rrruru�s���L�!�:�.���v�&�L�6�����"%)��	*1�#�*1��D�>�*1�

�*1�X
7�T�
7��
7�"�>[ �\�[ �c�[ rruc�T�dg}ddg}|D]}tj|||��r�yy)Nrvz	/usr/sbinz/sbin)r@rmFT)r�which)rm�expectedr@�ps    r�	availabler
s:���{�H��7�
#�F�
����z�z�!�F�6�:���rr)#r�r�rD�loggingrgr��typingrr�	cloudinitrrrr�
cloudinit.netr	r
rrr
�cloudinit.net.network_staterrr~rk�	getLoggerrrGrrr\rdrsrur
r�rr�<module>rs����	���	��!�4�4���G�:���� �g����!���PK�t�PK�D�PK�f	7��:P �x� � �P �fr

Zerion Mini Shell 1.0