nova compute 如何创建 ovs 端口

最近搞 qemu 使用 ovs internal port 出现了点问题,但是 neutron ovn 好像默认就是 internal port,所以这里想看下 nova compute 到底使用的是 ovs internal port 还是 linux tap 设备

这两个场景都在这个函数 _nw_info_build_network 中

设备名应该统一为 tap<11 位 port id>

1. 上面这个方法仅在 _build_network_info_model 使用

Return list of ordered VIFs attached to instance

返回需要插入到虚拟机中的有序的虚拟网卡列表

2. 上面这个方法仅在 _get_instance_nw_info 有调用

3. 上面这个方法在这几个方法中调用

update_instance_cache_with_nw_info( # 存一下数据库,忽略 get_instance_nw_info( # 主要关注 通用场景 add_fixed_ip_to_instance( # 特别场景,忽略 remove_fixed_ip_from_instance(

4. 仅需要关注 get_instance_nw_info 在最通用的 allocate_for_instance 方法中调用

5. 仅需要关注 allocate_for_instance 在 _attach_interface 中的使用

(另一个是远程调用 neutron 分配 ip)

只需要关注 ovs vsctl 相关的 driver 中的 attach_interface 实现即可

6. 只能是 libvirt 的实现

7. 结论: 只能是 linux tap 设备

python 复制代码
    def plug_tap(self, instance, vif):
        """Plug a VIF_TYPE_TAP virtual interface."""
        dev = self.get_vif_devname(vif)
        mac = vif['details'].get(network_model.VIF_DETAILS_TAP_MAC_ADDRESS)
        image_meta = instance.image_meta
        vif_model = self.get_vif_model(image_meta=image_meta)
        # TODO(ganso): explore whether multiqueue works for other vif models
        # that go through this code path.
        multiqueue = False
        if vif_model == network_model.VIF_MODEL_VIRTIO:
            multiqueue = hardware.get_vif_multiqueue_constraint(
                instance.flavor, image_meta)
        nova.privsep.linux_net.create_tap_dev(dev, mac, multiqueue=multiqueue)
        network = vif.get('network')
        mtu = network.get_meta('mtu') if network else None
        nova.privsep.linux_net.set_device_mtu(dev, mtu)

@nova.privsep.sys_admin_pctxt.entrypoint
def create_tap_dev(dev, mac_address=None, multiqueue=False):
    if not device_exists(dev):
        try:
            # First, try with 'ip'
            cmd = ('ip', 'tuntap', 'add', dev, 'mode', 'tap')
            if multiqueue:
                cmd = cmd + ('multi_queue', )
            processutils.execute(*cmd, check_exit_code=[0, 2, 254])
        except processutils.ProcessExecutionError:
            if multiqueue:
                LOG.warning(
                    'Failed to create a tap device with ip tuntap. '
                    'tunctl does not support creation of multi-queue '
                    'enabled devices, skipping fallback.')
                raise

            # Second option: tunctl
            processutils.execute('tunctl', '-b', '-t', dev)

        if mac_address:
            _set_device_macaddr_inner(dev, mac_address)
        _set_device_enabled_inner(dev)

历史参考

我之前的笔记确实也是:port 绑定给虚拟机,即 compute livbvirt attatch port 给 br-int 实际上是调用 ovs-vsctl add-port br-int tapxxx: 参考 www.jianshu.com/p/c1c684c5b...

相关推荐
唐叔在学习14 分钟前
200kb能作甚?mss表示我给你整个截图程序
后端·python
出师未捷的小白14 分钟前
[NestJS] 手摸手~工作队列模式的邮件模块解析以及grpc调用
前端·后端
用户83562907805127 分钟前
用Python自动化转换PowerPoint幻灯片为图片
后端·python
程序员爱钓鱼43 分钟前
Python编程实战 · 基础入门篇 | 推导式(列表推导式 / 字典推导式)
后端·python
无限进步_44 分钟前
【C语言】函数指针数组:从条件分支到转移表的优雅进化
c语言·开发语言·数据结构·后端·算法·visual studio
程序员爱钓鱼1 小时前
Python编程实战 · 基础入门篇 | 循环控制:break / continue / else
后端
canonical_entropy1 小时前
领域驱动设计(DDD)领域对象一定要讲究充血模型吗?
后端·领域驱动设计·graphql
9ilk1 小时前
【同步/异步 日志系统】 --- 前置技术
笔记·后端·其他·中间件
野犬寒鸦2 小时前
从零起步学习MySQL || 第九章:从数据页的角度看B+树及MySQL中数据的底层存储原理(结合常见面试题深度解析)
java·服务器·数据库·后端·mysql·oracle·1024程序员节
IT_陈寒2 小时前
SpringBoot 3.2 实战:这5个新特性让你的开发效率提升50%!
前端·人工智能·后端