Ejemplo n.º 1
0
    def get_config(self, instance, network, mapping, image_meta, inst_type):
        conf = vconfig.LibvirtConfigGuestInterface()
        # Default to letting libvirt / the hypervisor choose the model
        model = None
        driver = None

        # If the user has specified a 'vif_model' against the
        # image then honour that model
        if image_meta:
            vif_model = image_meta.get('properties', {}).get('hw_vif_model')
            if vif_model is not None:
                model = vif_model

        # Else if the virt type is KVM/QEMU, use virtio according
        # to the global config parameter
        if (model is None and CONF.libvirt_type in ('kvm', 'qemu')
                and CONF.libvirt_use_virtio_for_bridges):
            model = "virtio"

        # Workaround libvirt bug, where it mistakenly
        # enables vhost mode, even for non-KVM guests
        if model == "virtio" and CONF.libvirt_type == "qemu":
            driver = "qemu"

        if not is_vif_model_valid_for_virt(CONF.libvirt_type, model):
            raise exception.UnsupportedHardware(model=model,
                                                virt=CONF.libvirt_type)

        designer.set_vif_guest_frontend_config(conf, mapping['mac'], model,
                                               driver)

        return conf
Ejemplo n.º 2
0
    def get_config(self, instance, vif, image_meta, inst_type):
        conf = vconfig.LibvirtConfigGuestInterface()
        # Default to letting libvirt / the hypervisor choose the model
        model = None
        driver = None

        # If the user has specified a 'vif_model' against the
        # image then honour that model
        if image_meta:
            vif_model = image_meta.get('properties',
                                       {}).get('hw_vif_model')
            if vif_model is not None:
                model = vif_model

        # Else if the virt type is KVM/QEMU, use virtio according
        # to the global config parameter
        if (model is None and
            CONF.libvirt.virt_type in ('kvm', 'qemu') and
                    CONF.libvirt.use_virtio_for_bridges):
            model = "virtio"

        # Workaround libvirt bug, where it mistakenly
        # enables vhost mode, even for non-KVM guests
        if model == "virtio" and CONF.libvirt.virt_type == "qemu":
            driver = "qemu"

        if not is_vif_model_valid_for_virt(CONF.libvirt.virt_type,
                                           model):
            raise exception.UnsupportedHardware(model=model,
                                                virt=CONF.libvirt.virt_type)

        designer.set_vif_guest_frontend_config(
            conf, vif['address'], model, driver)

        return conf
Ejemplo n.º 3
0
    def get_base_config(self, instance, mac, image_meta, inst_type, virt_type):
        conf = vconfig.LibvirtConfigGuestInterface()
        # Default to letting libvirt / the hypervisor choose the model
        model = None
        driver = None
        vhost_queues = None

        # If the user has specified a 'vif_model' against the
        # image then honour that model
        if image_meta:
            model = osinfo.HardwareProperties(image_meta).network_model

        # Else if the virt type is KVM/QEMU, use virtio according
        # to the global config parameter
        if (model is None and virt_type in ('kvm', 'qemu')
                and CONF.libvirt.use_virtio_for_bridges):
            model = network_model.VIF_MODEL_VIRTIO

        # Workaround libvirt bug, where it mistakenly
        # enables vhost mode, even for non-KVM guests
        if (model == network_model.VIF_MODEL_VIRTIO and virt_type == "qemu"):
            driver = "qemu"

        if not is_vif_model_valid_for_virt(virt_type, model):
            raise exception.UnsupportedHardware(model=model, virt=virt_type)
        if (virt_type == 'kvm' and model == network_model.VIF_MODEL_VIRTIO):
            vhost_drv, vhost_queues = self._get_virtio_mq_settings(
                image_meta, inst_type)
            driver = vhost_drv or driver

        designer.set_vif_guest_frontend_config(conf, mac, model, driver,
                                               vhost_queues)

        return conf
Ejemplo n.º 4
0
 def test_set_vif_guest_frontend_config(self):
     conf = config.LibvirtConfigGuestInterface()
     designer.set_vif_guest_frontend_config(conf, "fake-mac", "fake-model", "fake-driver", "fake-queues")
     self.assertEqual("fake-mac", conf.mac_addr)
     self.assertEqual("fake-model", conf.model)
     self.assertEqual("fake-driver", conf.driver_name)
     self.assertEqual("fake-queues", conf.vhost_queues)
