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

�

\�`f<����ddlZddlZddlZddlZddlZddlZddlmZmZm	Z	m
Z
mZmZddl
mZddlmZmZddlmZmZej*e�ZdZdZgd�Zgd	�Zej8d
�fd�Zd�Zdcd
�Z				ddd�Z ded�Z!d�Z"d�Z#d�Z$d�Z%d�Z&d�Z'd�Z(d�Z)ejTd��de+fd��Z,ejTd��de-fd��Z.de/de+fd�Z0ded�Z1d�Z2d �Z3dede+fd!�Z4ded"�Z5ded#�Z6d$�Z7d%�Z8d&�Z9d'�Z:d(�Z;Gd)�d*e<�Z=d+�Z>de
e/fd,�Z?dee/fd-�Z@de
e/fd.�ZAdee/fd/�ZBde
e/fd0�ZCdee/fd1�ZDde
e/fd2�ZEdee/fd3�ZFded4�ZGd5�ZHdfd6�ZIdgd7�ZJ	dhd8�ZKd9�ZLd:�ZMdeNfd;�ZOd<e/dee/fd=�ZPdeNfd>�ZQdeNfd?�ZRdeNfd@�ZSdeNfdA�ZT							didBe+dCe+dDe+dEe+dFe+dGe+dHe+de-fdI�ZUdJedKdLe
ee/e/e/e/fddfdM�ZVdN�ZWdOe	e/efde+fdP�ZXdQedRe/fdS�ZYdRe/de+fdT�ZZdRe/de+fdU�Z[dRe/de+fdV�Z\dRe/de+fdW�Z]dRe/de+fdX�Z^dRe/de+fdY�Z_de+fdZ�Z`de/fd[�Zadebfd\�Zcdebfd]�Zdd^e/d_e/de/fd`�ZeGda�dbef�Zgy)j�N)�Any�Callable�Dict�List�Optional�Tuple)�urlparse)�subp�util)�UrlError�readurlz/sys/class/net/�eth0)�dhcp6�
ipv6_slaaczipv6_dhcpv6-statelesszipv6_dhcpv6-stateful)�	ovs-vsctlz--format�csvz
--no-headingsz	--timeout�10z	--columns�name�find�	interfacez
type=internalz([0-9]+)c��tj||�D�cgc]-}|j�rt|�n|j	���/c}Scc}w)aDSorting for Humans: natural sort order. Can be use as the key to sort
    functions.
    This will sort ['eth0', 'ens3', 'ens10', 'ens12', 'ens8', 'ens0'] as
    ['ens0', 'ens3', 'ens8', 'ens10', 'ens12', 'eth0'] instead of the simple
    python way which will produce ['ens0', 'ens10', 'ens12', 'ens3', 'ens8',
    'eth0'].)�re�split�isdigit�int�lower)�s�_nsre�texts   �8/usr/lib/python3/dist-packages/cloudinit/net/__init__.py�natural_sort_keyr!,sF���H�H�U�A�&����\�\�^��D�	�����5����s�2Ac��tS)z3Simple function to return the global SYS_CLASS_NET.)�
SYS_CLASS_NET��r �get_sys_class_pathr&9s���r%c�(�t�|zdz|zS)N�/)r&��devname�paths  r �sys_dev_pathr,>s����'�)�C�/�$�6�6r%c���t||�}	tj|�}|j�}|�|S	||S#ttf$rf}t|dd�}	|	tjtjfvr|�
||�cYd}~S|	tjfvr|�
||�cYd}~S�d}~wwxYw#t$r,}|�
||�cYd}~Stjd||��d}~wwxYw)N�errnoz5Found unexpected (not translatable) value '%s' in '%s)r,r�load_text_file�OSError�IOError�getattrr.�ENOENT�ENOTDIR�EINVAL�strip�KeyError�LOG�debug)
r*r+�	translate�	on_enoent�on_keyerror�	on_einval�dev_path�contents�e�e_errnos
          r �read_sys_netrBBs����G�T�*�H�
��&�&�x�0���~�~��H��������"�"��
�W����!�W�d�+���u�|�|�U�]�]�3�3��$� ��|�#��u�|�|�o�%��$� ��|�#�
�����	��"��q�>�!��I�I�G���
�

��	�sP�=�B5�B2�8B-�B2�
B-�&B2�,B-�-B2�5	C*�>	C%�C*�
C%�%C*c�*�d�}t||||||��S)Nc��y�NFr$)r@s r �
on_excp_falsez(read_sys_net_safe.<locals>.on_excp_falsehs��r%)r<r;r=r:)rB)�iface�fieldr:rFs    r �read_sys_net_saferIgs(����
�
�!����
�r%c�Z�t||�}|dury	t|�S#t$rYywxYwrE)rIr�
ValueError)rGrH�vals   r �read_sys_net_intrMus8��
�E�5�
)�C�
�e�|����3�x�������s�
�	*�*c�*�dddd�}t|d|��S)NTF)�up�unknown�down�	operstate)r:�rI)r*r:s  r �is_uprTs����e�<�I��W�k�Y�G�Gr%c�T�tjjt|d��S)N�bridge��osr+�existsr,�r*s r �	is_bridger[�s��
�7�7�>�>�,�w��9�:�:r%c�T�tjjt|d��S)N�bondingrWrZs r �is_bondr^�s��
�7�7�>�>�,�w�	�:�;�;r%c�`�t|d��}tjj|�r|Sy)z8Return the master path for devname, or None if no master�master�r+N)r,rXr+rYr)s  r �
get_masterrb�s&����h�/�D�	�w�w�~�~�d����r%c��t|�}|�ytjj|d�}tjj|d�}tjj	|�xstjj	|�S)z@Return a bool indicating if devname's master is a bridge or bondFr]rV)rbrXr+�joinrY)r*�master_path�bonding_path�bridge_paths    r �master_is_bridge_or_bondrh�sb���W�%�K�����7�7�<�<��Y�7�L��'�'�,�,�{�H�5�K�
�7�7�>�>�,�'�F�2�7�7�>�>�+�+F�Fr%c�v�t|�}|�yt|d��}tjj	|�S)z;Return a bool indicating if devname's master is openvswitchFzupper_ovs-systemra)rbr,rXr+rY)r*re�ovs_paths   r �master_is_openvswitchrk�s5���W�%�K�����G�*<�=�H�
�7�7�>�>�(�#�#r%c� �t|d�dk(S)N�type�32rSrZs r �is_ib_interfacero�s���W�f�-��5�5r%)�maxsize�returnc�p�ttjd��}|stj	d�|S)zDReturn a bool indicating if Open vSwitch is installed in the system.rz<ovs-vsctl not in PATH; not detecting Open vSwitch interfaces)�boolr
�whichr8r9)�rets r �openvswitch_is_installedrv�s0���t�z�z�+�&�
'�C���	�	�J�	
��Jr%c���	tjt�\}}|j�S#tj$r0}d|jvrt
j
d�gcYd}~S�d}~wwxYw)z�Return a list of the names of OVS internal interfaces on the system.

    These will all be strings, and are used to exclude OVS-specific interface
    from cloud-init's network configuration handling.
    zdatabase connection failedzJOpen vSwitch is not yet up; no interfaces will be detected as OVS-internalN)r
