Esempio n. 1
0
    def _plug_os_vif(self, instance, vif, raw_vif):
        instance_info = os_vif_util.nova_to_osvif_instance(instance)

        try:
            os_vif.plug(vif, instance_info)
        except osv_exception.ExceptionBase as ex:
            msg = (_("Failure running os_vif plugin plug method: %(ex)s")
                   % {'ex': ex})
            raise exception.NovaException(msg)

        # TODO(johngarbutt) remove this hack once 1623876 is fixed in os-vif
        network = raw_vif.get('network')
        mtu = network.get_meta('mtu') if network else None
        if mtu is not None:
            linux_net._set_device_mtu(network["bridge"], mtu)

        if (type(vif) == os_vif.objects.vif.VIFBridge and
            hasattr(vif, "port_profile") and
            isinstance(vif.port_profile,
                       os_vif.objects.vif.VIFPortProfileOpenVSwitch)):
            veths = [
                ("qvb%s" % vif.id)[:network_model.NIC_NAME_LEN],
                ("qvo%s" % vif.id)[:network_model.NIC_NAME_LEN]]
            for veth in veths:
                linux_net._set_device_mtu(veth, mtu)
Esempio n. 2
0
    def _plug_os_vif(self, instance, vif, raw_vif):
        instance_info = os_vif_util.nova_to_osvif_instance(instance)

        try:
            os_vif.plug(vif, instance_info)
        except osv_exception.ExceptionBase as ex:
            msg = (_("Failure running os_vif plugin plug method: %(ex)s") % {
                'ex': ex
            })
            raise exception.NovaException(msg)

        # TODO(johngarbutt) remove this hack once 1623876 is fixed in os-vif
        network = raw_vif.get('network')
        mtu = network.get_meta('mtu') if network else None
        if mtu is not None:
            linux_net._set_device_mtu(network["bridge"], mtu)

        if (type(vif) == os_vif.objects.vif.VIFBridge
                and hasattr(vif, "port_profile")
                and isinstance(vif.port_profile,
                               os_vif.objects.vif.VIFPortProfileOpenVSwitch)):
            veths = [("qvb%s" % vif.id)[:network_model.NIC_NAME_LEN],
                     ("qvo%s" % vif.id)[:network_model.NIC_NAME_LEN]]
            for veth in veths:
                linux_net._set_device_mtu(veth, mtu)
Esempio n. 3
0
def connect(vif, instance_info, ifname, netns=None, report_health=None):
    driver = _get_binding_driver(vif)
    if report_health:
        report_health(driver.is_healthy())
    os_vif.plug(vif, instance_info)
    driver.connect(vif, ifname, netns)
    _configure_l3(vif, ifname, netns)
Esempio n. 4
0
def connect(vif, instance_info, ifname, netns=None, report_health=None,
            is_default_gateway=True, container_id=None):
    driver = _get_binding_driver(vif)
    if report_health:
        report_health(driver.is_alive())
    os_vif.plug(vif, instance_info)
    driver.connect(vif, ifname, netns, container_id)
    if _need_configure_l3(vif):
        _configure_l3(vif, ifname, netns, is_default_gateway)
Esempio n. 5
0
 def test_plug(self):
     plugin = mock.MagicMock()
     with mock.patch('stevedore.extension.ExtensionManager',
                     return_value={'foobar': plugin}):
         os_vif.initialize()
         instance = mock.MagicMock()
         vif = objects.vif.VIF(id='uniq', plugin='foobar')
         os_vif.plug(vif, instance)
         plugin.plug.assert_called_once_with(vif, instance)
Esempio n. 6
0
def connect(vif, instance_info, ifname, netns=None,
            is_default_gateway=True, container_id=None):
    netns = utils.convert_netns(netns)
    driver = _get_binding_driver(vif)
    os_vif.plug(vif, instance_info)
    driver.connect(vif, ifname, netns, container_id)
    if _need_configure_l3(vif):
        vif_dict = utils.osvif_vif_to_dict(vif)
        _configure_l3(vif_dict, ifname, netns, is_default_gateway)
