GOOD SHELL MAS BOY
Server: Apache/2.4.52 (Ubuntu)
System: Linux vmi1836763.contaboserver.net 5.15.0-130-generic #140-Ubuntu SMP Wed Dec 18 17:59:53 UTC 2024 x86_64
User: www-data (33)
PHP: 8.4.10
Disabled: NONE
Upload Files
File: //usr/share/netplan/netplan/cli/__pycache__/sriov.cpython-38.pyc
U

ci�_�5�@s�ddlZddlZddlZddlmZddlmmZddlm	Z	ddl
Z
dd�Zdd�Zdd	�Z
d
d�Zdd
d�Zdd�ZdS)�N)�defaultdict)�ConfigurationErrorcCs�||kr�|j|}|�d�}|r�|�d�}|r@||kr@|||<q�|�d�}|�d�}|�d�}	|D]R}
|rvt�|
|�rb|r�t�|
|�rb|	r�t�|
|	�s�qb||kr�td|��|
||<qbn||kr�|||<|�|d�S)N�matchzset-name�name�
macaddress�driverz3matched more than one interface for a PF device: %s)�	ethernets�get�utils�is_interface_matching_name� is_interface_matching_macaddress�!is_interface_matching_driver_namer)�
interfaces�config_manager�pf_link�pfsZpf_devZpf_match�set_name�by_nameZby_macZ	by_driver�	interface�r�'/usr/share/netplan/netplan/cli/sriov.py�_get_target_interfaces6






�
��
�rcCs�i}|j��D]�\}}|sq|dkr&q|�d�}|rPt||||�}	|	r|||	<q|�d�}
|
r|
|jkrt|||
|�|
|kr�|||
d7<nt�d|
�qd||<q|��D]8\}	}|	|kr�||	|kr�td||	|f��|||	<q�dS)z�
    Go through the list of netplan ethernet devices and identify which are
    PFs and VFs, matching the former with actual networking interfaces.
    Count how many VFs each PF will need.
    �rendererzvirtual-function-count�link�z9could not match physical interface for the defined PF: %sNz;more VFs allocated than the explicit size declared: %s > %s)r�itemsr	r�logging�warningr)rr�	vf_counts�vfsrZexplicit_countsZethernet�settingsZexplicit_num�pfr�countrrr�get_vf_count_and_functionsEs4


�r#c

Cs�|dkrtd||f��tj�d|d�}tj�|d�}tj�|d�}z(t|��}t|�����}W5QRXWnTtk
r�}zt	d|t
|�f��W5d}~XYn tk
r�t	d	|��YnX||kr�td
|||f��z(t|d��}|�t
|��W5QRXWn�tk
�r�}z�d}|j
d
k�r�t�d|�zHt|d��}|�d�W5QRXt|d��}|�t
|��W5QRXWn(tk
�r�}	z|	}W5d}	~	XYnXd}|�r�t	d||t
|�f��W5d}~XYnXdS)zB
    Allocate the required number of VFs for the selected PF.
    �zDcannot allocate more VFs for PF %s than the SR-IOV maximum: %s > 256�/sys/class/net�deviceZsriov_numvfsZsriov_totalvfsz(failed parsing sriov_totalvfs for %s: %sNz#invalid sriov_totalvfs value for %szKcannot allocate more VFs for PF %s than supported: %s > %s (sriov_totalvfs)�wT�zLdevice or resource busy while setting sriov_numvfs for %s, trying workaround�0Fz,failed setting sriov_numvfs to %s for %s: %s)r�os�path�join�open�int�read�strip�IOError�RuntimeError�str�
ValueError�write�errnorr)
r!�vf_count�devdirZnumvfs_pathZ
totalvfs_path�fZvf_max�eZbailZe_innerrrr�set_numvfs_for_pfvsH
�
$�(r;c
Cs�tj�d|d�}zhttj�|d���}|����dd�}W5QRXttj�|d���}|����dd�}W5QRXWn6tk
r�}ztd|t|�f��W5d}~XYnXd�||g�}d}||kr�dS)	z�
    Perform any hardware-specific quirks for the given SR-IOV device to make
    sure all the VF-count changes are applied.
    r%r&Zvendor�Nz2could not determine vendor and device ID of %s: %s�:r)	r*r+r,r-r/r0r1r2r3)r!r8r9Z	device_idZ	vendor_idr:Zcombined_idZ
quirk_devicesrrr� perform_hardware_specific_quirks�s"&
r>�/cCs�d}tj�|d|d�}tj�t�|��}tj�|d|d�}t�|�D]D}	d|	krDtj�||	�}
tj�t�|
��}||krD|	dd�}q�qD|s�td||f��z.tjddd	d
|d|dt	|�g	tj
tj
d
�Wn"tjk
r�td|��YnXdS)z@
    Apply the hardware VLAN filtering for the selected VF.
    Nz
sys/class/netr&Zvirtfn�zAcould not determine the VF index for %s while configuring vlan %s�ipr�set�dev�vf�vlan)�stdout�stderrzJfailed setting SR-IOV VLAN filter for vlan %s (ip link set command failed))r*r+r,�basename�readlink�listdirr2�
subprocess�
check_callr3�DEVNULL�CalledProcessError)r!rDZ	vlan_name�vlan_id�prefixZvf_indexZ	vf_devdirZ	vf_dev_idZ	pf_devdirr9Zdev_pathZdev_idrrr�apply_vlan_filter_for_vf�s>
�
��
�rQcCs�|��t��}tt�}i}i}t|||||�g}|r`|��D]\}}t||�sTq@|�|�q@|r~|D]}t	|�qht��}|D]z}|j
�|�}	|	�d�}
|
r�|
�d�}|D]:}|r�t�
||�s�q�||kr�||r�td|��|||<q�q�||kr�|||<q�t�}
|j��D]�\}}	|	�d�dk�r|	�d�}|	�d�}|�sLtd|��|�|�}|�srt�d	||f��q|j
�|��d�}|�|�}||
k�r�td
|||f��t||||�|
�|��qdS)z
    Go through all interfaces, identify which ones are SR-IOV VFs, create
    them and perform all other necessary setup.
    rrz3matched more than one interface for a VF device: %srZsriovr�idz)no id property defined for SR-IOV vlan %szKSR-IOV vlan defined for %s but link %s is either not a VF or has no matcheszJinterface %s for netplan device %s (%s) already has an SR-IOV vlan definedN)�parse�	netifacesrrr.r#rr;�appendr>rr	r
rrrB�vlansrrrQ�add)rrrrrZvf_count_changedr!r7rDr rrrZfiltered_vlans_setrErrOZvf_parent_entryrrr�apply_sriov_config�st�






�

�

�rX)r?)rr*rK�collectionsr�netplan.cli.utils�clir
�netplan.configmanagerrrTrr#r;r>rQrXrrrr�<module>s'1/
'