Your IP : 216.73.217.13


Current Path : /usr/lib/python3/dist-packages/cloudinit/net/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/cloudinit/net/__pycache__/__init__.cpython-38.pyc

U

�Ad;��@stddlZddlZddlZddlZddlZddlZddlmZmZm	Z	m
Z
mZddlm
Z
ddlmZmZddlmZmZe�e�ZdZdZdd	d
dgZdd
dddddddddgZe�d�fdd�Zdd�Zd�dd�Zd�dd �Zd�d!d"�Z d#d$�Z!d%d&�Z"d'd(�Z#d)d*�Z$d+d,�Z%d-d.�Z&d/d0�Z'ej(dd1�e)d2�d3d4��Z*ej(dd1�e+d2�d5d6��Z,e-e)d7�d8d9�Z.d�d:d;�Z/d<d=�Z0d>d?�Z1d�e)d2�d@dA�Z2d�dBdC�Z3d�dDdE�Z4dFdG�Z5dHdI�Z6dJdK�Z7dLdM�Z8dNdO�Z9GdPdQ�dQe:�Z;dRdS�Z<d�ee
e-e
e-dT�dUdV�Z=d�ee
e-ee-dT�dWdX�Z>d�ee
e-e
e-dT�dYdZ�Z?d�ee
e-ee-dT�d[d\�Z@d�ee
e-e
e-dT�d]d^�ZAd�ee
e-ee-dT�d_d`�ZBd�ee
e-e
e-dT�dadb�ZCd�ee
e-ee-dT�dcdd�ZDd�dedf�ZEdgdh�ZFd�djdk�ZGd�dmdn�ZHd�dodp�ZIdqdr�ZJdsdt�ZKd�eLd2�dudv�ZMe-ee-dw�dxdy�ZNd�eLd2�dzd{�ZOd�eLd2�d|d}�ZPd�eLd2�d~d�ZQd�eLd2�d�d��ZRd�e+d2�d�d��ZSd�d��ZTe	e-efe)d��d�d��ZUee-d��d�d��ZVe-e)d��d�d��ZWe-e)d��d�d��ZXe-e)d��d�d��ZYe-e)d��d�d��ZZe-e)d��d�d��Z[e-e)d��d�d��Z\e)d2�d�d��Z]e-d2�d�d��Z^e_d2�d�d��Z`e_d2�d�d��Zae-e-e-d��d�d��ZbGd�d��d�ec�ZddS)��N)�Any�Callable�Dict�List�Optional)�urlparse)�subp�util)�UrlError�readurlz/sys/class/net/Zeth0Zdhcp6Z
ipv6_slaaczipv6_dhcpv6-statelesszipv6_dhcpv6-stateful�	ovs-vsctlz--formatZcsvz
--no-headingsz	--timeoutZ10z	--columns�name�find�	interfacez
type=internalz([0-9]+)cCsdd�t�||�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'].cSs$g|]}|��rt|�n|���qS�)�isdigit�int�lower)�.0�textrr�8/usr/lib/python3/dist-packages/cloudinit/net/__init__.py�
<listcomp>3s�z$natural_sort_key.<locals>.<listcomp>)�re�split)�sZ_nsrerrr�natural_sort_key,s
�rcCstS)z3Simple function to return the global SYS_CLASS_NET.)�
SYS_CLASS_NETrrrr�get_sys_class_path9sr�cCst�|d|S)N�/)r��devname�pathrrr�sys_dev_path>sr#c

Cs
t||�}zt�|�}Wn�ttfk
r�}z^t|dd�}	|	tjtjfkrb|dk	rb||�WY�,S|	tj	fkr�|dk	r�||�WY�S�W5d}~XYnX|�
�}|dkr�|Sz
||WStk
�r}z,|dk	r�||�WY�St�
d||��W5d}~XYnXdS)N�errnoz5Found unexpected (not translatable) value '%s' in '%s)r#r	Z	load_file�OSError�IOError�getattrr$�ENOENTZENOTDIRZEINVAL�strip�KeyError�LOG�debug)
r!r"�	translate�	on_enoent�on_keyerror�	on_einvalZdev_path�contents�eZe_errnorrr�read_sys_netBs4

