404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@3.135.184.218: ~ $
3

�~�f��@sJddlZddlZddlZddlZddlZddlZddlmZmZm	Z	m
Z
mZmZddl
mZddlmZmZddlmZmZeje�ZdZdZdd	d
dgZdd
dddddddddgZejd�fdd�Zdd�Zd�dd�Zd�dd �Z d�d!d"�Z!d#d$�Z"d%d&�Z#d'd(�Z$d)d*�Z%d+d,�Z&d-d.�Z'd/d0�Z(d1d2�Z)ej*dd3�e+d4�d5d6��Z,ej*dd3�e-d4�d7d8��Z.e/e+d9�d:d;�Z0d�d<d=�Z1d>d?�Z2d@dA�Z3d�e+d4�dBdC�Z4d�dDdE�Z5d�dFdG�Z6dHdI�Z7dJdK�Z8dLdM�Z9dNdO�Z:dPdQ�Z;GdRdS�dSe<�Z=dTdU�Z>e
e/d4�dVdW�Z?ee/d4�dXdY�Z@e
e/d4�dZd[�ZAee/d4�d\d]�ZBe
e/d4�d^d_�ZCee/d4�d`da�ZDe
e/d4�dbdc�ZEee/d4�ddde�ZFd�dfdg�ZGdhdi�ZHd�dkdl�ZId�dndo�ZJd�dpdq�ZKdrds�ZLdtdu�ZMeNd4�dvdw�ZOe/ee/dx�dydz�ZPeNd4�d{d|�ZQeNd4�d}d~�ZReNd4�dd��ZSeNd4�d�d��ZTd�e+e+e+e+e+e+e+e-d��d�d��ZUed�e
ee/e/e/e/fdd��d�d��ZVd�d��ZWe	e/efe+d��d�d��ZXee/d��d�d��ZYe/e+d��d�d��ZZe/e+d��d�d��Z[e/e+d��d�d��Z\e/e+d��d�d��Z]e/e+d��d�d��Z^e/e+d��d�d��Z_e+d4�d�d��Z`e/d4�d�d��Zaebd4�d�d��Zcebd4�d�d��Zde/e/e/d��d�d��ZeGd�d��d�ef�ZgdS)��N)�Any�Callable�Dict�List�Optional�Tuple)�urlparse)�subp�util)�UrlError�readurlz/sys/class/net/Zeth0�dhcp6Z
ipv6_slaaczipv6_dhcpv6-statelesszipv6_dhcpv6-statefulz	ovs-vsctlz--formatZcsvz
--no-headingsz	--timeoutZ10z	--columns�name�find�	interfacez
type=internalz([0-9]+)cCsdd�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'].cSs$g|]}|j�rt|�n|j��qS�)�isdigit�int�lower)�.0�textrr�/usr/lib/python3.6/__init__.py�
<listcomp>4sz$natural_sort_key.<locals>.<listcomp>)�re�split)�sZ_nsrerrr�natural_sort_key,srcCstS)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||�}ytj|�}Wnpttfk
r�}zPt|dd�}	|	tjtjfkrZ|dk	rZ||�S|	tj	fkrv|dk	rv||�S�WYdd}~XnX|j
�}|dkr�|Sy||Stk
r�}z&|dk	r�||�Stj
d||��WYdd}~XnXdS)N�errnoz5Found unexpected (not translatable) value '%s' in '%s)r#r
Z	load_file�OSError�IOError�getattrr$�ENOENT�ENOTDIRZEINVAL�strip�KeyError�LOG�debug)
r!r"�	translate�	on_enoent�on_keyerror�	on_einvalZdev_path�contents�eZe_errnorrr�read_sys_netBs2
r4cCsdd�}t||||||d�S)NcSsdS)NFr)r3rrr�
on_excp_falsehsz(read_sys_net_safe.<locals>.on_excp_false)r0r/r1r.)r4)�iface�fieldr.r5rrr�read_sys_net_safegsr8cCs8t||�}|dkrdSyt|�Stk
r2dSXdS)NF)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r@cCstjjt|d��S)N�bridge)�osr"�existsr#)r!rrr�	is_bridge�srDcCstjjt|d��S)N�bonding)rBr"rCr#)r!rrr�is_bond�srFcCs t|dd�}tjj|�r|SdS)z8Return the master path for devname, or None if no master�master)r"N)r#rBr"rC)r!r"rrr�
get_master�srHcCsHt|�}|dkrdStjj|d�}tjj|d�}tjj|�pFtjj|�S)z@Return a bool indicating if devname's master is a bridge or bondNFrErA)rHrBr"�joinrC)r!�master_pathZbonding_pathZbridge_pathrrr�master_is_bridge_or_bond�srKcCs,t|�}|dkrdSt|dd�}tjj|�S)z;Return a bool indicating if devname's master is openvswitchNFzupper_ovs-system)r")rHr#rBr"rC)r!rJZovs_pathrrr�master_is_openvswitch�s
rLcCst|d�dkS)N�type�32)r8)r!rrr�is_ib_interface�srO)�maxsize)�returncCs ttjd��}|stjd�|S)zDReturn a bool indicating if Open vSwitch is installed in the system.z	ovs-vsctlz<ovs-vsctl not in PATH; not detecting Open vSwitch interfaces)�boolr	Zwhichr,r-)�retrrr�openvswitch_is_installed�s
rTcCs^ytjt�\}}Wn>tjk
rP}z d|jkr>tjd�gS�WYdd}~Xn
X|j�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!rQcCs,t�s
dSt�}||kr(tjd|�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)rTr\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rbcCs,d}yt|d�}Wntk
r&YnX|S)zDReturns a str from reading /sys/class/net/<devname>/device/features.rzdevice/features)r4�	Exception)r!�featuresrrr�get_dev_features�srecCs*t|�}|st|�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)re�len)r!rdrrr�has_netfail_standby_feature�srjcCs<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)rHr^rj)r!rarrr�is_netfail_masters	rlcCstt|dd�}tjj|�sdS|dkr,t|�}|dkr8dStjjtjj|��}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.
    rG)r"FNrkT)r#rBr"rCr^�basename�realpathrj)r!raZmaster_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.
    NFrkT)rHr^rj)r!rarrrr`:s	r`cCst|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�4TF)rprq)r8)r!rorrr�
is_renamedRs	
rrcCstt|d��}d|j�kS)N�ueventzDEVTYPE=vlan)�strr8rX)r!rsrrr�is_vlanasrucCs0d}t|d�}tjj|�r,tjjtj|��}|S)z8Return the device driver for net device named 'devname'.Nz
device/driver)r#rBr"�islinkrm�readlink)r!raZdriver_pathrrrr^fs

r^cCst|d�}|dkrdS|S)z;Return the device id string for net device named 'devname'.z
device/deviceFN)r8)r!Zdev_idrrr�device_devidqs
rxcCsjtj�stj�rtt�j��Sytjt��}Wn6t	k
rd}z|j
t
jkrRg}n�WYdd}~XnX|S)N)r
�
is_FreeBSD�is_DragonFlyBSD�list�get_interfaces_by_mac�valuesrB�listdirrr%r$r()�devsr3rrr�get_devicelistzsr�c@seZdZdZdS)�ParserErrorz6Raised when a parser has issue parsing a file/content.N)�__name__�
__module__�__qualname__�__doc__rrrrr��sr�cCs$|st|t�rdS|jd�dkS)NF�configZdisabled)�
isinstance�dict�get)�cfgrrr�is_disabled_cfg�sr�cCs6tj�stj�rt�Stj�s&tj�r,t�St�SdS)zqGet the list of network interfaces viable for networking.

    @return List of interfaces, sorted naturally.
    N)r
ryrz�find_candidate_nics_on_freebsd�	is_NetBSD�
is_OpenBSD�(find_candidate_nics_on_netbsd_or_openbsd�find_candidate_nics_on_linuxrrrr�find_candidate_nics�s
r�cCs6tj�stj�rt�Stj�s&tj�r,t�St�SdS)z.Get the name of the 'fallback' network device.N)r
ryrz�find_fallback_nic_on_freebsdr�r��&find_fallback_nic_on_netbsd_or_openbsd�find_fallback_nic_on_linuxrrrr�find_fallback_nic�s
r�cCstt�j�td�S)zmGet the names of the candidate network devices on NetBSD/OpenBSD.

    @return list of sorted interfaces
    )�key)�sortedr|r}rrrrrr��sr�cCst�}|r|dSdS)zfGet the 'fallback' network device name on NetBSD/OpenBSD.

    @return default interface, or None
    rN)r�)�namesrrrr��sr�cCs8tjddddg�\}}|j�}|r&|Stt�j�td�S)zgGet the names of the candidate network devices on FreeBSD.

    @return List of sorted interfaces.
    �ifconfigz-lz-u�ether)r�)r	rr�r|r}r)�stdoutZ_stderrr}rrrr��s