Esempio n. 7
0
 def test_plug(self):
     plugin = mock.MagicMock()
     with mock.patch('stevedore.extension.ExtensionManager',
                     return_value={'foobar': plugin}):
         os_vif.initialize()
         instance = mock.MagicMock()
         vif = objects.vif.VIF(id='uniq', plugin='foobar')
         os_vif.plug(vif, instance)
         plugin.plug.assert_called_once_with(vif, instance)
Esempio n. 8
0
    def _plug_os_vif(self, instance, vif):
        instance_info = os_vif_util.nova_to_osvif_instance(instance)

        try:
            os_vif.plug(vif, instance_info)
        except osv_exception.ExceptionBase as ex:
            msg = (_("Failure running os_vif plugin plug method: %(ex)s")
                   % {'ex': ex})
            raise exception.InternalError(msg)
Esempio n. 9
0
File: vif.py Progetto: andymcc/nova
    def _plug_os_vif(self, instance, vif):
        instance_info = os_vif_util.nova_to_osvif_instance(instance)

        try:
            os_vif.plug(vif, instance_info)
        except osv_exception.ExceptionBase as ex:
            msg = (_("Failure running os_vif plugin plug method: %(ex)s")
                   % {'ex': ex})
            raise exception.InternalError(msg)
Esempio n. 10
0
    def plug(self, instance, vif):
        vif_type = vif['type']
        instance_info = os_vif_util.nova_to_osvif_instance(instance)

        # Try os-vif codepath first
        vif_obj = os_vif_util.nova_to_osvif_vif(vif)
        if vif_obj is not None:
            os_vif.plug(vif_obj, instance_info)
            return

        # Legacy non-os-vif codepath
        func = getattr(self, 'plug_%s' % vif_type, None)
        if not func:
            raise exception.InternalError("Unexpected vif_type=%s" % vif_type)
        func(instance, vif)
 def test_plug(self, mock_plug):
     plg = extension.Extension(name="noop",
                               entry_point="os-vif",
                               plugin=NoOpPlugin,
                               obj=None)
     with mock.patch('stevedore.extension.ExtensionManager.names',
                     return_value=['foobar']),\
             mock.patch('stevedore.extension.ExtensionManager.__getitem__',
                        return_value=plg):
         os_vif.initialize()
         info = mock.sentinel.info
         vif = mock.MagicMock()
         vif.plugin_name = 'noop'
         os_vif.plug(vif, info)
         mock_plug.assert_called_once_with(vif, info)
Esempio n. 12
0
 def test_plug(self, mock_plug):
     plg = extension.Extension(name="demo",
                               entry_point="os-vif",
                               plugin=DemoPlugin,
                               obj=None)
     with mock.patch('stevedore.extension.ExtensionManager.names',
                     return_value=['foobar']),\
             mock.patch('stevedore.extension.ExtensionManager.__getitem__',
                        return_value=plg):
         os_vif.initialize()
         info = objects.instance_info.InstanceInfo()
         vif = objects.vif.VIFBridge(
             id='9a12694f-f95e-49fa-9edb-70239aee5a2c', plugin='foobar')
         os_vif.plug(vif, info)
         mock_plug.assert_called_once_with(vif, info)
Esempio n. 13
0
 def test_plug(self, mock_plug):
     plg = extension.Extension(name="demo",
                               entry_point="os-vif",
                               plugin=DemoPlugin,
                               obj=None)
     with mock.patch('stevedore.extension.ExtensionManager.names',
                     return_value=['foobar']),\
             mock.patch('stevedore.extension.ExtensionManager.__getitem__',
                        return_value=plg):
         os_vif.initialize()
         info = objects.instance_info.InstanceInfo()
         vif = objects.vif.VIFBridge(
             id='9a12694f-f95e-49fa-9edb-70239aee5a2c',
             plugin='foobar')
         os_vif.plug(vif, info)
         mock_plug.assert_called_once_with(vif, info)