�!OVS_INTERNAL_INTERFACE_LOOKUP_CMD�
splitlines�ProcessExecutionError�stderrr8�info)�out�_err�excs   r �get_ovs_internal_interfacesr��sh�� ��I�I�?�@�	��T��~�~�����%�%��'�3�:�:�5��H�H� �
��I�
���s!�.�A1�$A,�%A1�+A,�,A1r*c�d�t�syt�}||vrtjd|�yy)z�Returns True if this is an OVS internal interface.

    If OVS is not installed or not yet running, this will return False.
    FzDetected %s as an OVS interfaceT)rvr�r8r9)r*�ovs_bridgess  r �!is_openvswitch_internal_interfacer��s2��
$�%��-�/�K��+���	�	�3�W�=��r%c�P�|�t|�}t||�st||�ryy)z�netfailover driver uses 3 nics, master, primary and standby.
    this returns True if the device is either the primary or standby
    as these devices are to be ignored.
    TF)�
device_driver�is_netfail_primary�is_netfail_standby�r*�drivers  r �is_netfailoverr��s2��
�~��w�'���'�6�*�.@���/��r%c�D�d}	t|d�}|S#t$rY|SwxYw)zDReturns a str from reading /sys/class/net/<devname>/device/features.�zdevice/features)rB�	Exception�r*�featuress  r �get_dev_featuresr��s9���H�
���):�;���O���
���O�
�s��	�c�J�t|�}|rt|�dkry|ddk(S)z� Return True if VIRTIO_NET_F_STANDBY bit (62) is set.

    https://github.com/torvalds/linux/blob/         089cf7f6ecb266b6a4164919a2e69bd2f938374a/         include/uapi/linux/virtio_net.h#L60
    �@F�>�1)r��lenr�s  r �has_netfail_standby_featurer��s.�� ��(�H��s�8�}�r�)���B�<�3��r%c�Z�t|��y|�t|�}|dk7ryt|�syy)z�A device is a "netfail master" device if:

    - The device does NOT have the 'master' sysfs attribute
    - The device driver is 'virtio_net'
    - The device has the standby feature bit set

    Return True if all of the above is True.
    F�
virtio_netT�rbr�r�r�s  r �is_netfail_masterr�s:���'��&��
�~��w�'��
����&�w�/��r%c�:�t|d��}tjj|�sy|�t	|�}|dk(rytjjtjj
|��}t	|�}|dk7ryt|�}|syy)a7A device is a "netfail primary" device if:

    - the device has a 'master' sysfs file
    - the device driver is not 'virtio_net'
    - the 'master' sysfs file points to device with virtio_net driver
    - the 'master' device has the 'standby' feature bit set

    Return True if all of the above is True.
    r`raFr�T)r,rXr+rYr��basename�realpathr�)r*r��master_sysfs_path�master_devname�
master_driver�master_has_standbys      r r�r�s���%�W�8�<��
�7�7�>�>�+�,��
�~��w�'��
�����W�W�%�%�b�g�g�&6�&6�7H�&I�J�N�!�.�1�M���$��4�^�D����r%c�Z�t|��y|�t|�}|dk7ryt|�syy)z�A device is a "netfail standby" device if:

    - The device has a 'master' sysfs attribute
    - The device driver is 'virtio_net'
    - The device has the standby feature bit set

    Return True if all of the above is True.
    Fr�Tr�r�s  r r�r�:s:���'��"��
�~��w�'��
����&�w�/��r%c�*�t|d�}|r|dvryy)a�
    /* interface name assignment types (sysfs name_assign_type attribute) */
    #define NET_NAME_UNKNOWN      0  /* unknown origin (not exposed to user) */
    #define NET_NAME_ENUM         1  /* enumerated by kernel */
    #define NET_NAME_PREDICTABLE  2  /* predictably named by the kernel */
    #define NET_NAME_USER         3  /* provided by user-space */
    #define NET_NAME_RENAMED      4  /* renamed by user-space */
    �name_assign_type)�3�4TFrS)r*r�s  r �
is_renamedr�Rs#��)��2D�E���,�
�:��r%c�P�tt|d��}d|j�vS)N�ueventzDEVTYPE=vlan)�strrIry)r*r�s  r �is_vlanr�as(��
�"�7�H�5�
6�F��V�.�.�0�0�0r%c���d}t|d�}tjj|�r2tjj	tj
|��}|S)z8Return the device driver for net device named 'devname'.Nz
device/driver)r,rXr+�islinkr��readlink)r*r��driver_paths   r r�r�fsE��
�F��w��8�K�	�w�w�~�~�k�"����!�!�"�+�+�k�":�;���Mr%c�(�t|d�}|dury|S)z;Return the device id string for net device named 'devname'.z
device/deviceFNrS)r*�dev_ids  r �device_devidr�qs��
�w��
8�F�
�����Mr%c�D�tj�stj�r!tt	�j��S	t
jt��}|S#t$r,}|jtjk(rg}n�Yd}~|Sd}~wwxYw�N)r�
is_FreeBSD�is_DragonFlyBSD�list�get_interfaces_by_mac�valuesrX�listdirr&r0r.r3)�devsr@s  r �get_devicelistr�zs�������D�0�0�2��)�+�2�2�4�5�5���z�z�,�.�/���K�����7�7�e�l�l�"��D��
��K���s�A*�*	B�3!B�Bc��eZdZdZy)�ParserErrorz6Raised when a parser has issue parsing a file/content.N)�__name__�
__module__�__qualname__�__doc__r$r%r r�r��s��@r%r�c�P�|rt|t�sy|jd�dk(S)NF�config�disabled)�
isinstance�dict�get)�cfgs r �is_disabled_cfgr��s%���j��d�+���7�7�8��
�*�*r%c���tj�stj�r
t�Stj�stj
�r
t
�St�S)zqGet the list of network interfaces viable for networking.

    @return List of interfaces, sorted naturally.
    )rr�r��find_candidate_nics_on_freebsd�	is_NetBSD�
is_OpenBSD�(find_candidate_nics_on_netbsd_or_openbsd�find_candidate_nics_on_linuxr$r%r �find_candidate_nicsr��sG��
����D�0�0�2�-�/�/�	
���	�T�_�_�.�7�9�9�+�-�-r%c���tj�stj�r
t�Stj�stj
�r
t
�St�S)z.Get the name of the 'fallback' network device.)rr�r��find_fallback_nic_on_freebsdr�r��&find_fallback_nic_on_netbsd_or_openbsd�find_fallback_nic_on_linuxr$r%r �find_fallback_nicr��sE������D�0�0�2�+�-�-�	
���	�T�_�_�.�5�7�7�)�+�+r%c�P�tt�j�t��S)zmGet the names of the candidate network devices on NetBSD/OpenBSD.

    @return list of sorted interfaces
    ��key)�sortedr�r�r!r$r%r r�r��s��
�'�)�0�0�2�8H�I�Ir%c�&�t�}|r|dSy)zfGet the 'fallback' network device name on NetBSD/OpenBSD.

    @return default interface, or None
    rN)r���namess r r�r��s��

5�6�E���Q�x��r%c��tjgd��\}}|j�}|r|Stt�j	�t
��S)zgGet the names of the candidate network devices on FreeBSD.

    @return List of sorted interfaces.
    )�ifconfigz-lz-u�etherr�)r
rr�r�r�r!)�stdout�_stderrr�s   r r�r��sG��
�i�i� A�B�O�F�G�
�\�\�^�F�
��
��'�)�0�0�2�8H�I�Ir%c�&�t�}|r|dSy)z_Get the 'fallback' network device name on FreeBSD.

    @return List of sorted interfaces.
    rN)r�r�s r r�r��s��

+�,�E���Q�x��r%c���dtj�vrtjd�n~t	�D�cgc]}|dk7r
t|�s|��}}t
|�rLtjd|�d}tjtj|tj��g}g}tdddddd�	�D]�\}}}}|dk(r�|jd
�rtjd|��6t|d�}|r|j|��Vtjd
|�t|d�}|r|j|���t|d�}	|	dvr|j|���tjd|���g}
||fD]K}t|t��}t |vr+|j#t �|j%dt �|
|z
}
�M|
Scc}w)zeGet the names of the candidate network devices on Linux.

    @return List of sorted interfaces.
    z
net.ifnames=0z9Stable ifnames disabled by net.ifnames=0 in /proc/cmdline�loz4Found unstable nic names: %s; calling udevadm settlez!Waiting for udev events to settle)�funcFT)�filter_openvswitch_internal�2filter_slave_if_master_not_bridge_bond_openvswitch�filter_vlan�filter_without_own_mac�filter_zero_mac�log_filtered_reasons�vethzIgnoring veth interface: %s�carrierzInterface has no carrier: %s�dormantrR)r�rQ�lowerlayerdownrPzInterface ignored: %sr�r)r�get_cmdliner8r9r�r�r��log_time�udevadm_settle�get_interfaces�
startswithrM�appendrIr�r!�DEFAULT_PRIMARY_INTERFACE�remove�insert)�device�unstable�msg�	connected�possibly_connectedr�_r�r�rR�sorted_interfaces�
interfacess            r r�r��s���
�$�*�*�,�,��	�	�M�N�)�*�
����~�j��&8�
�
��
�
�x�=��I�I�F��
�6�C��M�M�#�)�)�S�t�/B�/B�C��I���,�$)�;@��$��!�
�6��	�1�a����������'��I�I�3�Y�?��"�9�i�8������Y�'���	�	�0�)�<�#�9�i�8����%�%�i�0��%�i��=�	��H�H��%�%�i�0���	�	�)�9�5�=6�J�� �"4�5�(�
��J�,<�=�
�$�
�2����7�8����a�!:�;��Z�'��(����}
s�Gc�&�t�}|r|dSy)z]Get the 'fallback' network device name on Linux.

    @return List of sorted interfaces.
    rN)r�r�s r r�r�!s��

)�*�E���Q�x��r%c���|sd}t�}|syt|�rd|i}ndt|d�j�i}dd||d�}|rt	|�}|r||dd	<||id
d�}|S)zBGenerate network cfg v2 for dhcp on the NIC most likely connected.FNr�
macaddress�addressT)�dhcp4r�set-name�matchrr��)�	ethernets�version)r�r�rIrr�)�
config_driver�target_namerr�r��nconfs      r �generate_fallback_configr-s�����
�#�%�K�����%���%��
�+�K��C�I�I�K�
������	�C���{�+���%+�C��L��"�&��,��;�E��Lr%c��d�}d�}|jd�}|dk(r||�S|dk(r||�Std|z��)Nc��g}|jdi�D]�}|jd�dk7r�|jd�}|s�,|jd�}|jdi�jd�}|jdi�jd�}|st|�}|st|�}|j||||g���|S)	Nr�rm�physical�mac_addressr�paramsr��	device_id)r�r�r�r�)�netcfg�physdevs�ent�macrr�rs       r �
_version_1z$extract_physdevs.<locals>._version_1Ms������:�:�h��+�
	<�C��w�w�v��*�,���'�'�-�(�C����7�7�6�?�D��W�W�X�r�*�.�.�x�8�F�����"�-�1�1�+�>�I��&�t�,���(��.�	��O�O�S�$��	�:�;�
	<��r%c��g}|jdi�j�D]�}|jd�}|s�|jdi�jd�}|s�;|jdi�jd�}|jdi�jd�}|st|�}|st|�}|j	||||g���|S)Nr
rrrr�r)r�r�r�r�r�)rrrrrr�rs       r �
_version_2z$extract_physdevs.<locals>._version_2_s������:�:�k�2�.�5�5�7�	<�C��7�7�:�&�D����'�'�'�2�&�*�*�<�8�C����W�W�W�b�)�-�-�h�7�F������,�0�0��=�I��&�t�,���(��.�	��O�O�S�$��	�:�;�	<� �r%r�r	z"Unknown network config version: %s)r��RuntimeError)rrrrs    r �extract_physdevsrLsQ���$�(�j�j��#�G��!�|��&�!�!�	�A���&�!�!�
�;�g�E�
F�Fr%c�B�t|d�}|�|rtd��y|dvS)a�return True if the provided interface has its own address.

    Based on addr_assign_type in /sys.  Return true for any interface
    that does not have a 'stolen' address. Examples of such devices
    are bonds or vlans that inherit their mac from another device.
    Possible values are:
      0: permanent address    2: stolen from another device
      1: randomly generated   3: set using dev_set_mac_address�addr_assign_typez%s had no addr_assign_type.T)rr�)rMrK)�ifname�strict�assign_types   r �interface_has_own_macr&|s6��#�6�+=�>�K�����:�;�;���)�#�#r%c	���i}t�D]*\}}}}d|||j�|t|�d�||<�,|r�tjd�}tj
gd�d��\}}tj
gd�d��\}	}t
�}
||	fD]"}|
j|j|���$|j�D]}|dd	uxs|d
|
v|d<�|S)a�Collect information necessary for rename_interfaces.

    returns a dictionary by mac address like:
       {name:
         {
          'downable': None or boolean indicating that the
                      device has only automatically assigned ip addrs.
          'device_id': Device id value (if it has one)
          'driver': Device driver (if it has one)
          'mac': mac address (in lower case)
          'name': name
          'up': boolean: is_up(name)
         }}
    N)�downablerr�rrrOz[0-9]+:\s+(\w+)[@:])�ipz-6�addr�show�	permanent�scope�globalT��capture)r)z-4r*r+rOFrr()
r�rrTr�compiler
�set�update�findallr�)
�check_downable�cur_inforrr�r�nmatch�ipv6r~�ipv4�nics_with_addresses�	bytes_out�ds
             r �_get_current_rename_infor=�s���H�*8�*:�
�&��s�F�I��"���9�9�;����+�

����
�����2�3���Y�Y�H��
�
��d��Y�Y�;�T�J�
��d�!�e�����	B�I��&�&�v�~�~�i�'@�A�	B����"�	�A��$��5� �H�A�f�I�5H�$H�
�j�M�	�
�Or%c
��� �t|�stjd�y|�
t�}i�|j	�D]F\}}|j�}|j
d�r|dj�|d<||d<|�|<�Htjd���fd�}d�}d�}	d�}
g}g}g}
|��}d	}d
}d�� �� fd�}|D�]�\}}}}|r|j�}g}||||�}|s|r|jd
|�d|�d���D|j
d�}||k(r�[|s|r|jd
|�d|�d���x|drRd}|ds|r|j||||fz���d|d<|jd|||ff�|
jd|||ff�||vr�||}|dr7d}|ds|r|j||||fz���|jd|||ff�d}|�||vr|dz
}||z}|��
||vr�|jd||||ff�||d<|��}|dr|
jd|||ff�|jd|||d|ff�||d<|��}||z
}���||	|
d�}t|�t|
�zdk(r:t|�rtjd||�nUtjd|�n>tjd|||
z�||
zD]\}}}}	|j
|�|��t|�rtd!j|���y#t$r)}|jd|�|�d|�d|�d |��	�Yd}~�rd}~wwxYw)"Nzno interfaces to renamerrzDetected interfaces %sc�D��td��j�D��S)Nc3�*K�|]}|d|f���
y�w)rNr$)�.0�datas  r �	<genexpr>z<_rename_interfaces.<locals>.update_byname.<locals>.<genexpr>�s����G�T�T�&�\�4�(�G�s�)r�r�)�bymacr6s �r �
update_bynamez)_rename_interfaces.<locals>.update_byname�s����G�X�_�_�5F�G�G�Gr%c�>�tjddd|d|gd��y)Nr)�linkr2rTr/�r
)�cur�news  r �renamez"_rename_interfaces.<locals>.rename�s���	�	�4����V�S�9�4�Hr%c�<�tjddd|dgd��y)Nr)rGr2rQTr/rH�rs r rQz _rename_interfaces.<locals>.down�s���	�	�4����f�5�t�Dr%c�<�tjddd|dgd��y)Nr)rGr2rOTr/rHrMs r rOz_rename_interfaces.<locals>.up�s���	�	�4����d�3�T�Br%z
cirename%d���c��|r |r|r|d|k(xr|d|k(xr|d|k(S|r|r|d|k(xr|d|k(S|r|d|k(Sy)zmatch if set and in datarr�rFr$)rBrr�rs    r �entry_matchz'_rename_interfaces.<locals>.entry_match�sv���6�i��U��s�"�3���N�f�,�3���%��2�
�
�V���;�#�%�B�$�x�.�F�*B�B�
���;�#�%�%�r%c	�����j�D�cgc]}�||||�r|��}}t|�r-t|�dkDrd|�d|�d|�d|�d�	}t|��|dSycc}w)Nrz2Failed to match a single device. Matched devices "z" with search values "(mac:z driver:z device_id:z)"r)r�r�rK)rr�rrBrr�r6rQs      ��r �
find_entryz&_rename_interfaces.<locals>.find_entry�s}���!���)�
���4��f�i�8�
�
��
�
�u�:��5�z�A�~��c�6�9�6��
!��o�%���8�O���
s�A#z$[nic not present] Cannot rename mac=z to z, not available.rOz*[busy] Error renaming mac=%s from %s to %sr(FrQz2[busy-target] Error renaming mac=%s from %s to %s.rrK)rKrQrOrz1Unable to rename interfaces: %s due to errors: %sz$no work necessary for renaming of %szRenamed %s with ops %sznknown] Error performing z for z, z: �
)
r�r8r9r=�items�copyr�rr��warningr�rrd)!�renames�strict_present�strict_busy�current_inforrBrIrErKrQrO�ops�errors�ups�
cur_byname�tmpname_fmt�tmpirSr�new_namer�r�cur_ops�cur_namer��target�tmp_name�opmap�oprr@r6rQs!                               @@r �_rename_interfacesri�s�����w�<��	�	�+�,����/�1���H�"�(�(�*��
��d��i�i�k���7�7�5�>��U��)�)�+�C��J���F��������I�I�&��1�H�I�E�C�
�C�
�F�
�C��x�(�J��K�
�D�
��$-4�=�(��X�v�y���)�)�+�C�����f�i�0�����
�
�*-�x�9��
��7�7�6�?���x������
�
�*-�x�9��
��t�9�>�C��z�?���M�M�#��h��(A�"A�B���C��I��N�N�F�C��H�;�?�@��J�J��c�8�h�[�9�:��z�!���)�F��d�|�J���j�)�"��
�
�c�S�(�H�,E�&E�F���N�N�F�C��H�;�#G�H��H��"�h�*�&<���	��&��-���"�h�*�&<�
�N�N�H�c�8�h��5I�J�K�%�F�6�N�&�x�0�J��d�|��
�
�D�#�x�(��=�>�����#�x�#�f�+�x�1H�I�J���F��"�8�,�
��w���{=�~�t�2�6�E�
�3�x�#�c�(��a���v�;��K�K�C���
�
�I�I�<�g�F��	�	�*�G�S�3�Y�?�),�s��	�%�B��X�v�
���	�	�"�
�v�&�	��6�{��4�9�9�V�,�-�-���
�
��
�
��6�3��!�5����
�s�*L&�&	M�/M�Mc�t�d}tjjt|d��rd}t	||�S)z6Returns the string value of an interface's MAC Addressr�
bonding_slavezbonding_slave/perm_hwaddr)rXr+�isdirr,rI)r#r+s  r �get_interface_macrmas2���D�	�w�w�}�}�\�&�/�:�;�+���V�T�*�*r%c�Z�t|d�dk(rt|�}|r
|r|dd|ddz}|Sy)z�Returns the string value of an Infiniband interface's hardware
    address. If ethernet_format is True, an Ethernet MAC-style 6 byte
    representation of the address will be returned.
    rmrn�$i��3N)rIrm)r#�ethernet_formatrs   r �get_ib_interface_hwaddrrrksB�����(�D�0���'���?��b��+��B�C��(�C��
�1r%c���tj�stj�r
t�Stj�r
t�Stj�r
t�St�Sr�)	rr�r�� get_interfaces_by_mac_on_freebsdr��get_interfaces_by_mac_on_netbsdr�� get_interfaces_by_mac_on_openbsd�get_interfaces_by_mac_on_linuxr$r%r r�r�ysO������D�0�0�2�/�1�1�	
���	�.�0�0�	
���	�/�1�1�-�/�/r%rc��t�j�D]*\}}|j�|j�k(s�(|cSyr�)r�rUr)r�
interface_mac�interface_names   r �find_interface_name_from_macr{�sD��)>�)@�)F�)F�)H�"�%�
�~��9�9�;�-�-�-�/�/�!�!�"�r%c��tjgd��\}}d�}d�}|||��D��cic]\}}||��
}}}|Scc}}w)N)r��-ar�c3�K�d}|jd�D]!}|jd�r||z
}�|r|��|}�#|��y�w)Nr�rT�	)rr�)r}�
curr_block�lines   r �flattenz1get_interfaces_by_mac_on_freebsd.<locals>.flatten�sN�����
��I�I�d�O�	"�D����t�$��d�"�
��$�$�!�
�
	"���s�=?c3�K�|D]?}tjd|�}|s�|jd�|jd�f���Ay�w)Nz2^(?P<ifname>\S*): .*ether\s(?P<mac>[\da-f:]{17}).*rr#)r�search�group)�	flat_list�block�ms   r �find_macz2get_interfaces_by_mac_on_freebsd.<locals>.find_mac�sI�����	:�E��	�	�E�u��A���w�w�u�~�q�w�w�x�'8�9�9�	:�s
�A�'ArH)r}r�r�r�rr#�resultss       r rtrt�sP���y�y�4�5�H�S�!�	�:�/7�w�s�|�.D�E�{�s�F�s�F�{�E�G�E��N��Fs�
Ac��i}d}tjddg�\}}tjdd|�j�}|D]6}tj||�}|s�|j�}|d||d<�8|S)NzE(?P<ifname>\w+).*address:\s(?P<mac>([\da-f]{2}[:-]){5}([\da-f]{2})).*r�r}�\n\s+� r#r�r
r�subryr�	groupdict�ru�re_field_matchr}r��if_linesr�r��fieldss        r ruru����
�C�	6���y�y�*�d�+�,�H�S�!��v�v�h��S�)�4�4�6�H��2���H�H�^�T�*����[�[�]�F�!'��!1�C��u�
��	2�
�Jr%c��i}d}tjddg�\}}tjdd|�j�}|D]6}tj||�}|s�|j�}|d||d<�8|S)NzC(?P<ifname>\w+).*lladdr\s(?P<mac>([\da-f]{2}[:-]){5}([\da-f]{2})).*r�r}r�r�r#rr�r�s        r rvrv�r�r%c� �i}t�D]~\}}}}||vr:|dvrtjd||||��,d|�d||�d|�d�}t|��|||<t	|d�}|s�Z||vr|||<�dtjd||||���|S)	zmBuild a dictionary of tuples {mac: name}.

    Bridges and any devices that have a 'stolen' mac are excluded.)�	fsl_enetc�
mscc_felix�qmi_wwanz>Ignoring duplicate macs from '%s' and '%s' due to driver '%s'.�duplicate mac found! both '�' and '�' have mac 'z'.Tz^Ethernet and InfiniBand interfaces have the same address both '%s' and '%s' have address '%s'.)r�r8r9rrrrW)rurrr��_devidr��ib_macs       r rwrw�s����C�%3�%5�=�!��c�6�6��#�:��@�@��	�	�#����H����A���C����C�
�s�#�#���C��
)��t�4���*�S� �"��F�����=����K���o=�|�Jr%�filter_hyperv_vf_with_syntheticr�r�r�r�r�r�c	�`�|rtjnd�}g}t�}	djd�}
|	D]�}|rt	|�s�t|�r
|d|��&|rt
|�r�4t|�r
|d|��I|r"t|��t|�st|�s�mt|�r
|d|���t|�}|s
|d|���|r|d	k7r||
dt|�k(r��|rt|�r��t|�}
|j!|||
t#|�f���|rt%||�|S)
z�Return list of interface tuples (name, mac, driver, device_id)

    Bridges and any devices that have a 'stolen' mac are excluded.c��yr�r$)�argss r �<lambda>z get_interfaces.<locals>.<lambda>s�r%�:)�00r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�zIgnoring bridge interface: %szIgnoring bond interface: %sNzIgnoring failover interface: %sz"Ignoring interface without mac: %sr�)r8r9r�rdr&r[r�r^rbrhrkr�rmr�r�r�r�r��)filter_hyperv_vf_with_synthetic_interface)r�r�r�r�r�r�r��filtered_loggerrur��zero_macrrr�s              r r�r�s=��$8�c�i�i�=O�O�
�C���D��x�x��%�H��"<��!�*?��*E���T�?��;�T�B���7�4�=���4�=��9�4�@��>��4� �,�,�T�2�)�$�/���$���=�t�D����%����@�$�G���t�t�|��x�
�#�c�(�7K�0K��&�+L��,
�
��t�$���
�
�D�#�v�|�D�'9�:�;�E"<�J'�1�/�3�G��Jr%r�).Nrc���|D�cic]}|ddk(s�|d|d��}}|D�cgc]}|d|vr
|ddk7r|��}}|D])}|\}}}}	|d|||||�|j|��+ycc}wcc}w)a�Filter Hyper-V SR-IOV/VFs when used with synthetic hv_netvsc.

    Hyper-V's netvsc driver may register an SR-IOV/VF interface with a mac
    that matches the synthetic (hv_netvsc) interface.  This VF will be
    enslaved to the synthetic interface, but cloud-init may be racing this
    process.  The [perhaps-yet-to-be-enslaved] VF should never be directly
    configured, so we filter interfaces that duplicate any hv_netvsc mac
    address, as this the most reliable indicator that it is meant to be
    subordinate to the synthetic interface.

    VF drivers will be mlx4_core, mlx5_core, or mana.  However, given that
    this list of drivers has changed over time and mana's dependency on
    hv_netvsc is expected to be removed in the future, we no longer rely
    on these names. Note that this will not affect mlx4/5 instances outside
    of Hyper-V, as it only affects environments where hv_netvsc is present.
    r	�	hv_netvscrrzdIgnoring %r VF interface with driver %r due to synthetic hv_netvsc interface %r with mac address %r.N)r�)
