HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-10-0-8-47 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:31:58 UTC 2024 aarch64
User: ubuntu (1000)
PHP: 8.1.2-1ubuntu2.22
Disabled: NONE
Upload Files
File: //proc/self/root/lib/python3/dist-packages/cloudinit/distros/__pycache__/networking.cpython-310.pyc
o

�AdV,�@s�ddlZddlZddlZddlmZmZddlmZmZm	Z	ddl
mZe�e
�ZeZeZGdd�dejd�ZGdd	�d	e�ZGd
d�de�ZGdd
�d
e�ZdS)�N)�List�Optional)�net�subp�util)�ifconfigc@s�eZdZdZdd�Zdefdd�Zdd�d	eddfd
d�Ze	j
deddfd
d��Zde
fdd�Zde
fdd�Zdedefdd�Zdd�dd�Zddd�defdd�Zdefdd�Zdefd d!�Zde
d"efd#d$�Zde
fd%d&�Zdefd'd(�Zdefd)d*�Zde
fd+d,�Zdd-�de
d.edefd/d0�Zde
defd1d2�Zde
defd3d4�Ze	j
de
defd5d6��Zde
defd7d8�Zde
defd9d:�Z de
defd;d<�Z!de
defd=d>�Z"e	j
dd?�dGd@dA��Z#dBd-�ded.eddfdCdD�Z$e	j
de
defdEdF��Z%dS)H�
NetworkingaThe root of the Networking hierarchy in cloud-init.

    This is part of an ongoing refactor in the cloud-init codebase, for more
    details see "``cloudinit.net`` -> ``cloudinit.distros.networking``
    Hierarchy" in CONTRIBUTING.rst for full details.
    cCs
d|_dS�N��blacklist_drivers��self�r�>/usr/lib/python3/dist-packages/cloudinit/distros/networking.py�__init__�
zNetworking.__init__�returncC�t��Sr	)r�_get_current_rename_inforrrrr�z#Networking._get_current_rename_infoN��current_info�renamescC�tj||d�S)Nr)r�_rename_interfaces)r
rrrrrr �zNetworking._rename_interfaces�netcfgcC�dS)z7Read the network config and rename devices accordingly.Nr�r
rrrr�apply_network_config_names#�z%Networking.apply_network_config_names�devnamecC�
t�|�Sr	)r�device_devid�r
r!rrrr#'rzNetworking.device_devidcCr"r	)r�
device_driverr$rrrr%*rzNetworking.device_drivercCr"r	)r�extract_physdevsrrrrr&-rzNetworking.extract_physdevsr
cCstj|d�S�Nr
)r�find_fallback_nic)r
rrrrr(0�zNetworking.find_fallback_nicF�r�
config_driverr+cCr)Nr*)r�generate_fallback_config)r
rr+rrrr,3s�z#Networking.generate_fallback_configcCrr	)r�get_devicelistrrrrr-:rzNetworking.get_devicelistcCrr	)r�get_ib_hwaddrs_by_interfacerrrrr.=rz&Networking.get_ib_hwaddrs_by_interface�ethernet_formatcCst�||�Sr	)r�get_ib_interface_hwaddr)r
r!r/rrrr0@sz"Networking.get_ib_interface_hwaddrcCr"r	)r�get_interface_macr$rrrr1ErzNetworking.get_interface_maccCrr	)r�get_interfacesrrrrr2HrzNetworking.get_interfacescCstj|jd�Sr')r�get_interfaces_by_macrrrrrr3Ks�z Networking.get_interfaces_by_maccCr"r	)r�
get_masterr$rrrr4PrzNetworking.get_master��strictr6cCr)Nr5)r�interface_has_own_mac)r
r!r6rrrr7Ssz Networking.interface_has_own_maccCr"r	)r�is_bondr$rrrr8XrzNetworking.is_bondcCr"r	)r�	is_bridger$rrrr9[rzNetworking.is_bridgecCr)z�
        Is ``devname`` a physical network device?

        Examples of non-physical network devices: bonds, bridges, tunnels,
        loopback devices.
        Nrr$rrr�is_physical^r zNetworking.is_physicalcCr"r	)r�
is_renamedr$rrrr;grzNetworking.is_renamedcCr"r	)r�is_upr$rrrr<jrzNetworking.is_upcCr"r	)r�is_vlanr$rrrr=mrzNetworking.is_vlancCr"r	)r�master_is_bridge_or_bondr$rrrr>prz#Networking.master_is_bridge_or_bond��existscCr)a�Wait for device population in the system to complete.

        :param exists:
            An optional optimisation.  If given, only perform as much of the
            settle process as is required for the given DeviceName to be
            present in the system.  (This may include skipping the settle
            process entirely, if the device already exists.)
        :type exists: Optional[DeviceName]
        Nr�r
r@rrr�settlesr zNetworking.settleTcCs�|�|�}tdd�|D��}t|���}|����}tdd�D];}|�|�r.t�d�dS|�	|�}t�d|�|D]}	||	}
d�
|
�}tjtj||j
d	|
id
�q;|����}qd|}t�|�|rjt|��dS)a�Wait for all the physical devices in `netcfg` to exist on the system

        Specifically, this will call `self.settle` 5 times, and check after
        each one if the physical devices are now present in the system.

        :param netcfg:
            The NetworkConfig from which to extract physical devices to wait
            for.
        :param strict:
            Raise a `RuntimeError` if any physical devices are not present
            after waiting.
        cSsg|]
}|d|df�qS)r�r)�.0�ifacerrr�
<listcomp>�sz0Networking.wait_for_physdevs.<locals>.<listcomp>r�z*net: all expected physical devices presentNz)net: waiting for expected net devices: %szWaiting for settle or {} existsr@)�func�kwargsz-Not all expected physical devices present: %s)r&�dict�set�keysr3�range�issubset�LOG�debug�
difference�formatr�log_timerB�warning�RuntimeError)r
rr6�physdevs�expected_ifaces�
expected_macs�present_macs�_�missing�macr!�msgrrr�wait_for_physdevss2




