%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_manager.cpython-312.pyc

�

�f�O���ddlZddlZddlZddlZddlZddlZddlmZmZddl	m
Z
mZddlm
Z
mZmZmZddlmZddlmZdZdZd	Zd
Zej2e�ZGd�d�ZGd
�dej:�Zdd�Zdd�Zd�Z dd�Z!dd�Z"y)�N)�List�Optional)�subp�util)�is_ipv6_address�is_ipv6_network�renderer�subnet_is_ipv6)�NetworkState)�available_nm_ifcfg_rhz/etc/NetworkManagerz/usr/lib/NetworkManagerz/etc/sysconfig/network-scriptsz�# This is generated by cloud-init. Do not edit.
#
[.config]
  enable=nm-version-min:1.40
[connection.30-cloud-init-ip6-addr-gen-mode]
  # Select EUI64 to be used if the profile does not specify it.
  ipv6.addr-gen-mode=0

c��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	efd
�Zd�Z
d�Zd
�Zd�Zded	dfd�Zdeed	dfd�Zd�Zd�Zed��Zd�Zd�Zy)�NMConnectionz/Represents a NetworkManager connection profile.c��tjd�}tj�|_t
|j_d|��ttj||��dd�|jd<ddi|jd<y	)
z�
        Initializes the connection with some very basic properties,
        notably the UUID so that the connection can be referred to.
        z$a3924cb8-09e0-43e9-890b-77972a800108zcloud-init �120)�id�uuidzautoconnect-priority�
connectionz%org.freedesktop.NetworkManager.originz
cloud-init�userN)r�UUID�configparser�ConfigParser�config�str�optionxform�uuid5)�self�con_id�
CI_NM_UUIDs   �?/usr/lib/python3/dist-packages/cloudinit/net/network_manager.py�__init__zNMConnection.__init__-sx���Y�Y�E�F�
�"�/�/�1���"%����� ��x�(���
�
�:�v�6�7�$)�%
����L�!�
4�\�
����F��c��|jj|�si|j|<|jj||�s||j||<yy)z_
        Sets a property unless it's already set, ensuring the section
        exists.
        N�r�has_section�
has_option�r�section�option�values    r�_set_defaultzNMConnection._set_defaultEsP���{�{�&�&�w�/�#%�D�K�K�� ��{�{�%�%�g�v�6�+0�D�K�K�� ��(�7r!c�t�|jj|�xr|jj||�S)zf
        Checks if a config option is set. Returns True if it is,
        else returns False.
        r#�rr'r(s   r�_config_option_is_setz"NMConnection._config_option_is_setPs6��
�{�{�&�&�w�/�
�D�K�K�4J�4J��V�5
�	
r!c�L�|j||�r|j||Sy)z]
        Returns the value of a config option if its set,
        else returns None.
        N�r-rr,s   r�_get_config_optionzNMConnection._get_config_optionYs+��
�%�%�g�v�6��;�;�w�'��/�/�r!c�N�|j||�r||j||<yy)z�
        Overrides the value of a config option if its already set.
        Else, if the config option is not set, it does nothing.
        Nr/r&s    r�_change_set_config_optionz&NMConnection._change_set_config_optioncs,��
�%�%�g�v�6�+0�D�K�K�� ��(�7r!c��dD]/}|j|d�dk7ry|j|d�dvs�/ydD]}|j|dd��y)zt
        If for both ipv4 and ipv6, 'may-fail' is set to be False,
        set it to True for both of them.
        ��ipv4�ipv6�may-fail�falseN�method)�dhcp�auto�true)r0r2)r�familys  r�$_set_mayfail_true_if_both_false_dhcpz1NMConnection._set_mayfail_true_if_both_false_dhcpksr��
'�	�F��&�&�v�z�:�g�E���&�&�v�x�8�A��
�	� '�	G�F��*�*�6�:�v�F�	Gr!c	�l�ddddddddd�}|j|dd�	||}|j|ddk(ry	|j|ddk(r|dk(ry	|d
vr|jddd�||j|d<|j|dd�y	#t$rd}d|j|d<Y��wxYw)
z}
        Ensures there's appropriate [ipv4]/[ipv6] for given family
        appropriate for given configuration type
        �manualr;r:)�static�static6�dhcp6�
ipv6_slaac�ipv6_dhcpv6-stateless�ipv6_dhcpv6-stateful�dhcp4r:r9�disabledr<r7N)rFrErDr5r8)r*�KeyErrorr)rr=�subnet_type�
method_mapr9s     r�_set_ip_methodzNMConnection._set_ip_method�s������ �%+�$*���	
�
�	
���&�(�J�7�	5���,�F��;�;�v��x�(�F�2���;�;�v��x�(�F�2�v��7I���
�
�
���f�h�
�;�(.����F��H�%����&�*�g�6��+�	5��F�.4�D�K�K���
�+�	5�s�B�B3�2B3�returnc���|jj|�si|j|<tjd�D](}|�|��}|jj	||�r�&|cSy)N��not_possible)rr$�	itertools�countr%)rr'�
key_prefix�index�keys     r�_get_next_numbered_sectionz'NMConnection._get_next_numbered_section�sf���{�{�&�&�w�/�#%�D�K�K�� ��_�_�Q�'�	�E��L���(�C��;�;�)�)�'�3�7��
�	�r!c�L�|j||�}||j||<y)z�
        Adds a numbered property, such as address<n> or route<n>, ensuring
        the appropriate value gets used for <n>.
        N)rVr)rr'rSr)rUs     r�
_add_numberedzNMConnection._add_numbered�s)��
�-�-�g�z�B��$)����G��S�!r!c��|�d�}|j|j|�}|r
|�d|�d|��n|�d|��|j||<y)a:Add route options to a given route

        Example:
        Given:
          section: ipv4
          route: route0
          key: mtu
          value: 500

        Create line under [ipv4] section:
            route0_options=mtu=500

        If the line already exists, then append the new key/value pair
        �_options�,�=N)r�get)rr'�routerUr)�numbered_key�
route_optionss       r�_add_route_optionszNMConnection._add_route_options�se�� ���)�����G�,�0�0��>�
���o�Q�s�e�1�U�G�,��5��%��!�	
���G��\�*r!c�X�|ddzt|d�z}|j|d|�y)z5
        Adds an ipv[46]address<n> property.
        �address�/�prefixN)rrX)rr=�subnetr)s    r�_add_addresszNMConnection._add_address�s4��
�y�!�C�'�#�f�X�.>�*?�?�����6�9�e�4r!c���t|d�rdnd}|d�d|d��}d|vr|d|d��z
}|j|d�}||j||<d	|vr|j||d	|d	�y
y
)z!Adds a ipv[46].route<n> property.�networkr6r5rdre�gatewayr[r^�mtuN)rrVrra)rr^r=r)�	route_keys     r�
_add_routezNMConnection._add_route�s���+�5��+;�<��&����#�$�A�e�H�o�%6�7������q��y�)�*�+�+�E��3�3�F�G�D�	�).����F��I�&��E�>��#�#�F�I�u�e�E�l�K�r!�dnsNc���t|�rdnd}|jj|�r<|j|dd�|j|d|zdz|j|d<yy)zF
        Extends the ipv[46].dns property with a name server.
        r6r5rn��;N)rrr$r*)rrnr=s   r�_add_nameserverzNMConnection._add_nameserver�sf��+�3�/��V���;�;�"�"�6�*����f�e�R�0�)-���V�)<�U�)C�c�)I�C�)O�D�K�K����&�+r!�
dns_searchc���dD]h}|jj|�s�|j|dd�|j|ddj|�zdz|j|d<�jy)zM
        Extends the ipv[46].dns-search property with a name server.
        r4z
dns-searchrprqN)rr$r*�join)rrsr=s   r�_add_dns_searchzNMConnection._add_dns_search�st��'�	�F��{�{�&�&�v�.��!�!�&�,��;��K�K��'��5��h�h�z�*�+������F�#�L�1�	r!c�&�|jddS)z-
        Returns the connection UUID
        rr)r�rs r�con_uuidzNMConnection.con_uuids���{�{�<�(��0�0r!c�:�|jjdd�S)zN
        Can this be serialized into a meaningful connection profile?
        r�type)rr%rxs r�validzNMConnection.valid	s���{�{�%�%�l�F�;�;r!c�B�|jdd�j�S)z)
        Sanitize a MAC address.
        �-�:)�replace�upper)�addrs r�mac_addrzNMConnection.mac_addrs��
�|�|�C��%�+�+�-�-r!c
��ddddddd�}||d}|�yd	|vrd}nd}||jd
d<|�:||jd
d<|j||dz�|jd
d
<i|j|<dddddddddd�	ddd�ddiiid�}|d}d}	g}
g}|dD]�}t|�rd nd!}
|j|
|d�d"|vr|j	|
|�d#|vr|d#|j|
d#<|d$D]}|j|��d%|vr|
j
|d%�d&|vr|j
|d&�|
d!k(s��d|vs��|d}	��d'|vr:|
|d'd(D�cgc]}||
vr|��
c}z
}
||d'd)D�cgc]}||vr|��
c}z
}|
s|jr|j}
|s|jr|j}|
D]}|j|��|r|j|�|j�|	�|}	|	|k(stjd*|d+||	�||j�D][\}}||vr�||��t||t �r||rd,nd-|j||<�>t#||�|j||<�]|dk(rh|d.d/urt#d0�|jdd1<|	�t#|	�|jdd<|d2�$|j%|d2�|jdd3<|dk(r)d4|vr%|j|d4�|jdd5<|dk(ry|d6D]H}|j&|�}|j)d
dd�|j)d
d
|j+���J|d2�$|j%|d2�|jdd3<|dk(rX|	�Vd7|jdd8<t#|	�|jdd<|d2�$|j%|d2�|jdd3<|dk(s|jj-|d3�s|d+|jd
d9<yycc}wcc}w):z�
        Integrate information from network state interface information
        into the connection. Most of the work is done here.
        �ethernet�vlan�bond�bridge�
infinibandN)�physicalr�r�r�r��loopbackr{zbond-masterrz
slave-typez-master�masterz	bond-mode�bond_miimonzbond-xmit-hash-policyzbond-num-grat-arpzbond-downdelayzbond-updelayzbond-fail-over-maczbond-primary-reselectzbond-primary)	�mode�miimon�xmit_hash_policy�num_grat_arp�	downdelay�updelay�
fail_over_mac�primary_reselect�primary�
bridge_stp�bridge_bridgeprio)�stp�priorityr�vlan_id)r�r�r�r�r�rk�subnetsr6r5rcrj�routes�dns_nameserversrsrn�nameservers�searchzZNetwork config: ignoring %s device-level mtu:%s because ipv4 subnet-level mtu:%s provided.�namer<r8�	wakeonlanT�@zwake-on-lan�mac_addresszmac-addresszvlan-raw-device�parent�bridge_ports�datagramztransport-modezinterface-name)r�con_refr
rLrgrm�extendr��dns_searchdomainsrrrvr>�LOG�warning�items�
isinstance�boolrr��get_connr*ryr%)r�iface�
network_stater	�	_type_map�if_type�
slave_type�	_prop_map�
device_mtu�ipv4_mtu�found_nameservers�found_dns_searchrfr=r^rnr��
nameserver�nm_proprU�ports                     r�render_interfacezNMConnection.render_interfaces���#����&��

�	��E�&�M�*���?���E�!��J��J�,3����L�!�&�)��!�6@�D�K�K��%�l�3�2B�(�2B�2B��j�9�,�-�3�D�K�K��%�h�/�
 "����G��$�'�$;� 3�-�)�!5�$;�)�
�$�/��
�i����)
�	�.�5�\�
��������I�&�	)�F�-�f�5�V�6�F������v��7��F�"��!�!�&�&�1��F�"�17�	�1B����F�#�I�.���)�
'������&�
'�!�F�*�!�(�(��0A�)B�C��v�%� �'�'��|�(<�=����E�V�O�!�%�=��!	)�&�E�>�� ��<�
�6�"���/�/��"�
��

�#�E�l�8�4�!���!1�1��!�
��!�]�%B�%B� -� =� =���M�$C�$C�,�>�>��,�	-�J�� � ��,�	-��� � �!1�2�	
�1�1�3���!�H��:�%��K�K�>��f�
���
�&�g�.�4�4�6�
	@�L�G�S��%����S�z�!���%��*�d�+�#�C�j�F�g����G�$�W�-�14�E�#�J�����G�$�W�-�
	@��j� ��[�!�T�)�9<�T�����J�'�
�6��#�14�X�����J�'��.��]�#�/�9=����-�(�:����J�'�
�6��f��!2�e�!;�,<�H�,<�,<��'�(�-�D�K�K����)��h���n�-�
K��(�x�(�(��.���!�!�,��h�G��!�!�,��$�-�-�/�J�
K��]�#�/�7;�}�}��-�(�8����H�%�m�4��l�"�x�';�:D�D�K�K��%�&6�7�/2�8�}�D�K�K��%�e�,��]�#�/�;?�=�=��-�(�<����L�)�-�8�
�h��d�k�k�&<�&<��]�'
�;@��-�D�K�K��%�&6�7�'
��u"��
!s�$
Q�
Q
c��tj�}|jj|d��d}||j	�zS)z
        Stringify.
        F)�space_around_delimitersz2# Generated by cloud-init. Changes will be lost.

)�io�StringIOr�write�getvalue)r�buf�headers   r�dumpzNMConnection.dump�s<��
�k�k�m�������#�u��=�G�������&�&r!)�__name__�
__module__�__qualname__�__doc__r r*r-r0r2r>rLrrVrXrargrmrrrrvryr|�staticmethodr�r�r��r!rrr*s���9�
�0	1�
��1�G�0+7�Z���*�
�.5�L�P�3�P�4�P��$�s�)����1�<��.��.�rH�h'r!rc�D�eZdZdZd
d�Zd�Zd�Z		ddedee	ddfd	�Z
y)�Rendererz�Renders network information in a NetworkManager keyfile format.

    See https://networkmanager.dev/docs/api/latest/nm-settings-keyfile.html
    Nc� �i|_||_y�N)�connectionsr)rrs  rr zRenderer.__init__�s�������r!c� �|j|Sr�)r��rrs  rr�zRenderer.get_conn�s������'�'r!c�\�||jvr|j|j�S|Sr�)r�ryr�s  rr�zRenderer.con_ref�s1���T�%�%�%��#�#�F�+�4�4�6�6��Mr!r��	templatesrMc���|j�D] }t|d�|j|d<�"|j�D]'}|j|d}|j|||��)|jj	�D]G\}}|j�s�t
||�}tj||j�d��Itjt|�td�y)Nr�i�)�iter_interfacesrr�r�r�r|�nm_conn_filenamer�
write_filer��cloud_init_nm_conf_filename�NM_IPV6_ADDR_GEN_CONF)rr�r��targetr��connrr�s        r�render_network_statezRenderer.render_network_state�s���#�2�2�4�	J�E�.:�5��=�.I�D���U�6�]�+�	J�#�2�2�4�	>�E��#�#�E�&�M�2�D��!�!�%���=�	>�
!�,�,�2�2�4�	6�L�F�D��:�:�<��#�F�F�3�D��O�O�D�$�)�)�+�u�5�		6�	
���'��/�1F��	
r!r�)NN)r�r�r�r�r r�r�rr�dictr�r�r!rr�r��sC���
�(��%)��	
�#�
��D�>�
�

�
r!r�c�P�tj|t�}d|�d�}|�d|��S)Nzcloud-init-z
.nmconnectionz/system-connections/�r�target_path�
NM_RUN_DIR)rr��target_con_dir�con_files    rr�r�s5���%�%�f�j�9�N��V�H�M�2�H��
�1�(��<�<r!c�N�tj|t�}d|��}|�d|��S)Nzifcfg-rd)rr��IFCFG_CFG_FILE)�devnamer�r�r�s    r�sysconfig_conn_filenamer�s2���%�%�f�n�=�N���y�!�H��
�Q�x�j�)�)r!c���t|�}tjj|�st	�rt|�}tjj|�r|SdS)a�
    This function returns the name of the interface config file.
    It first checks for presence of network manager connection file.
    If absent and ifcfg-rh plugin for network manager is available,
    it returns the name of the ifcfg file if it is present. If the
    plugin is not present or the plugin is present but ifcfg file is
    not, it returns None.
    This function is called from NetworkManagerActivator class in
    activators.py.
    N)r��os�path�isfilerr�)r��	conn_files  r�
conn_filenamer�sJ��!��)�I�
�7�7�>�>�)�$�)>�)@�+�G�4�	������y�1�9�;�t�;r!c�H�tj|t�}d}|�d|��S)Nz$30-cloud-init-ip6-addr-gen-mode.confz/conf.d/r�)r�r��	conf_files   rr�r�)s+���%�%�f�j�9�N�6�I��
�X�i�[�1�1r!c���ddlm}tjd|��}d}|�r	tjgd��t|�xr|S#tj$rd}Y�&wxYw)Nr)�uses_systemd�nmcli)r�T)�	systemctlz
is-enabledzNetworkManager.serviceF)�cloudinit.distrosr�r�which�ProcessExecutionErrorr�)r�r��
nmcli_present�service_actives    r�	availabler�/sa��/��J�J�w�v�6�M��N��~�	#��I�I�K�L��
��1�>�1���)�)�	#�"�N�	#�s�A�A&�%A&r�)#rr�rQ�loggingr�r�typingrr�	cloudinitrr�
cloudinit.netrrr	r
�cloudinit.net.network_stater�cloudinit.net.sysconfigrr��
NM_LIB_DIRr�r��	getLoggerr�r�rr�r�r�r�r�r�r�r!r�<module>rs����	���	��!� ���5�9�
"�
�
&�
�1�����g����!��h'�h'�V
0
�x� � �0
�f=�*�<�*2�
2r!

Zerion Mini Shell 1.0