�r3cCsdd�}t||||||d�S)NcSsdS�NFr)r2rrr�
on_excp_falsehsz(read_sys_net_safe.<locals>.on_excp_false)r/r.r0r-)r3)�iface�fieldr-r5rrr�read_sys_net_safegs�r8cCs<t||�}|dkrdSz
t|�WStk
r6YdSXdSr4)r8r�
ValueError)r6r7�valrrr�read_sys_net_intus

r;cCsdddd�}t|d|d�S)NTF)�up�unknown�down�	operstate)r-�r8)r!r-rrr�is_upsrAcCstj�t|d��S)N�bridge��osr"�existsr#�r!rrr�	is_bridge�srGcCstj�t|d��S)N�bondingrCrFrrr�is_bond�srIcCs t|dd�}tj�|�r|SdS)z8Return the master path for devname, or None if no master�master�r"N)r#rDr"rEr rrr�
get_master�srLcCsHt|�}|dkrdStj�|d�}tj�|d�}tj�|�pFtj�|�S)z@Return a bool indicating if devname's master is a bridge or bondNFrHrB)rLrDr"�joinrE)r!�master_pathZbonding_pathZbridge_pathrrr�master_is_bridge_or_bond�srOcCs,t|�}|dkrdSt|dd�}tj�|�S)z;Return a bool indicating if devname's master is openvswitchNFzupper_ovs-systemrK)rLr#rDr"rE)r!rNZovs_pathrrr�master_is_openvswitch�s
rP)�maxsize)�returncCs tt�d��}|st�d�|S)zDReturn a bool indicating if Open vSwitch is installed in the system.rz<ovs-vsctl not in PATH; not detecting Open vSwitch interfaces)�boolrZwhichr+r,)�retrrr�openvswitch_is_installed�s�rUc
Csfzt�t�\}}WnFtjk
rX}z&d|jkrFt�d�gWY�S�W5d}~XYn
X|��SdS)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_CMDZProcessExecutionError�stderrr+�info�
splitlines)�out�_err�excrrr�get_ovs_internal_interfaces�s
�r])r!rRcCs,t�s
dSt�}||kr(t�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)rUr]r+r,)r!Zovs_bridgesrrr�!is_openvswitch_internal_interface�sr^cCs,|dkrt|�}t||�s$t||�r(dSdS)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!�driverrrr�is_netfailover�s�rdcCs,d}zt|d�}Wntk
r&YnX|S)zDReturns a str from reading /sys/class/net/<devname>/device/features.rzdevice/features)r3�	Exception�r!Zfeaturesrrr�get_dev_features�srgcCs(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)rg�lenrfrrr�has_netfail_standby_feature�srlcCs<t|�dk	rdS|dkr t|�}|dkr,dSt|�s8dSdS)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�rLr_rlrbrrr�is_netfail_master�s	rocCstt|dd�}tj�|�sdS|dkr,t|�}|dkr8dStj�tj�|��}t|�}|dkr`dSt|�}|spdSdS)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.
    rJrKFNrmT)r#rDr"rEr_�basename�realpathrl)r!rcZmaster_sysfs_pathZmaster_devnameZ
master_driverZmaster_has_standbyrrrr`sr`cCs<t|�dkrdS|dkr t|�}|dkr,dSt|�s8dSdS)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.
    NFrmTrnrbrrrra6s	racCst|d�}|r|dkrdSdS)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�4TFr@)r!rrrrr�
is_renamedNs	
rucCstt|d��}d|��kS)N�ueventzDEVTYPE=vlan)�strr8rY)r!rvrrr�is_vlan]srxcCs0d}t|d�}tj�|�r,tj�t�|��}|S)z8Return the device driver for net device named 'devname'.Nz
device/driver)r#rDr"�islinkrp�readlink)r!rcZdriver_pathrrrr_bs

r_cCst|d�}|dkrdS|S)z;Return the device id string for net device named 'devname'.z
device/deviceFNr@)r!Zdev_idrrr�device_devidms
r{c
Csjt��st��rtt����Szt�t��}Wn6t	k
rd}z|j
t
jkrRg}n�W5d}~XYnX|S�N)r	�
is_FreeBSD�is_DragonFlyBSD�list�get_interfaces_by_mac�valuesrD�listdirrr%r$r()�devsr2rrr�get_devicelistvsr�c@seZdZdZdS)�ParserErrorz6Raised when a parser has issue parsing a file/content.N)�__name__�
__module__�__qualname__�__doc__rrrrr��sr�cCs |rt|t�sdS|�d�dkS)NF�configZdisabled)�
isinstance�dict�get)�cfgrrr�is_disabled_cfg�sr�)�blacklist_driversrRcCs<t��st��rt|�St��s(t��r0t|�St|�SdS)zqGet the list of network interfaces viable for networking.

    @return List of interfaces, sorted naturally.
    N)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�rrr�find_candidate_nics�s
r�cCs<t��st��rt|�St��s(t��r0t|�St|�SdS)z.Get the name of the 'fallback' network device.N)r	r}r~�find_fallback_nic_on_freebsdr�r��&find_fallback_nic_on_netbsd_or_openbsd�find_fallback_nic_on_linuxr�rrr�find_fallback_nic�s
r�cCstt���td�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�rr�rrrr��sr�cCst|�}|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��namesrrrr��sr�cCs8t�ddddg�\}}|��}|r&|Stt���td�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�)rrr�r�r�r)r��stdoutZ_stderrr�rrrr��s
r�cCst|�}|r|dSdS)z�Get the 'fallback' network device name on FreeBSD.

    @param blacklist_drivers: Currently ignored.
    @return List of sorted interfaces.
    rN)r�r�rrrr��sr�cCs�|sg}dt��kr t�d�n<dd�t�D�}t|�r\t�d|�d}tjtj|tjd�g}g}t�D�]}|dkrzqjt|�}||kr�t�d	||�qjt	|d
�s�t�d|�qj|�
d�r�t�d
|�qjt|�r�t�d|�qjt|�r�t�d|�qjt
|��rt�d|�qjt|d�}|�r*|�|�qjt�d|�t|d�}|�rR|�|�qjt	|d�}	|	dk�rr|�|�qjt�d|�qjg}
||fD]:}t|td�}t|k�r�|�t�|�dt�|
|7}
�q�|
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/cmdlinecSs g|]}|dkrt|�s|�qS)�lo)ru)rZdevicerrrr�s�z0find_candidate_nics_on_linux.<locals>.<listcomp>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: %sZvethzIgnoring veth interface: %szIgnoring bridge interface: %szIgnoring bond interface: %szIgnoring failover interface: %s�carrierzInterface has no carrier: %s�dormantr?)r�r>Zlowerlayerdownr=zInterface ignored: %sr�r)r	Zget_cmdliner+r,r�rkZlog_timeZudevadm_settler_r8�
startswithrGrIrdr;�appendr�r�DEFAULT_PRIMARY_INTERFACE�remove�insert)r�Zunstable�msgZ	connectedZpossibly_connectedrrcr�r�r?Zsorted_interfacesZ
interfacesrrrr��s����











r�cCst|�}|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�rrrr�>sr�cCsx|sd}t|d�}|sdSt|�r,d|i}ndt|d���i}d||d�}|rft|�}|rf||d	d
<||idd�}|S)
zBGenerate network cfg v2 for dhcp on the NIC most likely connected.Fr�Nr
�
macaddressr�T)Zdhcp4�set-name�matchr�rc�)�	ethernets�version)r�ror8rr_)r�Z
config_driverZtarget_namer�r�rcZnconfrrr�generate_fallback_configMs"

�r�cCsJdd�}dd�}|�d�}|dkr*||�S|dkr:||�Std|��dS)	NcSs�g}|�di�D]|}|�d�dkr$q|�d�}|s4q|�d�}|�di��d�}|�di��d�}|snt|�}|szt|�}|�||||g�q|S)	Nr��typeZphysicalZmac_addressr
�paramsrc�	device_id)r�r_r{r�)�netcfg�physdevs�ent�macr
rcr�rrr�
_version_1hs 

z$extract_physdevs.<locals>._version_1cSs�g}|�di���D]z}|�d�}|s(q|�di��d�}|s@q|�di��d�}|�di��d�}|spt|�}|s|t|�}|�||||g�q|S)Nr�r�r�r�rcr�)r�r�r_r{r�)r�r�r�r
r�rcr�rrr�
_version_2zs 
z$extract_physdevs.<locals>._version_2r��r�z"Unknown network config version: %s)r��RuntimeError)r�r�r�r�rrr�extract_physdevsgs
r�FcCs*t|d�}|dkr"|rtd��dS|dkS)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_addressZaddr_assign_typeNz%s had no addr_assign_type.T)rr��)r;r9)�ifname�strictZassign_typerrr�interface_has_own_mac�s

r�Tc
Cs�i}t�D]*\}}}}d|||��|t|�d�||<q
|r�t�d�}tjdddddd	d
gdd�\}}tjdd
ddgdd�\}	}t�}
||	fD]}|
�|�|��q�|�	�D] }|ddkp�|d|
k|d<q�|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)�downabler�rcr�r
r<z[0-9]+:\s+(\w+)[@:]�ipz-6ZaddrZshowZ	permanentZscope�globalT�Zcapturez-4r<Fr
r�)
�get_interfacesrrAr�compiler�set�update�findallr�)
Zcheck_downable�cur_infor
r�rcr�ZnmatchZipv6r[Zipv4Znics_with_addressesZ	bytes_out�drrr�_get_current_rename_info�s.�	
�
�r�cs�t|�st�d�dS|dkr$t�}i�|��D]:\}}|��}|�d�rZ|d��|d<||d<|�|<q0t�d���fdd�}dd�}d	d
�}	dd�}
g}g}g}
|��}d
}d}dd����fdd�}|D�]�\}}}}|r�|��}g}||||�}|�s|r�|�d||f�q�|�d�}||k�r0q�|�sN|r�|�d||f�q�|d�r�d}|d�s�|r�|�||||f�q�d|d<|�d|||ff�|
�d|||ff�||k�rz||}|d�r
d}|d�s�|r�|�||||f�q�n|�d|||ff�d}|dk�s"||k�r6|d7}||}�q|�d||||ff�||d<|��}|d�rz|
�d|||ff�|�d|||d|ff�||d<|��}||7}q�||	|
d�}t|�t|
�dk�r�t|��r�t�d|�nt�d|�nzt�d |||
�||
D]^\}}}}z|�|�|�Wn<t	k
�rj}z|�d!|||||f�W5d}~XYnX�qt|��r�t	d"�
|���dS)#Nzno interfaces to renamer�r
zDetected interfaces %scstdd����D��S)Ncss|]}|d|fVqdS)r
Nr�r�datarrr�	<genexpr>�sz<_rename_interfaces.<locals>.update_byname.<locals>.<genexpr>)r�r�)Zbymac)r�rr�
update_byname�sz)_rename_interfaces.<locals>.update_bynamecSstjddd|d|gdd�dS)Nr��linkr�r
Tr��r)�cur�newrrr�rename�sz"_rename_interfaces.<locals>.renamecSstjddd|dgdd�dS)Nr�r�r�r>Tr�r��r
rrrr>�sz _rename_interfaces.<locals>.downcSstjddd|dgdd�dS)Nr�r�r�r<Tr�r�r�rrrr<�sz_rename_interfaces.<locals>.upz
cirename%d���cSsd|r0|r0|r0|d|ko.|d|ko.|d|kS|rP|rP|d|koN|d|kS|r`|d|kSdS)zmatch if set and in datar�rcr�Fr)r�r�rcr�rrr�entry_matchs
�
�z'_rename_interfaces.<locals>.entry_matchcsT����fdd����D�}t|�rPt|�dkrHd|���f}t|��|dSdS)Ncsg|]}�|����r|�qSrrr�)r�rcr�r�rrrs�z:_rename_interfaces.<locals>.find_entry.<locals>.<listcomp>r�zjFailed to match a single device. Matched devices "%s" with search values "(mac:%s driver:%s device_id:%s)"r)r�rkr9)r�rcr�r�r��r�r�)r�rcr�r�
find_entrys�
��z&_rename_interfaces.<locals>.find_entryz<[nic not present] Cannot rename mac=%s to %s, not available.r<z*[busy] Error renaming mac=%s from %s to %sr�Fr>z2[busy-target] Error renaming mac=%s from %s to %s.r�r�)r�r>r<rz(unable to do any work for renaming of %sz$no work necessary for renaming of %sz$achieving renaming of %s with ops %sz.[unknown] Error performing %s%s for %s, %s: %s�
)rkr+r,r��items�copyr�rr�rerM)�renamesZstrict_presentZstrict_busyZcurrent_infor
r�r�r�r�r>r<Zops�errorsZupsZ
cur_bynameZtmpname_fmtZtmpir�r��new_namercr�Zcur_opsZcur_namer��targetZtmp_nameZopmap�opr�r2rr�r�_rename_interfaces�s�


��

��







��
r�cCs$d}tj�t|d��rd}t||�S)z6Returns the string value of an interface's MAC Addressr�Z
bonding_slavezbonding_slave/perm_hwaddr)rDr"�isdirr#r8)r�r"rrr�get_interface_macxsr�cCs>t|d�dkr:t|�}|r6|r6|dd�|dd�}|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�Z32�$i��3N)r8r�)r�Zethernet_formatr�rrr�get_ib_interface_hwaddr�s
r�cCsLt��st��rt|d�St��r,t|d�St��r>t|d�St|d�SdS)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�rrrr��s����r�)r�rRcCs0t���D] \}}|��|��kr
|Sq
dSr|)r�r�r)r�Z
interface_macZinterface_namerrr�find_interface_name_from_mac�s
r�cCs>t�dddg�\}}dd�}dd�}dd	�|||��D�}|S)
Nr��-ar�css@d}|�d�D]&}|�d�r&||7}q|r0|V|}q|VdS)Nrr��	)rr�)rZZ
curr_block�linerrr�flatten�s

z1get_interfaces_by_mac_on_freebsd.<locals>.flattencss4|D]*}t�d|�}|r|�d�|�d�fVqdS)Nz2^(?P<ifname>\S*): .*ether\s(?P<mac>[\da-f:]{17}).*r�r�)r�search�group)Z	flat_list�block�mrrr�find_mac�s�z2get_interfaces_by_mac_on_freebsd.<locals>.find_maccSsi|]\}}||�qSrr)rr�r�rrr�
<dictcomp>�sz4get_interfaces_by_mac_on_freebsd.<locals>.<dictcomp>r�)r�rZ�_r�r�Zresultsrrrr��s
r�c	Csbi}d}t�ddg�\}}t�dd|���}|D],}t�||�}|r0|��}|d||d<q0|S)NzE(?P<ifname>\w+).*address:\s(?P<mac>([\da-f]{2}[:-]){5}([\da-f]{2})).*r�r��\n\s+� r�r��rr�subrYr��	groupdict�	r�rTZre_field_matchrZr�Zif_linesr�r�Zfieldsrrrr��s�r�c	Csbi}d}t�ddg�\}}t�dd|���}|D],}t�||�}|r0|��}|d||d<q0|S)NzC(?P<ifname>\w+).*lladdr\s(?P<mac>([\da-f]{2}[:-]){5}([\da-f]{2})).*r�r�r�r�r�r�rrrrrr��s�r�c
	Csi}i}t|d�D�]\}}}}||kr�d}d||||f}|||kr�||dkrtt�|d||||f�q|dkr�d}t�|d|||||f�|dks�|dkr�t�d	||||�q|r�t|��|||<|||<t|d�}	|	r|	|k�r|||	<qt�d