r�cCst�}|r|dSdS)z_Get the 'fallback' network device name on FreeBSD.

    @return List of sorted interfaces.
    rN)r�)r�rrrr��sr�cCs`dtj�krtjd�n<dd�t�D�}t|�rTtjd|�d}tjtj|tjd�g}g}x�tdddddd	d
�D]�\}}}}|dkr�qr|j	d�r�tjd
|�qrt
|d�}|r�|j|�qrtjd|�t
|d�}|r�|j|�qrt|d�}|dk�r|j|�qrtjd|�qrWg}	xF||gD]:}
t
|
td�}
t|
k�rN|
jt�|
jdt�|	|
7}	�qW|	S)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/cmdlinecSs"g|]}|dkrt|�r|�qS)�lo)rr)rZdevicerrrr�sz0find_candidate_nics_on_linux.<locals>.<listcomp>z4Found 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_reasonsr�ZvethzIgnoring veth interface: %s�carrierzInterface has no carrier: %s�dormantr?r>�lowerlayerdownr=zInterface ignored: %s)r�r)r�r>r�r=)r
Zget_cmdliner,r-r�riZlog_timeZudevadm_settle�get_interfaces�
startswithr;�appendr8r�r�DEFAULT_PRIMARY_INTERFACE�remove�insert)Zunstable�msgZ	connectedZpossibly_connectedr�_r�r�r?Zsorted_interfaces�
interfacesrrrr��s\










r�cCst�}|r|dSdS)z]Get the 'fallback' network device name on Linux.

    @return List of sorted interfaces.
    rN)r�)r�rrrr�!sr�cCsv|sd}t�}|sdSt|�r(d|i}ndt|d�j�i}dd||d�}|rdt|�}|rd||dd	<||id
d�}|S)zBGenerate network cfg v2 for dhcp on the NIC most likely connected.FNr�
macaddress�addressT)Zdhcp4r
zset-name�matchr�ra�)�	ethernets�version)r�rlr8rr^)Z
config_driverZtarget_namer�r�raZnconfrrr�generate_fallback_config-s$
r�cCsJdd�}dd�}|jd�}|dkr*||�S|dkr:||�Std|��dS)	NcSs�g}x�|jdi�D]|}|jd�dkr&q|jd�}|s6q|jd�}|jdi�jd�}|jdi�jd�}|spt|�}|s|t|�}|j||||g�qW|S)	Nr�rMZphysicalZmac_addressr�paramsra�	device_id)r�r^rxr�)�netcfg�physdevs�ent�macrrar�rrr�
_version_1Ms 

z$extract_physdevs.<locals>._version_1cSs�g}x�|jdi�j�D]z}|jd�}|s*q|jdi�jd�}|sBq|jdi�jd�}|jdi�jd�}|srt|�}|s~t|�}|j||||g�qW|S)Nr�zset-namer�r�rar�)r�r}r^rxr�)r�r�r�rr�rar�rrr�
_version_2_s 
z$extract_physdevs.<locals>._version_2r��r�z"Unknown network config version: %s)r��RuntimeError)r�r�r�r�rrr�extract_physdevsLs
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.Trr��)rr�r�)r;r9)�ifname�strictZassign_typerrr�interface_has_own_mac|s

r�Tc
Cs�i}x4t�D]*\}}}}d|||j�|t|�d�||<qW|r�tjd�}tjdddddd	d
gdd�\}}tjdd
ddgdd�\}	}t�}
x ||	fD]}|
j|j|��q�Wx,|j	�D] }|ddkp�|d|
k|d<q�W|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�rar�rr<z[0-9]+:\s+(\w+)[@:]�ipz-6ZaddrZshowZ	permanentZscope�globalT)�capturez-4r<Frr�)
r�rr@r�compiler	�set�update�findallr})
Zcheck_downable�cur_inforr�rar�ZnmatchZipv6rZZipv4Znics_with_addressesZ	bytes_out�drrr�_get_current_rename_info�s(
 r�cs�t|�stjd�dS|dkr$t�}i�xF|j�D]:\}}|j�}|jd�r\|dj�|d<||d<|�|<q2Wtjd���fdd�}dd�}d	d
�}	dd�}
g}g}g}
|��}d
}d"}dd����fdd�}�x�|D�]�\}}}}|r�|j�}g}||||�}|�s"|r�|jd||f�q�|jd�}||k�r8q�|�sV|r�|jd||f�q�|d�r�d}|d�s�|r�|j||||f�q�d|d<|jd|||ff�|
jd|||ff�||k�r�||}|d�rd}|d�s�|r�|j||||f�q�n|jd|||ff�d}x*|dk�s,||k�r@|d7}||}�qW|jd||||ff�||d<|��}|d�r�|
jd|||ff�|jd|||d|ff�||d<|��}||7}q�W||	|
d�}t|�t|
�dk�rt|��r�tjd|�ntjd|�n~tjd|||
�xj||
D]^\}}}}y|j|�|�Wn<t	k
�rz}z|jd |||||f�WYdd}~XnX�q Wt|��r�t
d!j|���dS)#Nzno interfaces to renamer�rzDetected interfaces %scstdd��j�D��S)Ncss|]}|d|fVqdS)rNr)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�rT)r�)r	)�cur�newrrr�rename�sz"_rename_interfaces.<locals>.renamecSstjddd|dgdd�dS)Nr�r�r�r>T)r�)r	)rrrrr>�sz _rename_interfaces.<locals>.downcSstjddd|dgdd�dS)Nr�r�r�r<T)r�)r	)rrrrr<�sz_rename_interfaces.<locals>.upz
cirename%dr�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�rar�Fr)r�r�rar�rrr�entry_match�sz'_rename_interfaces.<locals>.entry_matchcsT����fdd��j�D�}t|�rPt|�dkrHd|���f}t|��|dSdS)Ncsg|]}�|����r|�qSrr)rr�)r�rar�r�rrr�sz:_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}rir9)r�rar�r�r�)r�r�)r�rar�r�
find_entry�s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<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�
���)rir,r-r��items�copyr�rr�rcr�rI)�renamesZstrict_presentZstrict_busyZcurrent_inforr�r�r�r�r>r<Zops�errorsZupsZ
cur_bynameZtmpname_fmtZtmpir�r��new_namerar�Zcur_opsZcur_namer��targetZtmp_nameZopmap�opr�r3r)r�r�r�_rename_interfaces�s�










*
r�cCs$d}tjjt|d��rd}t||�S)z6Returns the string value of an interface's MAC Addressr�Z
bonding_slavezbonding_slave/perm_hwaddr)rBr"�isdirr#r8)r�r"rrr�get_interface_mac]sr�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.
    rMrN�$��3Ni�)r8r�)r�Zethernet_formatr�rrr�get_ib_interface_hwaddrgs
r�cCs<tj�stj�rt�Stj�r$t�Stj�r2t�St�SdS)N)	r
ryrz� get_interfaces_by_mac_on_freebsdr��get_interfaces_by_mac_on_netbsdr�� get_interfaces_by_mac_on_openbsd�get_interfaces_by_mac_on_linuxrrrrr|usr|)r�rQcCs0x*t�j�D]\}}|j�|j�kr|SqWdS)N)r|r�r)r�Z
interface_macZinterface_namerrr�find_interface_name_from_mac�sr�cCs>tjdddg�\}}dd�}dd�}dd	�|||��D�}|S)
Nr�z-ar�cssDd}x4|jd�D]&}|jd�r(||7}q|r2|V|}qW|VdS)Nrr��	)rr�)rYZ
curr_block�linerrr�flatten�s

z1get_interfaces_by_mac_on_freebsd.<locals>.flattencss8x2|D]*}tjd|�}|r|jd�|jd�fVqWdS)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	)rYr�r�r��resultsrrrr��s
r�cCsfi}d}tjddg�\}}tjdd|�j�}x4|D],}tj||�}|r2|j�}|d||d<q2W|S)NzE(?P<ifname>\w+).*address:\s(?P<mac>([\da-f]{2}[:-]){5}([\da-f]{2})).*r�z-az\n\s+� r�r�)r	r�subrXr��	groupdict)rS�re_field_matchrYr��if_linesr�r��fieldsrrrr��s
r�cCsfi}d}tjddg�\}}tjdd|�j�}x4|D],}tj||�}|r2|j�}|d||d<q2W|S)NzC(?P<ifname>\w+).*lladdr\s(?P<mac>([\da-f]{2}[:-]){5}([\da-f]{2})).*r�z-az\n\s+r�r�r�)r	rr�rXr�r�)rSr�rYr�r�r�r�r�rrrr��s
r�cCs�i}x�t�D]�\}}}}||krX|dkr>tjd||||�qd||||f}t|��|||<t|d�}|r||kr�|||<qtjd||||�qW|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'.z6duplicate mac found! both '%s' and '%s' have mac '%s'.Tz^Ethernet and InfiniBand interfaces have the same address both '%s' and '%s' have address '%s'.)r�rr)r�r,r-r�r��warning)rSrr�raZ_devidr��ib_macrrrr��s4


r�)�filter_hyperv_vf_with_syntheticr�r�r�r�r�r�rQcCs0|r
tjndd�}g}t�}	djd
�}
x�|	D]�}|r@t|�r@q,t|�rT|d|�q,|rbt|�rbq,t|�rv|d|�q,|r�t|�dk	r�t	|�r�t
|�r�q,t|�r�|d	|�q,t|�}|s�|d
|�q,|r�|dkr�||
dt
|��kr�q,|o�t|��r�q,t|�}
|j|||
t|�f�q,W|�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.cWsdS)Nr)�argsrrr�<lambda>sz get_interfaces.<locals>.<lambda>�:�00�zIgnoring bridge interface: %szIgnoring bond interface: %sNzIgnoring failover interface: %sz"Ignoring interface without mac: %sr�)r)rrrrrrrrrrrrrrrr)r,r-r�rIr�rDrurFrHrKrLrbr�rir]r^r�rx�)filter_hyperv_vf_with_synthetic_interface)rr�r�r�r�r�r��filtered_loggerrSrZzero_macrr�rarrrr�
sJ







 
r�.)rr�rQcs\dd�|D���fdd�|D�}x6|D].}|\}}}}|d||�||�|j|�q&WdS)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.
    cSs&i|]}|ddkr|d|d�qS)r��	hv_netvscrr�r)r�irrrr�Zsz=filter_hyperv_vf_with_synthetic_interface.<locals>.<dictcomp>cs(g|] }|d�kr|ddkr|�qS)r�r�rr)rr
)�hv_netvsc_mac_to_namerrr^sz=filter_hyperv_vf_with_synthetic_interface.<locals>.<listcomp>zdIgnoring %r VF interface with driver %r due to synthetic hv_netvsc interface %r with mac address %r.N)r�)rr�Zinterfaces_to_removerrr�rar�r)rrr
Fs

r
cCsTi}xJt�D]@\}}}}t|d�}|r||krDtd||||f��|||<qW|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�)rSrr�rrrr�get_ib_hwaddrs_by_interfaceps
r)�url_datarQcCs�d|krtjd|�dS|d}y6t|�}t|jdk|jdkg�sTtjd|j�dSWn,tk
r�}ztjd|�dSd}~XnXd	|kr�d
|d	<ytf|�Wntk
r�dSXdS)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�any�schemer9rr)rr�result�errrrr�has_url_connectivity�s,
r)�convert_to_addressr�cKs&y||f|�Stk
r dSXdS)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�rQcCstttj|��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�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.
    )rRrrZIPv4Address)r�rrr�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.
    )rRrrZIPv6Address)r�rrr�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�)rRrr�
ip_network)r�rrr�
is_ip_network�s	r!cCstttj|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.
    F)r�)rRrr�IPv4Network)r�rrr�is_ipv4_network�s	r#cCstttj|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.
    F)r�)rRrrZIPv6Network)r�rrr�is_ipv6_network�s	r$cCs@|djd�s|dtkrdS|ddkr<t|jd��r<dSdS)z:Common helper for checking network_state subnets for ipv6.rM�6TZstaticr�F)�endswith�IPV6_DYNAMIC_TYPESrr�)Zsubnetrrr�subnet_is_ipv6s
r(cCsttjd|���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.z0.0.0.0/)rtrr"�netmask)�prefixrrr�net_prefix_to_ipv4_masksr+cCstjd|���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
    z0.0.0.0/)rr �	prefixlen)�maskrrr�ipv4_mask_to_net_prefixs	r.c
Cs�ytjd|���j}|Stk
r*YnXtj|�}t|�}|dkrJ|Sttj||d@j��}||?}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')	rr r,r9rr�minZ
IPV6LENGTH�
bit_length)r-r,r)Zmask_intZtrailing_zeroesZleading_onesZall_onesrrr�ipv6_mask_to_net_prefix)s"

r1)r-r�rQcCsttj|�d|��dd�j�S)zCGet string representation of broadcast address from an ip/mask pairr F)r�)rtrr"Zbroadcast_address)r-r�rrr�mask_and_ipv4_to_bcast_addrLsr2c@seZdZdS)�RendererNotFoundErrorN)r�r�r�rrrrr3Ssr3)r)NNNN)N)N)N)N)N)N)F)T)TTN)TTTTTTF).N)hr$�	functoolsrZloggingrBrZtypingrrrrrrZurllib.parserZ	cloudinitr	r
Zcloudinit.url_helperrrZ	getLoggerr�r,rr�r'rUr�rrr#r4r8r;r@rDrFrHrKrLrO�	lru_cacherRrTr{r\rtr]rbrerjrlr_r`rrrur^rxr�rcr�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
rrrrrrr!r#r$r(r+rr.r1r2r�r3rrrr�<module>s� 






	