r�r�i�hv_netvsc_mac_to_name�interfaces_to_removerrrr�r�s
          r r�r�Js���*'���!�A�$�+�*=��!��a��d�
����
��
��Q�4�(�(�Q�q�T�[�-@�	
����*�
%�	�(���c�6�1��
D���!�#�&��
	
�	���)�$�
%����s�
A-�A-�A2c
��i}t�D]7\}}}}t|d�}|s�||vrtd|�d||�d|�d���|||<�9|S)zTBuild a dictionary mapping Infiniband interface names to their hardware
    address.Fr�r�r��')r�rrr)rurr�r�s    r �get_ib_hwaddrs_by_interfacer�tsh��
�C�'�)��
��a��A�(��u�5�����}�"��S��[�&�2����C��I���Jr%�url_datac��d|vrtjd|�y|d}	t|�}t|jdk(|jdk(g�s!tjd|j�y	d	|vrd
|d	<	t
di|��y#t
$r }tjd|�Yd}~yd}~wwxYw#t$rYywxYw)
aDReturn true when the instance has access to the provided URL.

    Logs a warning if url is not the expected format.

    url_data is a dictionary of kwargs to send to readurl. E.g.:

    has_url_connectivity({
        "url": "http://example.invalid",
        "headers": {"some": "header"},
        "timeout": 10
    })
    �urlz4Ignoring connectivity check. No 'url' to check in %sF�http�httpsz2Ignoring connectivity check. Invalid URL scheme %sz+Ignoring connectivity check. Invalid URL %sN�timeout�Tr$)r8rWr	�any�schemerKr
