/usr/share/netplan/netplan/cli/__pycache__
NameSizeModeActions
core.cpython-38.pyc12430644editdlrm
ovs.cpython-38.pyc44680644editdlrm
sriov.cpython-38.pyc122260644editdlrm
utils.cpython-38.pyc84460644editdlrm
__init__.cpython-38.pyc1330644editdlrm
Edit: /usr/share/netplan/netplan/cli/__pycache__/sriov.cpython-38.pyc (12226B)
U )/b N@sddlZddlZddlZddlZddlmZddlmmZddl m Z ddl m Z ddl Z GdddeZejedddZejeejed d d Zd d ZddZddZddZddZdddZdddZdS)N) defaultdict)ConfigurationErrorc@seZdZdZedddZeedddZeeddd Zeed d d Z eedd dZ ee dddZ ee dddZ ee dddZeedddZeedddZeeedddZedddZdS) PCIDevicez.Helper class for interaction with a PCI devicepci_addrcCs ||_dS)znInitialise a new PCI device handler :param pci_addr: PCI address of device :type: str Nr)selfrr'/usr/share/netplan/netplan/cli/sriov.py__init__'szPCIDevice.__init__)returncCsdS)zusysfs path (can be overridden for testing) :return: full path to /sys filesystem :rtype: str z/sysrrrrr sys.sz PCIDevice.syscCstj|jd|jS)zq/sys path for PCI device :return: full path to PCI device in /sys filesystem :rtype: str zbus/pci/devices)ospathjoinr rr rrr r6szPCIDevice.path)subpathr cCstj|j|S)z/sys subpath helper for PCI device :param subpath: subpath to construct path for :type: str :return: self.path + subpath :rtype: str )rrr)rrrrr r>szPCIDevice.subpathcCs2d}tj|dr.tjt|d}|S)zjKernel driver for PCI device :return: kernel driver in use for device :rtype: str driver)rrexistsrbasenamereadlink)rrrrr rGszPCIDevice.drivercCstj|dS)zDetermine if device is bound to a kernel driver :return: whether device is bound to a kernel driver :rtype: bool rrrrrr rrr boundRszPCIDevice.boundcCstj|dS)zwDetermine if device is a SR-IOV Physical Function :return: whether device is a PF :rtype: bool sriov_numvfsrr rrr is_pfZszPCIDevice.is_pfcCstj|dS)zvDetermine if device is a SR-IOV Virtual Function :return: whether device is a VF :rtype: bool Zphysfnrr rrr is_vfbszPCIDevice.is_vfc CsXg}d}z(|tjt|d|Wntk rHYqTYnX|d7}q|S)zList Virtual Function addresses associated with a Physical Function :return: List of PCI addresses of Virtual Functions :rtype: list[str] rzvirtfn{})appendrrrrrformatFileNotFoundError)rvf_addrsirrr r js  zPCIDevice.vf_addrscCsdd|jDS)zList Virtual Function associated with a Physical Function :return: List of PCI devices of Virtual Functions :rtype: list[PCIDevice] cSsg|] }t|qSr)r).0addrrrr sz!PCIDevice.vfs..)r r rrr vfs~sz PCIDevice.vfs)obj_namepropvaluec Cs$tdd|dd|j||gdS)zSet devlink options for the PCI device :param obj_name: devlink object to set options on :type: str :param prop: property to set :type: str :param value: value to set for property :type: str z /sbin/devlinkdevsetzpci/{}N) subprocess check_callrr)rr&r'r(rrr devlink_sets  zPCIDevice.devlink_setcCs|jS)zbString represenation of object :return: PCI address of string :rtype: str rr rrr __str__szPCIDevice.__str__N)__name__ __module__ __qualname____doc__strr propertyr rrrboolrrrlistr r%r-r.rrrr r$s*  r)r%c CsJg}|D]<}|jstd|d}||j||W5QRXq|S)zBind unbound VFs to driver.z/sys/bus/pci/drivers/{}/bindwtropenrwriterr)r%rZ bound_vfsvffrrr bind_vfss r=)r%r c CsJg}|D]<}|jrtd|d}||j||W5QRXq|S)zUnbind bound VFs from driver.z/sys/bus/pci/drivers/{}/unbindr7r8)r%rZ unbound_vfsr;r<rrr unbind_vfss r>c Cs||kr|j|}|d}|r|d}|r@||kr@|||<q|d}|d}|d} |D]R} |rvt| |rb|rt| |rb| rt| | sqb||krtd|| ||<qbn||kr|||<||dS)Nmatchzset-namename macaddressrz3matched more than one interface for a PF device: %s) ethernetsgetutilsis_interface_matching_name is_interface_matching_macaddress!is_interface_matching_driver_namer) interfacesconfig_managerpf_linkpfsZpf_devZpf_matchset_nameby_nameZby_macZ by_driver interfacerrr _get_target_interfaces6            rOc Cstjd|d}zbt|P}d}|D]<}|}|dr(|ddd}|W5QRWSq(W5QRXWn6tk r}zt d|t |fW5d}~XYnXdS) z5 Read PCI slot name for given interface name /sys/class/netz device/ueventNzPCI_SLOT_NAME==rz'failed parsing PCI slot name for %s: %s) rrrr9 readlinesstrip startswithsplitIOError RuntimeErrorr3)ZnetdevZ uevent_pathr<Z pci_slot_namelineerrr _get_pci_slot_names   &r[c Csi}|jD]\}}|sq|dkr&q|d}|rPt||||} | r||| <q|d} | r| |jkrt||| || |kr||| d7<ntd| qd||<q|D]8\} } | |kr|| | krtd|| | f| || <qdS)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-countlinkrz9could not match physical interface for the defined PF: %sNz;more VFs allocated than the explicit size declared: %s > %s)rBitemsrCrOloggingwarningr) rHrI vf_countsr%rKZexplicit_countsZethernetsettingsZ explicit_numpfrJcountrrr get_vf_count_and_functionss4   rec Cs|dkrtd||ftjd|d}tj|d}tj|d}z(t|}t|}W5QRXWnTtk r}zt d|t |fW5d}~XYn t k rt d |YnX||krtd |||fz(t|d }| t |W5QRXWntk r}zd }|j d krtd|zHt|d }| dW5QRXt|d }| t |W5QRXWn(tk r} z| }W5d} ~ XYnXd}|rt d||t |fW5d}~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 > 256rPdevicerZsriov_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)wTzLdevice or resource busy while setting sriov_numvfs for %s, trying workaround0Fz,failed setting sriov_numvfs to %s for %s: %s)rrrrr9intreadrTrWrXr3 ValueErrorr:errnor_r`) rcvf_countdevdirZ numvfs_pathZ totalvfs_pathr<Zvf_maxrZZbailZe_innerrrr set_numvfs_for_pf"sH  $     (rqc Cstjd|d}zhttj|d}|dd}W5QRXttj|d}|dd}W5QRXWn6tk r}ztd|t|fW5d}~XYnXd||g}d}||krdS) z Perform any hardware-specific quirks for the given SR-IOV device to make sure all the VF-count changes are applied. rPrgZvendorrRNz2could not determine vendor and device ID of %s: %s:r) rrrr9rlrTrWrXr3)rcrpr<Z device_idZ vendor_idrZZ combined_idZ quirk_devicesrrr perform_hardware_specific_quirksQs"& rs/c Csd}tj|d|d}tjt|}tj|d|d}t|D]D} d| krDtj|| } tjt| } | |krD| dd}qqD|std||fz.tjddd d |d |d t |g tj tj d Wn"tj k rtd|YnXdS)z@ Apply the hardware VLAN filtering for the selected VF. Nz sys/class/netrgZvirtfnzAcould not determine the VF index for %s while configuring vlan %sipr]r*r)r;vlan)stdoutstderrzJfailed setting SR-IOV VLAN filter for vlan %s (ip link set command failed)) rrrrrlistdirrXr+r,r3DEVNULLCalledProcessError) rcr;Z vlan_namevlan_idprefixZvf_indexZ vf_devdirZ vf_dev_idZ pf_devdirr<Zdev_pathZdev_idrrr apply_vlan_filter_for_vfns>    rc Cst}||t}|||t}tt }i}i}t |||||g}|r| D]\} } t | | sxqd| | qd|r|D] } t| qt}|D]} |j| } | d} | r| d}|D]>}|rt||sq| |kr || r td| ||| <qq| |kr| || <q| D]\}}||}|j}|dkr0t|}t|}|jr0td||j|jr0|j}z t |j|j|!dd|W5|st|j|jXq0t"}|j# D]\}} | dd kr| d }| d }||} | s(t$d ||fq|j|d }||} | |kr`td | ||ft%| | |||&| qdS)z Go through all interfaces, identify which ones are SR-IOV VFs, create them and perform all other necessary setup. r?r@z3matched more than one interface for a VF device: %s)Z switchdevZlegacyzFound VFs of {}: {}Zeswitchmoder\Zsriovr]idzKSR-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)' libnetplanParserZload_yaml_hierarchyStateZimport_parser_resultsparse netifacesrHrrkrer^rqrrsrBrCrDrErZembedded_switch_moder[rrr_debugrr r%Zdelay_virtual_functions_rebindr=rr>r-r*vlansr`radd)rIZrootdirparserZnp_staterHrar%rKZvf_count_changedrcror;rbr?rMrNZ netdef_idifaceZnetdefZ eswitch_moderZpcidevZrebind_delayedZfiltered_vlans_setrwr]r}Zvf_parent_entryrrr apply_sriov_configs                   r)rt)rt)r_rr+typing collectionsrnetplan.cli.utilsclirDZnetplan.libnetplanrnetplan.configmanagerrrobjectrIterabler=r>rOr[rerqrsrrrrrr s$     '1/ '