!
	

I
0

/

H5''	#

Filemanager

Name Type Size Permission Actions
__init__.cpython-36.opt-1.pyc File 33.43 KB 0644
__init__.cpython-36.pyc File 33.43 KB 0644
activators.cpython-36.opt-1.pyc File 9.52 KB 0644
activators.cpython-36.pyc File 9.52 KB 0644
bsd.cpython-36.opt-1.pyc File 5.74 KB 0644
bsd.cpython-36.pyc File 5.74 KB 0644
cmdline.cpython-36.opt-1.pyc File 7.2 KB 0644
cmdline.cpython-36.pyc File 7.2 KB 0644
dhcp.cpython-36.opt-1.pyc File 15.98 KB 0644
dhcp.cpython-36.pyc File 15.98 KB 0644
eni.cpython-36.opt-1.pyc File 12.89 KB 0644
eni.cpython-36.pyc File 12.89 KB 0644
ephemeral.cpython-36.opt-1.pyc File 10.51 KB 0644
ephemeral.cpython-36.pyc File 10.51 KB 0644
freebsd.cpython-36.opt-1.pyc File 2.54 KB 0644
freebsd.cpython-36.pyc File 2.54 KB 0644
netbsd.cpython-36.opt-1.pyc File 1.69 KB 0644
netbsd.cpython-36.pyc File 1.69 KB 0644
netplan.cpython-36.opt-1.pyc File 11.91 KB 0644
netplan.cpython-36.pyc File 11.91 KB 0644
network_manager.cpython-36.opt-1.pyc File 12.83 KB 0644
network_manager.cpython-36.pyc File 12.83 KB 0644
network_state.cpython-36.opt-1.pyc File 27.57 KB 0644
network_state.cpython-36.pyc File 27.57 KB 0644
networkd.cpython-36.opt-1.pyc File 8.21 KB 0644
networkd.cpython-36.pyc File 8.21 KB 0644
openbsd.cpython-36.opt-1.pyc File 2.18 KB 0644
openbsd.cpython-36.pyc File 2.18 KB 0644
renderer.cpython-36.opt-1.pyc File 1.82 KB 0644
renderer.cpython-36.pyc File 1.82 KB 0644
renderers.cpython-36.opt-1.pyc File 1.53 KB 0644
renderers.cpython-36.pyc File 1.53 KB 0644
sysconfig.cpython-36.opt-1.pyc File 23.07 KB 0644
sysconfig.cpython-36.pyc File 23.07 KB 0644
udev.cpython-36.opt-1.pyc File 1.22 KB 0644
udev.cpython-36.pyc File 1.31 KB 0644