예제 #1
0
    def device_from_node(conn, name=None, nodedev=None):
        """
        Convert the passed device name to a VirtualHostDevice
        instance, with proper error reporting. Name can be any of the
        values accepted by NodeDeviceParser.lookupNodeName. If a node
        device name is not specified, a virtinst.NodeDevice instance can
        be passed in to create a dev from.

        @param conn: libvirt.virConnect instance to perform the lookup on
        @param name: optional libvirt node device name to lookup
        @param nodedev: optional L{virtinst.NodeDevice} instance to use

        @rtype: L{virtinst.VirtualHostDevice} instance
        """

        if not name and not nodedev:
            raise ValueError(_("'name' or 'nodedev' required."))

        if nodedev:
            nodeinst = nodedev
        else:
            nodeinst = NodeDeviceParser.lookupNodeName(conn, name)

        if isinstance(nodeinst, NodeDeviceParser.PCIDevice):
            return VirtualHostDevicePCI(conn, nodedev=nodeinst)
        elif isinstance(nodeinst, NodeDeviceParser.USBDevice):
            return VirtualHostDeviceUSB(conn, nodedev=nodeinst)
        elif isinstance(nodeinst, NodeDeviceParser.NetDevice):
            parentname = nodeinst.parent
            try:
                return VirtualHostDevice.device_from_node(conn,
                                                          name=parentname)
            except:
                logging.exception("Fetching net parent device failed.")

        raise ValueError(
            _("Node device type '%s' cannot be attached to "
              " guest.") % nodeinst.device_type)
예제 #2
0
    def setup(self, conn=None):
        """
        DEPRECATED: Please use setup_dev instead
        """
        if not conn:
            conn = self.conn

        if not NodeDeviceParser.is_pci_detach_capable(conn):
            return

        try:
            try:
                # Do this as a sanity check, so that we don't fail at domain
                # start time. This is independent of the 'managed' state, since
                # this should work regardless.
                node = conn.nodeDeviceLookupByName(self._nodedev.name)
                node.dettach()
                node.reset()
            except libvirt.libvirtError, e:
                if not support.is_error_nosupport(e):
                    raise
        except Exception, e:
            raise RuntimeError(_("Could not detach PCI device: %s" % str(e)))
    def setup(self, conn = None):
        """
        DEPRECATED: Please use setup_dev instead
        """
        if not conn:
            conn = self.conn

        if not NodeDeviceParser.is_pci_detach_capable(conn):
            return

        try:
            try:
                # Do this as a sanity check, so that we don't fail at domain
                # start time. This is independent of the 'managed' state, since
                # this should work regardless.
                node = conn.nodeDeviceLookupByName(self._nodedev.name)
                node.dettach()
                node.reset()
            except libvirt.libvirtError, e:
                if not support.is_error_nosupport(e):
                    raise
        except Exception, e:
            raise RuntimeError(_("Could not detach PCI device: %s" % str(e)))
    def device_from_node(conn, name=None, nodedev=None):
        """
        Convert the passed device name to a VirtualHostDevice
        instance, with proper error reporting. Name can be any of the
        values accepted by NodeDeviceParser.lookupNodeName. If a node
        device name is not specified, a virtinst.NodeDevice instance can
        be passed in to create a dev from.

        @param conn: libvirt.virConnect instance to perform the lookup on
        @param name: optional libvirt node device name to lookup
        @param nodedev: optional L{virtinst.NodeDevice} instance to use

        @rtype: L{virtinst.VirtualHostDevice} instance
        """

        if not name and not nodedev:
            raise ValueError(_("'name' or 'nodedev' required."))

        if nodedev:
            nodeinst = nodedev
        else:
            nodeinst = NodeDeviceParser.lookupNodeName(conn, name)

        if isinstance(nodeinst, NodeDeviceParser.PCIDevice):
            return VirtualHostDevicePCI(conn, nodedev=nodeinst)
        elif isinstance(nodeinst, NodeDeviceParser.USBDevice):
            return VirtualHostDeviceUSB(conn, nodedev=nodeinst)
        elif isinstance(nodeinst, NodeDeviceParser.NetDevice):
            parentname = nodeinst.parent
            try:
                return VirtualHostDevice.device_from_node(conn,
                                                          name=parentname)
            except:
                logging.exception("Fetching net parent device failed.")

        raise ValueError(_("Node device type '%s' cannot be attached to "
                           " guest.") % nodeinst.device_type)