|||	|	�q|S)zmBuild a dictionary of tuples {mac: name}.

    Bridges and any devices that have a 'stolen' mac are excluded.r�Tz6duplicate mac found! both '%s' and '%s' have mac '%s'.Z	hv_netvsczC Ignoring '%s' due to driver '%s' and '%s' having driver hv_netvsc.FZ
mscc_felixZ	fsl_enetcz>Ignoring duplicate macs from '%s' and '%s' due to driver '%s'.z^Ethernet and InfiniBand interfaces have the same address both '%s' and '%s' have address '%s'.)r�r+�warningr,r�r�)
r�rTZ
driver_mapr
r�rcZ_devidZraise_duplicate_mac_errorr��ib_macrrrr��sd�������


�r�cCs�g}|dkrg}t�}d�d�}|D]�}t|�s2q$t|�r<q$t|�rFq$t|�rPq$t|�dk	rnt|�snt|�snq$t	|�rxq$t
|�}|s�q$|dkr�||dt|��kr�q$t|�r�q$t
|�}||kr�q$|�|||t|�f�q$|S)z�Return list of interface tuples (name, mac, driver, device_id)

    Bridges and any devices that have a 'stolen' mac are excluded.N�:)�00rrrrrrrrrrrrrrrr�)r�rMr�rGrxrIrLrOrPrdr�rkr^r_r�r{)r�rTr�Zzero_macr