Ejemplo n.º 5
0
Archivo: vif.py Proyecto: isyippee/nova
    def get_base_config(self, instance, vif, image_meta, inst_type, virt_type):
        conf = vconfig.LibvirtConfigGuestInterface()
        # Default to letting libvirt / the hypervisor choose the model
        model = None
        driver = None
        vhost_queues = None

        # If the user has specified a 'vif_model' against the
        # image then honour that model
        if image_meta:
            vif_model = image_meta.properties.get("hw_vif_model")
            if vif_model is not None:
                model = vif_model

        # Else if the virt type is KVM/QEMU, use virtio according
        # to the global config parameter
        if model is None and virt_type in ("kvm", "qemu") and CONF.libvirt.use_virtio_for_bridges:
            model = network_model.VIF_MODEL_VIRTIO

        # Workaround libvirt bug, where it mistakenly
        # enables vhost mode, even for non-KVM guests
        if model == network_model.VIF_MODEL_VIRTIO and virt_type == "qemu":
            driver = "qemu"

        if not is_vif_model_valid_for_virt(virt_type, model):
            raise exception.UnsupportedHardware(model=model, virt=virt_type)
        if virt_type == "kvm" and model == network_model.VIF_MODEL_VIRTIO:
            vhost_drv, vhost_queues = self._get_virtio_mq_settings(image_meta, inst_type)
            driver = vhost_drv or driver

        designer.set_vif_guest_frontend_config(conf, vif["address"], model, driver, vhost_queues)

        return conf
Ejemplo n.º 6
0
 def test_set_vif_guest_frontend_config(self):
     conf = config.LibvirtConfigGuestInterface()
     designer.set_vif_guest_frontend_config(conf, 'fake-mac', 'fake-model',
                                            'fake-driver', 'fake-queues')
     self.assertEqual('fake-mac', conf.mac_addr)
     self.assertEqual('fake-model', conf.model)
     self.assertEqual('fake-driver', conf.driver_name)
     self.assertEqual('fake-queues', conf.vhost_queues)
Ejemplo n.º 7
0
def get_interface_xml(mac_address, bridge, interface):
    from nova.virt.libvirt import designer
    from nova.virt.libvirt.config import LibvirtConfigGuestInterface
    conf = LibvirtConfigGuestInterface()
    model = 'virtio'
    driver = None
    designer.set_vif_guest_frontend_config(conf, mac_address, model, driver)
    designer.set_vif_host_backend_bridge_config(conf, bridge, interface)
    return conf
Ejemplo n.º 8
0
 def test_set_vif_guest_frontend_config_rx_queue_size(self):
     conf = config.LibvirtConfigGuestInterface()
     designer.set_vif_guest_frontend_config(conf, 'fake-mac',
                                            'fake-model', 'fake-driver',
                                            'fake-queues', 1024)
     self.assertEqual('fake-mac', conf.mac_addr)
     self.assertEqual('fake-model', conf.model)
     self.assertEqual('fake-driver', conf.driver_name)
     self.assertEqual('fake-queues', conf.vhost_queues)
     self.assertEqual(1024, conf.vhost_rx_queue_size)
Ejemplo n.º 9
0
    def get_config(self, instance, network, mapping):
        conf = vconfig.LibvirtConfigGuestInterface()
        model = None
        driver = None
        if CONF.libvirt_type in ("kvm", "qemu") and CONF.libvirt_use_virtio_for_bridges:
            model = "virtio"
            # Workaround libvirt bug, where it mistakenly
            # enables vhost mode, even for non-KVM guests
            if CONF.libvirt_type == "qemu":
                driver = "qemu"

        designer.set_vif_guest_frontend_config(conf, mapping["mac"], model, driver)

        return conf
Ejemplo n.º 10
0
    def get_config(self, instance, network, mapping):
        conf = vconfig.LibvirtConfigGuestInterface()
        model = None
        driver = None
        if (CONF.libvirt_type in ('kvm', 'qemu')
                and CONF.libvirt_use_virtio_for_bridges):
            model = "virtio"
            # Workaround libvirt bug, where it mistakenly
            # enables vhost mode, even for non-KVM guests
            if CONF.libvirt_type == "qemu":
                driver = "qemu"

        designer.set_vif_guest_frontend_config(conf, mapping['mac'], model,
                                               driver)

        return conf