Esempio n. 14
0
    def plug(self, instance, vif):
        vif_type = vif['type']
        if vif_type == model.VIF_TYPE_HYPERV:
            self._vif_plugin.plug(instance, vif)
        elif vif_type == model.VIF_TYPE_OVS:
            vif = os_vif_util.nova_to_osvif_vif(vif)
            instance = os_vif_util.nova_to_osvif_instance(instance)

            # NOTE(claudiub): the vNIC has to be connected to a vSwitch
            # before the ovs port is created.
            self._netutils.connect_vnic_to_vswitch(CONF.hyperv.vswitch_name,
                                                   vif.id)
            os_vif.plug(vif, instance)
        else:
            reason = _("Failed to plug virtual interface: "
                       "unexpected vif_type=%s") % vif_type
            raise exception.VirtualInterfacePlugException(reason)
Esempio n. 15
0
    def plug(self, instance, vif):
        vif_type = vif['type']
        if vif_type == model.VIF_TYPE_HYPERV:
            self._vif_plugin.plug(instance, vif)
        elif vif_type == model.VIF_TYPE_OVS:
            vif = os_vif_util.nova_to_osvif_vif(vif)
            instance = os_vif_util.nova_to_osvif_instance(instance)

            # NOTE(claudiub): the vNIC has to be connected to a vSwitch
            # before the ovs port is created.
            self._netutils.connect_vnic_to_vswitch(CONF.hyperv.vswitch_name,
                                                   vif.id)
            os_vif.plug(vif, instance)
        else:
            reason = _("Failed to plug virtual interface: "
                       "unexpected vif_type=%s") % vif_type
            raise exception.VirtualInterfacePlugException(reason)
Esempio n. 16
0
    def plug(self, instance, vif):
        vif_type = vif['type']
        instance_info = os_vif_util.nova_to_osvif_instance(instance)

        # Try os-vif codepath first
        vif_obj = os_vif_util.nova_to_osvif_vif(vif)
        if vif_obj is not None:
            os_vif.plug(vif_obj, instance_info)
        else:
            # Legacy non-os-vif codepath
            func = getattr(self, 'plug_%s' % vif_type, None)
            if not func:
                raise exception.InternalError(
                    "Unexpected vif_type=%s" % vif_type
                )
            func(instance, vif)

        _post_plug_wiring(instance, vif)
Esempio n. 17
0
def connect(vif, instance_info, ifname, netns=None):
    driver = _get_binding_driver(vif)
    os_vif.plug(vif, instance_info)
    driver.connect(vif, ifname, netns)
    _configure_l3(vif, ifname, netns)
Esempio n. 18
0
    def plug(self, instance, vif):
        instance_info = os_vif_util.nova_to_osvif_instance(instance)
        vif_obj = os_vif_util.nova_to_osvif_vif(vif)

        os_vif.plug(vif_obj, instance_info)
Esempio n. 19
0
subnets = vif_objects.SubnetList([subnet])

network = vif_objects.Network(label='tenantnet',
                              subnets=subnets,
                              multi_host=False,
                              should_provide_vlan=False,
                              should_provide_bridge=False)

vif_uuid = uuid.uuid4()
vif = vif_objects.VIFVHostUser(id=vif_uuid,
                               address=None,
                               network=network,
                               plugin='vhostuser',
                               mode=vif_objects.fields.VIFVHostUserMode.SERVER)

# Now do the actual plug operations to connect the VIF to
# the backing network interface.
try:
    os_vif.plug(vif, instance_info)
except vif_exc.PlugException as err:
    # Handle the failure...
    pass

# If you are removing a virtual machine and its interfaces,
# you would use the unplug() operation:
try:
    os_vif.unplug(vif, instance_info)
except vif_exc.UnplugException as err:
    # Handle the failure...
    pass