r�rcrrrr�IsF
��r�cCsPi}t�D]@\}}}}t|d�}|r
||krBtd||||f��|||<q
|S)zTBuild a dictionary mapping Infiniband interface names to their hardware
    address.Fz5duplicate mac found! both '%s' and '%s' have mac '%s')r�r�r�)rTr
r�rrrr�get_ib_hwaddrs_by_interfacets
��
r)�url_datarRc
Cs�d|krt�d|�dS|d}z8t|�}t|jdk|jdkg�sVt�d|j�WdSWn4tk
r�}zt�d|�WY�dSd}~XYnXd	|kr�d
|d	<ztf|�Wntk
r�YdSXdS)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 %sFZhttpZhttpsz2Ignoring connectivity check. Invalid URL scheme %sz+Ignoring connectivity check. Invalid URL %sNZtimeout�T)r+rr�anyZschemer9rr
)r	r
�result�errrrr�has_url_connectivity�s2
��
r)�convert_to_addressr�cKs*z||f|�WStk
r$YdSXdS)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

    FN)r9)rr��kwargsrrr�maybe_get_address�s
r)r�rRcCstttj|��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�r�rrr�
is_ip_address�s	rcCstttj|��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.
    )rSrrZIPv4Addressrrrr�is_ipv4_address�s	rcCstttj|��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.
    )rSrrZIPv6Addressrrrr�is_ipv6_address�s	rcCstttj|dd��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�)rSrr�
ip_networkrrrr�
is_ip_network�s	rcCstttj|dd��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)rSrr�IPv4Networkrrrr�is_ipv4_network�s	�rcCstttj|dd��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)rSrrZIPv6Networkrrrr�is_ipv6_network�s	�rcCs@|d�d�s|dtkrdS|ddkr<t|�d��r<dSdS)z:Common helper for checking network_state subnets for ipv6.r��6TZstaticr�F)�endswith�IPV6_DYNAMIC_TYPESrr�)Zsubnetrrr�subnet_is_ipv6
s
r"cCstt�d|���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/)rwrr�netmask)�prefixrrr�net_prefix_to_ipv4_masksr&cCst�d|���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#)rr�	prefixlen)�maskrrr�ipv4_mask_to_net_prefixs	r)cCs�zt�d|���j}|WStk
r,YnXt�|�}t|�}|dkrL|Sttj||d@���}||?}tj|}d|>d}||kr�td|��|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::/rr�zInvalid network mask '%s')	rrr'r9rr�minZ
IPV6LENGTH�
bit_length)r(r'r$Zmask_intZtrailing_zeroesZleading_onesZall_onesrrr�ipv6_mask_to_net_prefix+s&
�
r,)r(r�rRcCsttj|�d|��dd�j�S)zCGet string representation of broadcast address from an ip/mask pairrFr)rwrrZbroadcast_address)r(r�rrr�mask_and_ipv4_to_bcast_addrNs�r-c@seZdZdS)�RendererNotFoundErrorN)r�r�r�rrrrr.Usr.)r)NNNN)N)N)N)N)N)N)N)N)N)N)N)N)N)NN)F)T)TTN)N)N)N)N)N)N)er$�	functoolsrZloggingrDr�typingrrrrrZurllib.parserZ	cloudinitrr	Zcloudinit.url_helperr
rZ	getLoggerr�r+rr�r!rVr�rrr#r3r8r;rArGrIrLrOrP�	lru_cacherSrUrr]rwr^rdrgrlror`rarurxr_r{r�rer�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrrrr"r&rr)r,r-r�r.rrrr�<module>s
��

�
%


	






!
	�
��
�
�
��
��
��
��
�[�
�
0

/�
 
c+'	#