Ejemplo n.º 11
0
    def get_base_config(self, instance, vif, image_meta,
                        inst_type, virt_type):
        conf = vconfig.LibvirtConfigGuestInterface()
        # Default to letting libvirt / the hypervisor choose the model
        model = None
        driver = None
        vhost_queues = None

        # If the user has specified a 'vif_model' against the
        # image then honour that model
        if image_meta:
            #model = osinfo.HardwareProperties(image_meta).network_model
            model = image_meta.properties.get('hw_vif_model', None)
            disable_csum = image_meta.properties.get('hw_vif_disable_csum', True)
            #if disable_csum.lower() in ('yes', '1', 'true'):
            conf.disable_csum = disable_csum
        # Else if the virt type is KVM/QEMU, use virtio according
        # to the global config parameter
        if (model is None and
            virt_type in ('kvm', 'qemu') and
                    CONF.libvirt.use_virtio_for_bridges):
            model = network_model.VIF_MODEL_VIRTIO

        # Workaround libvirt bug, where it mistakenly
        # enables vhost mode, even for non-KVM guests
        if (model == network_model.VIF_MODEL_VIRTIO and
            virt_type == "qemu"):
            driver = "qemu"

        if not is_vif_model_valid_for_virt(virt_type,
                                           model):
            raise exception.UnsupportedHardware(model=model,
                                                virt=virt_type)
        if (virt_type == 'kvm' and
            model == network_model.VIF_MODEL_VIRTIO):
            vhost_drv, vhost_queues = self._get_virtio_mq_settings(image_meta,
                                                                   inst_type)
            driver = vhost_drv or driver

        designer.set_vif_guest_frontend_config(
            conf, vif['address'], model, driver, vhost_queues)

        return conf
Ejemplo n.º 12
0
Archivo: vif.py Proyecto: andymcc/nova
    def get_base_config(self, instance, mac, image_meta,
                        inst_type, virt_type, vnic_type):
        conf = vconfig.LibvirtConfigGuestInterface()
        # Default to letting libvirt / the hypervisor choose the model
        model = None
        driver = None
        vhost_queues = None

        # If the user has specified a 'vif_model' against the
        # image then honour that model
        if image_meta:
            model = osinfo.HardwareProperties(image_meta).network_model

        # Else if the virt type is KVM/QEMU/VZ(Parallels), then use virtio
        # according to the global config parameter
        if (model is None and
            virt_type in ('kvm', 'qemu', 'parallels') and
                    CONF.libvirt.use_virtio_for_bridges):
            model = network_model.VIF_MODEL_VIRTIO

        # Workaround libvirt bug, where it mistakenly
        # enables vhost mode, even for non-KVM guests
        if (model == network_model.VIF_MODEL_VIRTIO and
            virt_type == "qemu"):
            driver = "qemu"

        if not is_vif_model_valid_for_virt(virt_type,
                                           model):
            raise exception.UnsupportedHardware(model=model,
                                                virt=virt_type)
        if (virt_type in ('kvm', 'parallels') and
            model == network_model.VIF_MODEL_VIRTIO and
            vnic_type not in network_model.VNIC_TYPES_SRIOV):
            vhost_drv, vhost_queues = self._get_virtio_mq_settings(image_meta,
                                                                   inst_type)
            driver = vhost_drv or driver

        designer.set_vif_guest_frontend_config(
            conf, mac, model, driver, vhost_queues)

        return conf
Ejemplo n.º 13
0
    def get_base_config(self, instance, vif, image_meta,
                        inst_type, virt_type):
        conf = vconfig.LibvirtConfigGuestInterface()
        # Default to letting libvirt / the hypervisor choose the model
        model = None
        driver = None

        # If the user has specified a 'vif_model' against the
        # image then honour that model
        if image_meta:
            vif_model = image_meta.get('properties',
                                       {}).get('hw_vif_model')
            if vif_model is not None:
                model = vif_model
            disable_csum = image_meta.get('properties',
                                          {}).get('hw_vif_disable_csum', 'no')
            if disable_csum.lower() in ('yes', '1', 'true'):
                conf.disable_csum = True

        # Else if the virt type is KVM/QEMU, use virtio according
        # to the global config parameter
        if (model is None and
            virt_type in ('kvm', 'qemu') and
                    CONF.libvirt.use_virtio_for_bridges):
            model = network_model.VIF_MODEL_VIRTIO

        # Workaround libvirt bug, where it mistakenly
        # enables vhost mode, even for non-KVM guests
        if (model == network_model.VIF_MODEL_VIRTIO and
            virt_type == "qemu"):
            driver = "qemu"

        if not is_vif_model_valid_for_virt(virt_type,
                                           model):
            raise exception.UnsupportedHardware(model=model,
                                                virt=virt_type)

        designer.set_vif_guest_frontend_config(
            conf, vif['address'], model, driver)

        return conf
