Esempio n. 1
0
    def tick(self):
        if not self.nodedev_obj:
            return
        if not self.nodedev_obj.conn.is_active():
            return

        try:
            self.nodedev_obj.refresh_xml()
            xml = self.nodedev_obj.get_xml()
        except:
            # Assume the device was removed
            return

        try:
            vobj = NodeDevice.parse(self.nodedev_obj.conn.get_backend(), xml)
            has_media = vobj.media_available or False
        except:
            logging.exception("Node device CDROM polling failed")
            return

        if has_media == self.has_media():
            return

        self.set_media(has_media, None, None)
        self.idle_emit(has_media and "media-added" or "media-removed")
Esempio n. 2
0
    def tick(self):
        if not self.nodedev_obj:
            return
        if not self.nodedev_obj.conn.is_active():
            return

        try:
            self.nodedev_obj.refresh_xml()
            xml = self.nodedev_obj.get_xml()
        except:
            # Assume the device was removed
            return

        try:
            vobj = NodeDevice.parse(self.nodedev_obj.conn.get_backend(), xml)
            has_media = vobj.media_available or False
        except:
            logging.exception("Node device CDROM polling failed")
            return

        if has_media == self.has_media():
            return

        self.set_media(has_media, None, None)
        self.idle_emit(has_media and "media-added" or "media-removed")
Esempio n. 3
0
    def _populate_sriov_state(self, net):
        (is_vf_pool, pf_name, vfs) = net.get_sriov_vf_networks()

        self.widget("net-sriov-expander").set_visible(is_vf_pool)
        if not pf_name:
            self.widget("pf-name").set_text("N/A")
            return

        self.widget("pf-name").set_text(pf_name)

        vf_list_model = self.widget("vf-list").get_model()
        vf_list_model.clear()
        for vf in vfs:
            addrStr = "%x:%x:%x.%x" % (vf.domain, vf.bus, vf.slot, vf.function)
            pcidev = NodeDevice.lookupNodedevFromString(
                self.conn.get_backend(), addrStr)

            vf_name = None

            netdevs = self.conn.filter_nodedevs("net")
            for netdev in netdevs:
                logging.debug(netdev.xmlobj.parent)
                if pcidev.name == netdev.xmlobj.parent:
                    vf_name = netdev.xmlobj.interface
                    break

            vf_list_model.append([vf_name or addrStr])
Esempio n. 4
0
    def _populate_sriov_state(self, net):
        (is_vf_pool, pf_name, vfs) = net.get_sriov_vf_networks()

        self.widget("net-sriov-expander").set_visible(is_vf_pool)
        if not pf_name:
            self.widget("pf-name").set_text("N/A")
            return

        self.widget("pf-name").set_text(pf_name)

        vf_list_model = self.widget("vf-list").get_model()
        vf_list_model.clear()
        for vf in vfs:
            addrStr = "%x:%x:%x.%x" % (vf.domain, vf.bus, vf.slot, vf.function)
            pcidev = NodeDevice.lookupNodedevFromString(self.conn.get_backend(),
                                                        addrStr)

            vf_name = None

            netdevs = self.conn.filter_nodedevs("net")
            for netdev in netdevs:
                logging.debug(netdev.xmlobj.parent)
                if pcidev.name == netdev.xmlobj.parent:
                    vf_name = netdev.xmlobj.interface
                    break

            vf_list_model.append([vf_name or addrStr])
Esempio n. 5
0
    def _testCompare(self, devname, vals, devxml=None):
        if devxml:
            dev = NodeDevice.parse(conn, devxml)
        else:
            dev = self._nodeDevFromName(devname)

        for attr in vals.keys():
            expect = vals[attr]
            actual = getattr(dev, attr)
            if expect != actual:
                raise AssertionError("devname=%s attribute=%s did not match:\n"
                    "expect=%s\nactual=%s" % (devname, attr, expect, actual))
            self.assertEqual(vals[attr], getattr(dev, attr))
Esempio n. 6
0
    def _testCompare(self, devname, vals, devxml=None):
        if devxml:
            dev = NodeDevice.parse(conn, devxml)
        else:
            dev = self._nodeDevFromName(devname)

        for attr in vals.keys():
            expect = vals[attr]
            actual = getattr(dev, attr)
            if expect != actual:
                raise AssertionError("devname=%s attribute=%s did not match:\n"
                    "expect=%s\nactual=%s" % (devname, attr, expect, actual))
            self.assertEqual(vals[attr], getattr(dev, attr))
