コード例 #1
0
    def get_pci_device_by_id(self, id):
        try:
            filters = {'id': id}
            pcis = self.list_pci_devices(filters=filters)
        except etcd.EtcdKeyNotFound:
            raise exception.PciDeviceNotFoundById(id=id)
        except Exception as e:
            LOG.error('Error occurred while retrieving pci device: %s',
                      six.text_type(e))
            raise

        if len(pcis) == 0:
            raise exception.PciDeviceNotFoundById(id=id)
        return pcis
コード例 #2
0
ファイル: test_utils.py プロジェクト: wanghuiict/zun
 def test_wrong_mac(self):
     self.mock_get_mac.side_effect = (
         exception.PciDeviceNotFoundById(self.pci_address))
     net_name = utils.get_net_name_by_vf_pci_address(self.pci_address)
     self.assertIsNone(net_name)
     self.mock_get_mac.called_once_with(self.pci_address)
     self.mock_get_ifname.assert_not_called()
コード例 #3
0
 def get_pci_device_by_id(self, id):
     pci_dev_ref = model_query(models.PciDevice).\
         filter_by(id=id).\
         first()
     if not pci_dev_ref:
         raise exception.PciDeviceNotFoundById(id=id)
     return pci_dev_ref
コード例 #4
0
ファイル: utils.py プロジェクト: zukobronja/zun
def get_ifname_by_pci_address(pci_addr, pf_interface=False):
    """Get the interface name based on a VF's pci address

    The returned interface name is either the parent PF's or that of the VF
    itself based on the argument of pf_interface.
    """
    dev_path = _get_sysfs_netdev_path(pci_addr, pf_interface)
    try:
        dev_info = os.listdir(dev_path)
        return dev_info.pop()
    except Exception:
        raise exception.PciDeviceNotFoundById(id=pci_addr)
コード例 #5
0
ファイル: utils.py プロジェクト: zukobronja/zun
def get_vf_num_by_pci_address(pci_addr):
    """Get the VF number based on a VF's pci address

    A VF is associated with an VF number, which ip link command uses to
    configure it. This number can be obtained from the PCI device filesystem.
    """
    VIRTFN_RE = re.compile("virtfn(\d+)")
    virtfns_path = "/sys/bus/pci/devices/%s/physfn/virtfn*" % (pci_addr)
    vf_num = None
    try:
        for vf_path in glob.iglob(virtfns_path):
            if re.search(pci_addr, os.readlink(vf_path)):
                t = VIRTFN_RE.search(vf_path)
                vf_num = t.group(1)
                break
    except Exception:
        pass
    if vf_num is None:
        raise exception.PciDeviceNotFoundById(id=pci_addr)
    return vf_num
コード例 #6
0
ファイル: utils.py プロジェクト: zukobronja/zun
def get_mac_by_pci_address(pci_addr, pf_interface=False):
    """Get the MAC address of the nic based on it's PCI address

    Raises PciDeviceNotFoundById in case the pci device is not a NIC
    """
    dev_path = _get_sysfs_netdev_path(pci_addr, pf_interface)
    if_name = get_ifname_by_pci_address(pci_addr, pf_interface)
    addr_file = os.path.join(dev_path, if_name, 'address')

    try:
        with open(addr_file) as f:
            mac = next(f).strip()
            return mac
    except (IOError, StopIteration) as e:
        LOG.warning(
            "Could not find the expected sysfs file for "
            "determining the MAC address of the PCI device "
            "%(addr)s. May not be a NIC. Error: %(e)s", {
                'addr': pci_addr,
                'e': e
            })
        raise exception.PciDeviceNotFoundById(id=pci_addr)