Ejemplo n.º 14
0
Archivo: vif.py Proyecto: YLTiny/nova
    def get_base_config(self, instance, mac, image_meta, inst_type, virt_type,
                        vnic_type):
        # TODO(sahid): We should rewrite it. This method handles too
        # many unrelated things. We probably need to have a specific
        # virtio, vhost, vhostuser functions.

        conf = vconfig.LibvirtConfigGuestInterface()
        # Default to letting libvirt / the hypervisor choose the model
        model = None
        driver = None
        vhost_queues = None
        rx_queue_size = None

        # NOTE(stephenfin): Skip most things here as only apply to virtio
        # devices
        if vnic_type in network_model.VNIC_TYPES_DIRECT_PASSTHROUGH:
            designer.set_vif_guest_frontend_config(conf, mac, model, driver,
                                                   vhost_queues, rx_queue_size)
            return conf

        rx_queue_size = CONF.libvirt.rx_queue_size

        # if model has already been defined,
        # image_meta contents will override it
        model = self.get_vif_model(image_meta=image_meta, vif_model=model)

        if not is_vif_model_valid_for_virt(virt_type, model):
            raise exception.UnsupportedHardware(model=model, virt=virt_type)

        # The rest of this only applies to virtio
        if model != network_model.VIF_MODEL_VIRTIO:
            designer.set_vif_guest_frontend_config(conf, mac, model, driver,
                                                   vhost_queues, rx_queue_size)
            return conf

        # Workaround libvirt bug, where it mistakenly enables vhost mode, even
        # for non-KVM guests
        if virt_type == 'qemu':
            driver = 'qemu'

        if virt_type in ('kvm', 'parallels'):
            vhost_drv, vhost_queues = self._get_virtio_mq_settings(
                image_meta, inst_type)
            # TODO(sahid): It seems that we return driver 'vhost' even
            # for vhostuser interface where for vhostuser interface
            # the driver should be 'vhost-user'. That currently does
            # not create any issue since QEMU ignores the driver
            # argument for vhostuser interface but we should probably
            # fix that anyway. Also we should enforce that the driver
            # use vhost and not None.
            driver = vhost_drv or driver

        if driver == 'vhost' or driver is None:
            # vhost backend only supports update of RX queue size
            if CONF.libvirt.rx_queue_size:
                # TODO(sahid): Specifically force driver to be vhost
                # that because if None we don't generate the XML
                # driver element needed to set the queue size
                # attribute. This can be removed when get_base_config
                # will be fixed and rewrite to set the correct
                # backend.
                driver = 'vhost'

        designer.set_vif_guest_frontend_config(conf, mac, model, driver,
                                               vhost_queues, rx_queue_size)

        return conf
