+ @staticmethod
+ def get_virtfn_pci_addr(node, pf_pci_addr, vf_id):
+ """Get PCI address of Virtual Function.
+
+ :param node: DUT node.
+ :param pf_pci_addr: Physical Function PCI address.
+ :param vf_id: Virtual Function number.
+ :type node: dict
+ :type pf_pci_addr: str
+ :type vf_id: int
+ :returns: Virtual Function PCI address.
+ :rtype: int
+ :raises RuntimeError: If failed to get Virtual Function PCI address.
+ """
+ command = "sh -c "\
+ "'basename $(readlink /sys/bus/pci/devices/{pci}/virtfn{vf_id})'".\
+ format(pci=pf_pci_addr, vf_id=vf_id)
+ message = 'Failed to get virtual function PCI address.'
+
+ stdout, _ = exec_cmd_no_error(node, command, timeout=30, sudo=True,
+ message=message)
+
+ return stdout.strip()
+
+ @staticmethod
+ def get_sriov_numvfs(node, pf_pci_addr):
+ """Get number of SR-IOV VFs.
+
+ :param node: DUT node.
+ :param pf_pci_addr: Physical Function PCI device address.
+ :type node: dict
+ :type pf_pci_addr: str
+ :returns: Number of VFs.
+ :rtype: int
+ :raises RuntimeError: If PCI device is not SR-IOV capable.
+ """
+ command = 'cat /sys/bus/pci/devices/{pci}/sriov_numvfs'.\
+ format(pci=pf_pci_addr.replace(':', r'\:'))
+ message = 'PCI device {pci} is not a SR-IOV device.'.\
+ format(pci=pf_pci_addr)
+
+ for _ in range(3):
+ stdout, _ = exec_cmd_no_error(node, command, timeout=30, sudo=True,
+ message=message)
+ try:
+ sriov_numvfs = int(stdout)
+ except ValueError:
+ logger.trace('Reading sriov_numvfs info failed on {host}'.
+ format(host=node['host']))
+ else:
+ return sriov_numvfs
+
+ @staticmethod
+ def set_sriov_numvfs(node, pf_pci_addr, numvfs=0):
+ """Init or reset SR-IOV virtual functions by setting its number on PCI
+ device on DUT. Setting to zero removes all VFs.
+
+ :param node: DUT node.
+ :param pf_pci_addr: Physical Function PCI device address.
+ :param numvfs: Number of VFs to initialize, 0 - removes the VFs.
+ :type node: dict
+ :type pf_pci_addr: str
+ :type numvfs: int
+ :raises RuntimeError: Failed to create VFs on PCI.
+ """
+ command = "sh -c "\
+ "'echo {num} | tee /sys/bus/pci/devices/{pci}/sriov_numvfs'".\
+ format(num=numvfs, pci=pf_pci_addr.replace(':', r'\:'))
+ message = 'Failed to create {num} VFs on {pci} device on {host}'.\
+ format(num=numvfs, pci=pf_pci_addr, host=node['host'])
+
+ exec_cmd_no_error(node, command, timeout=120, sudo=True,
+ message=message)