r)r�r��result�errs    r �has_url_connectivityr��s���
�H�����B�H�	
��
�5�/�C�
��#����F�M�M�V�+�V�]�]�g�-E�F�G��K�K�D��
�
�
��H��� ��������(���������A�3�G���������s*�AB�B8�	B5�B0�0B5�8	C�C�convert_to_addressrc�4�	||fi|��S#t$rYywxYw)aUse a function to return an address. If conversion throws a ValueError
    exception return False.

    :param check_cb:
        Test function, must return a truthy value
    :param address:
        The string to test.

    :return:
        Address or False

    F)rK)r�r�kwargss   r �maybe_get_addressr��s)���!�'�4�V�4�4������s��	�c�H�tttj|��S)z�Returns a bool indicating if ``s`` is an IP address.

    :param address:
        The string to test.

    :return:
        A bool indicating if the string is an IP address or not.
    )rsr��	ipaddress�
ip_address�rs r �
is_ip_addressr��s���!�)�"6�"6��@�A�Ar%c�H�tttj|��S)z�Returns a bool indicating if ``s`` is an IPv4 address.

    :param address:
        The string to test.

    :return:
        A bool indicating if the string is an IPv4 address or not.
    )rsr�r��IPv4Addressr�s r �is_ipv4_addressr������!�)�"7�"7��A�B�Br%c�H�tttj|��S)z�Returns a bool indicating if ``s`` is an IPv6 address.

    :param address:
        The string to test.

    :return:
        A bool indicating if the string is an IPv4 address or not.
    )rsr�r��IPv6Addressr�s r �is_ipv6_addressr��r�r%c�L�tttj|d���S)z�Returns a bool indicating if ``s`` is an IPv4 or IPv6 network.

    :param address:
        The string to test.

    :return:
        A bool indicating if the string is an IPv4 address or not.
    F�r$)rsr�r��
ip_networkr�s r �
is_ip_networkr��s���!�)�"6�"6���N�O�Or%c�L�tttj|d���S)z�Returns a bool indicating if ``s`` is an IPv4 network.

    :param address:
        The string to test.

    :return:
        A bool indicating if the string is an IPv4 address or not.
    Fr�)rsr�r��IPv4Networkr�s r �is_ipv4_networkr���#����)�/�/���G��r%c�L�tttj|d���S)z�Returns a bool indicating if ``s`` is an IPv6 network.

    :param address:
        The string to test.

    :return:
        A bool indicating if the string is an IPv4 address or not.
    Fr�)rsr�r��IPv6Networkr�s r �is_ipv6_networkr��r�r%c��|djd�s|dtvry|ddk(rt|jd��ryy)z:Common helper for checking network_state subnets for ipv6.rm�6T�staticrF)�endswith�IPV6_DYNAMIC_TYPESr�r�)�subnets r �subnet_is_ipv6r�
sG���f�~���s�#�v�f�~�9K�'K��	���8�	#���
�
�9�8M�(N��r%c�X�ttjd|���j�S)z�Convert a network prefix to an ipv4 netmask.

    This is the inverse of ipv4_mask_to_net_prefix.
        24 -> "255.255.255.0"
    Also supports input as a string.�0.0.0.0/)r�r�r��netmask)�prefixs r �net_prefix_to_ipv4_maskr�s'���y�$�$�x��x�%8�9�A�A�B�Br%c�F�tjd|���jS)aConvert an ipv4 netmask into a network prefix length.

    If the input is already an integer or a string representation of
    an integer, then int(mask) will be returned.
       "255.255.255.0" => 24
       str(24)         => 24
       "24"            => 24
    r�)r�r��	prefixlen)�masks r �ipv4_mask_to_net_prefixr�!s"�����(�4�&� 1�2�<�<�<r%c��	tjd|���j}|S#t$rYnwxYwtj|�}t|�}|dk(r|St