Ejemplo n.º 15
0
    def get_base_config(self, instance, mac, image_meta,
                        inst_type, virt_type, vnic_type, host):
        # TODO(sahid): We should rewrite it. This method handles too
        # many unrelated things. We probably need to have a specific
        # virtio, vhost, vhostuser functions.

        conf = vconfig.LibvirtConfigGuestInterface()
        # Default to letting libvirt / the hypervisor choose the model
        model = None
        driver = None
        vhost_queues = None

        # If the user has specified a 'vif_model' against the
        # image then honour that model
        if image_meta:
            model = osinfo.HardwareProperties(image_meta).network_model

        # Note(moshele): Skip passthough vnic_types as they don't support
        # virtio model.
        if vnic_type not in network_model.VNIC_TYPES_DIRECT_PASSTHROUGH:
            # Else if the virt type is KVM/QEMU/VZ(Parallels), then use virtio
            # according to the global config parameter
            if (model is None and
                virt_type in ('kvm', 'qemu', 'parallels') and
                        CONF.libvirt.use_virtio_for_bridges):
                model = network_model.VIF_MODEL_VIRTIO

        # Workaround libvirt bug, where it mistakenly
        # enables vhost mode, even for non-KVM guests
        if (model == network_model.VIF_MODEL_VIRTIO and
            virt_type == "qemu"):
            driver = "qemu"

        if not is_vif_model_valid_for_virt(virt_type,
                                           model):
            raise exception.UnsupportedHardware(model=model,
                                                virt=virt_type)
        if (virt_type in ('kvm', 'parallels') and
            model == network_model.VIF_MODEL_VIRTIO):
            vhost_drv, vhost_queues = self._get_virtio_mq_settings(image_meta,
                                                                   inst_type)
            # TODO(sahid): It seems that we return driver 'vhost' even
            # for vhostuser interface where for vhostuser interface
            # the driver should be 'vhost-user'. That currently does
            # not create any issue since QEMU ignores the driver
            # argument for vhostuser interface but we should probably
            # fix that anyway. Also we should enforce that the driver
            # use vhost and not None.
            driver = vhost_drv or driver

        rx_queue_size = None
        # Note(moshele): rx_queue_size is support only for virtio model
        if model == network_model.VIF_MODEL_VIRTIO:
            if driver == 'vhost' or driver is None:
                # vhost backend only supports update of RX queue size
                rx_queue_size, _ = self._get_virtio_queue_sizes(host)
                if rx_queue_size:
                    # TODO(sahid): Specifically force driver to be vhost
                    # that because if None we don't generate the XML
                    # driver element needed to set the queue size
                    # attribute. This can be removed when get_base_config
                    # will be fixed and rewrite to set the correct
                    # backend.
                    driver = 'vhost'

        designer.set_vif_guest_frontend_config(
            conf, mac, model, driver, vhost_queues, rx_queue_size)

        return conf
Ejemplo n.º 16
0
    def get_base_config(self, instance, mac, image_meta,
                        inst_type, virt_type, vnic_type, host):
        # TODO(sahid): We should rewrite it. This method handles too
        # many unrelated things. We probably need to have a specific
        # virtio, vhost, vhostuser functions.

        conf = vconfig.LibvirtConfigGuestInterface()
        # Default to letting libvirt / the hypervisor choose the model
        model = None
        driver = None
        vhost_queues = None

        # If the user has specified a 'vif_model' against the
        # image then honour that model
        if image_meta:
            model = osinfo.HardwareProperties(image_meta).network_model

        # Else if the virt type is KVM/QEMU/VZ(Parallels), then use virtio
        # according to the global config parameter
        if (model is None and
            virt_type in ('kvm', 'qemu', 'parallels') and
                    CONF.libvirt.use_virtio_for_bridges):
            model = network_model.VIF_MODEL_VIRTIO

        # Workaround libvirt bug, where it mistakenly
        # enables vhost mode, even for non-KVM guests
        if (model == network_model.VIF_MODEL_VIRTIO and
            virt_type == "qemu"):
            driver = "qemu"

        if not is_vif_model_valid_for_virt(virt_type,
                                           model):
            raise exception.UnsupportedHardware(model=model,
                                                virt=virt_type)
        if (virt_type in ('kvm', 'parallels') and
            model == network_model.VIF_MODEL_VIRTIO and
            vnic_type not in network_model.VNIC_TYPES_SRIOV):
            vhost_drv, vhost_queues = self._get_virtio_mq_settings(image_meta,
                                                                   inst_type)
            # TODO(sahid): It seems that we return driver 'vhost' even
            # for vhostuser interface where for vhostuser interface
            # the driver should be 'vhost-user'. That currently does
            # not create any issue since QEMU ignores the driver
            # argument for vhostuser interface but we should probably
            # fix that anyway. Also we should enforce that the driver
            # use vhost and not None.
            driver = vhost_drv or driver

        rx_queue_size = None
        if driver == 'vhost' or driver is None:
            # vhost backend only supports update of RX queue size
            rx_queue_size, _ = self._get_virtio_queue_sizes(host)
            if rx_queue_size:
                # TODO(sahid): Specifically force driver to be vhost
                # that because if None we don't generate the XML
                # driver element needed to set the queue size
                # attribute. This can be removed when get_base_config
                # will be fixed and rewrite to set the correct
                # backend.
                driver = 'vhost'

        designer.set_vif_guest_frontend_config(
            conf, mac, model, driver, vhost_queues, rx_queue_size)

        return conf