�
�zNetworking.wait_for_physdevscCr)z=Try setting the link to up explicitly and return if it is up.Nrr$rrr�try_set_link_up�r zNetworking.try_set_link_up�rN)&�__name__�
__module__�__qualname__�__doc__rrJr�listr�abc�abstractmethod�
NetworkConfigr�
DeviceNamer#r%r&r(�boolr,r-r.r0r1r2r3r4r7r8r9r:r;r<r=r>rBr^r_rrrrrsl�
��
����
����
�6r)�	metaclasscs�eZdZdZ�fdd�Zdd�Zdeddfd	d
�Zdede	fdd
�Z
dede	fdd�Zdede	fdd�Zdede	fdd�Z
dede	fdd�Zdd�ddd�Zdede	fdd�Z�ZS)�
BSDNetworkingz>Implementation of networking functionality shared across BSDs.cs&t��|_i|_|��t���dSr	)r�Ifconfig�ifc�ifs�_update_ifs�superrr��	__class__rrr�s
zBSDNetworking.__init__cCs0t�ddg�}|dr|j�|d�|_dSdS)Nrz-ar)rrn�parsero)r
�ifconfrrrrp�s�zBSDNetworking._update_ifsrrNcCst�d�dS)Nz Cannot rename network interface.)rOrPrrrrr�rz(BSDNetworking.apply_network_config_namesr!cC�|j|jSr	)ror:r$rrrr:�r)zBSDNetworking.is_physicalcCrvr	)ror8r$rrrr8�r)zBSDNetworking.is_bondcCrvr	)ror9r$rrrr9�r)zBSDNetworking.is_bridgecCrvr	)ror=r$rrrr=�r)zBSDNetworking.is_vlancCrvr	)ro�upr$rrrr<�r)zBSDNetworking.is_upr?cCr)z0BSD has no equivalent to `udevadm settle`; noop.NrrArrrrB�r zBSDNetworking.settlecCst�d|dg�|�|�S)��Try setting the link to up explicitly and return if it is up.
        Not guaranteed to bring the interface up. The caller is expected to
        add wait times before retrying.rrw�rr<r$rrrr_�s
zBSDNetworking.try_set_link_upr`)rarbrcrdrrprhrrirjr:r8r9r=r<rBr_�
__classcell__rrrrrrl�srlc@s0eZdZdeddfdd�Zdedefdd�ZdS)	�FreeBSDNetworkingrrNcCsdSr	rrrrrr�sz,FreeBSDNetworking.apply_network_config_namesr!cCsB|j|jsdStjdd|gddgd�\}}|d�|�krdSdS)	NF�devinfoz-prrC)�rcszdevinfo: {}: Not found
T)ror:rrR)r
r!rZ�errrrrr;�szFreeBSDNetworking.is_renamed)rarbrcrhrrirjr;rrrrr{�sr{c@s�eZdZdZdeddfdd�Zdedefdd	�Zdede	fd
d�Z
dede	fdd
�Zdede	fdd�Zdede	fdd�Z
dede	fdd�Zdede	fdd�Zdd�ddd�Zdede	fdd�ZdS)�LinuxNetworkingzCImplementation of networking functionality common to Linux distros.rrNc
Cs>z|�|�|��WdSty}ztd|�|�d}~ww)z�Read the network config and rename devices accordingly.

        Renames are only attempted for interfaces of type 'physical'. It is
        expected that the network system will create other devices with the
        correct name in place.
        z(Failed to apply network config names: %sN)rr&rU)r
r�errrrs����z*LinuxNetworking.apply_network_config_namesr!cCr"r	)r�get_dev_featuresr$rrrr�rz LinuxNetworking.get_dev_featurescCr"r	)r�has_netfail_standby_featurer$rrrr�rz+LinuxNetworking.has_netfail_standby_featurecCr"r	)r�is_netfailoverr$rrrr� rzLinuxNetworking.is_netfailovercCr"r	)r�is_netfail_masterr$rrrr�#rz!LinuxNetworking.is_netfail_mastercCr"r	)r�is_netfail_primaryr$rrrr�&rz"LinuxNetworking.is_netfail_primarycCr"r	)r�is_netfail_standbyr$rrrr�)rz"LinuxNetworking.is_netfail_standbycCstj�t�|d��S)N�device)�os�pathr@r�sys_dev_pathr$rrrr:,szLinuxNetworking.is_physicalr?cCs"|dur	t�|�}tj|d�dS)Nr?)rr�r�udevadm_settlerArrrrB/s
zLinuxNetworking.settlecCst�ddd|dg�|�|�S)rx�ip�linkrKrwryr$rrrr_4s
zLinuxNetworking.try_set_link_upr`)rarbrcrdrhrri�strr�rjr�r�r�r�r�r:rBr_rrrrrsr)rf�loggingr��typingrr�	cloudinitrrr�cloudinit.distros.parsersr�	getLoggerrarOr�rirJrh�ABCMetarrlr{rrrrr�<module>s
)-!