tj||dz
zj��}||z	}tj|z
}d|zdz
}||k7rtd|z��|S)z�Convert an ipv6 netmask (very uncommon) or prefix (64) to prefix.

    If the input is already an integer or a string representation of
    an integer, then int(mask) will be returned.
       "ffff:ffff:ffff::"  => 48
       "48"                => 48
    z::/rrzInvalid network mask '%s')	r�r�r�rKr�r�min�
IPV6LENGTH�
bit_length)r�r�r��mask_int�trailing_zeroes�leading_ones�all_oness       r �ipv6_mask_to_net_prefixr�-s���
��(�(�3�t�f��6�@�@�	�����
�	
�
��
�"�"�4�(�G��7�|�H��1�}��������y�H�q�L�9�E�E�G��O���.�L��$�$��6�I��Y��!�#�H��x���4�t�;�<�<��s�#&�	2�2r�r)c�`�ttj|�d|��d��j�S)zCGet string representation of broadcast address from an ip/mask pairr(Fr�)r�r�r��broadcast_address)r�r)s  r �mask_and_ipv4_to_bcast_addrr�Ps/��������A�d�V�n�U�;�M�M��r%c��eZdZy)�RendererNotFoundErrorN)r�r�r�r$r%r r�r�Ws��r%r�)r�)NNNNr�)F)T)TTN)TTTTTTF)hr.�	functoolsr��loggingrXr�typingrrrrrr�urllib.parser	�	cloudinitr
r�cloudinit.url_helperrr
�	getLoggerr�r8r#r�r�rxr1r!r&r,rBrIrMrTr[r^rbrhrkro�	lru_cachersrvr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr&r=rirmrrr�r�r{rtrurvrwr�r�r�r�r�r�r�r�r�r�r�r�r�rr�r�r�rr�r$r%r �<module>r�s$��
����	�	�=�=�!� �2��g����!��!�
�"����%�!�)�b�j�j��4�
��
7�����
"�J��H�;�<��G�$�6�����T�"��$��#������T�"� �T� �#� �(�s��t����
��t��0�B�0�1�
���A�)�A�+�
.�T�#�Y�
.�,�8�C�=�,�J�$�s�)�J�	���
�	�J��S�	�J�	�h�s�m�	�F�d�3�i�F�R	�H�S�M�	��>-G�`$�(+�^BF�`.�F+��0�t�0��c��h�s�m���$��8
��
� 
�$�
� D��D�P-1�(,�?C��#'� �!&�9�%)�9�!%�9�9=�9��	9�
!�9��
9��9�
�9�x'%��i�(�'%��U�3��S�#�-�.�/�'%�
�'%�T
� $�4��S��>�$�d�$�N�(��S��&	B�3�	B�4�	B�	C�S�	C�T�	C�	C�S�	C�T�	C�	P�3�	P�4�	P��S��T���S��T���d��C�s�C�	=�S�	=� �S� �F�c��s��s��	�L�	r%

Zerion Mini Shell 1.0