Esempio n. 7
0
def _pretty_name(xmlobj):
    if xmlobj.device_type == "net":
        return _("Interface %s") % xmlobj.interface or xmlobj.name

    if xmlobj.device_type == "pci":
        devstr = "%.4X:%.2X:%.2X:%X" % (int(xmlobj.domain), int(
            xmlobj.bus), int(xmlobj.slot), int(xmlobj.function))
        return "%s %s %s" % (devstr, xmlobj.vendor_name, xmlobj.product_name)
    if xmlobj.device_type == "usb_device":
        return _usb_pretty_name(xmlobj)

    if xmlobj.device_type == "drm":
        parent = NodeDevice.lookupNodedevFromString(xmlobj.conn, xmlobj.parent)
        return "%s (%s)" % (_pretty_name(parent), xmlobj.drm_type)

    return xmlobj.name  # pragma: no cover
Esempio n. 8
0
    def _testCompare(self, devname, vals, devxml=None):
        def _compare(dev, vals, root=""):
            for attr in list(vals.keys()):
                expect = vals[attr]
                actual = getattr(dev, attr)
                if isinstance(expect, list):
                    for adev, exp in zip(actual, expect):
                        _compare(adev, exp, attr + ".")
                else:
                    if expect != actual:
                        raise AssertionError("devname=%s attribute=%s%s did not match:\n"
                            "expect=%s\nactual=%s" % (devname, root, attr, expect, actual))
                    self.assertEqual(vals[attr], getattr(dev, attr))

        if devxml:
            dev = NodeDevice.parse(self.conn, devxml)
        else:
            dev = self._nodeDevFromName(devname)

        _compare(dev, vals)
        return dev
Esempio n. 9
0
    def _testCompare(self, devname, vals, devxml=None):
        def _compare(dev, vals, root=""):
            for attr in list(vals.keys()):
                expect = vals[attr]
                actual = getattr(dev, attr)
                if isinstance(expect, list):
                    for adev, exp in zip(actual, expect):
                        _compare(adev, exp, attr + ".")
                else:
                    if expect != actual:
                        raise AssertionError("devname=%s attribute=%s%s did not match:\n"
                            "expect=%s\nactual=%s" % (devname, root, attr, expect, actual))
                    self.assertEqual(vals[attr], getattr(dev, attr))

        if devxml:
            dev = NodeDevice.parse(self.conn, devxml)
        else:
            dev = self._nodeDevFromName(devname)

        _compare(dev, vals)
        return dev
Esempio n. 10
0
def _pretty_name(xmlobj):
    if xmlobj.device_type == "net":
        return _("Interface %s") % xmlobj.interface or xmlobj.name

    if xmlobj.device_type == "pci":
        devstr = "%.4X:%.2X:%.2X:%X" % (int(xmlobj.domain), int(
            xmlobj.bus), int(xmlobj.slot), int(xmlobj.function))
        return "%s %s %s" % (devstr, xmlobj.vendor_name, xmlobj.product_name)
    if xmlobj.device_type == "usb_device":
        return _usb_pretty_name(xmlobj)

    if xmlobj.device_type == "drm":
        parent = NodeDevice.lookupNodedevByName(xmlobj.conn, xmlobj.parent)

        # https://github.com/virt-manager/virt-manager/issues/328
        # Apparently we can't depend on successful parent lookup
        pretty_parent = xmlobj.parent
        if parent:
            pretty_parent = _pretty_name(parent)

        return "%s (%s)" % (pretty_parent, xmlobj.drm_type)

    return xmlobj.name  # pragma: no cover
Esempio n. 11
0
 def _nodeDevFromName(self, devname):
     node = conn.nodeDeviceLookupByName(devname)
     xml = node.XMLDesc(0)
     return NodeDevice.parse(conn, xml)
Esempio n. 12
0
def _parse_convert(conn, parsexml=None):
    return NodeDevice.parse(conn, parsexml)
Esempio n. 13
0
 def _nodeDevFromName(self, devname):
     node = conn.nodeDeviceLookupByName(devname)
     xml = node.XMLDesc(0)
     return NodeDevice.parse(conn, xml)
Esempio n. 14
0
 def testFunkyChars(self):
     # Ensure parsing doesn't fail
     dev = NodeDevice(self.conn, funky_chars_xml)
     self.assertEqual(dev.name, "L3B2616")
     self.assertEqual(dev.device_type, "LENOVO")
Esempio n. 15
0
def testFunkyChars():
    # Ensure parsing doesn't fail
    conn = utils.URIs.open_testdriver_cached()
    dev = NodeDevice(conn, funky_chars_xml)
    assert dev.name == "L3B2616"
    assert dev.device_type == "LENOVO"
Esempio n. 16
0
def _parse_convert(conn, parsexml=None):
    return NodeDevice.parse(conn, parsexml)