neutron学习小结

2024-06-07 02:44
文章标签 学习 小结 neutron

本文主要是介绍neutron学习小结,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

概述

基于yoga版本学习neutron,通过源码、官方文档、部署环境进行学习

neutron-dhcp-agent

neutron.agent.dhcp_agent.main

创建server,调oslo_service launch server,最后实际调了server的start方法

neutron.service.Service.start

Service创建时会传入一个manager路径,Service.start实际会调manager的一些方法启动业务,主要调了manager的init_host和after_start方法,after_start方法默认为空,主要是init_host

neutron没有prepare_service,而是把配置项注册汇聚到一个函数,可手动尝试

start方法周期运行service的report_state方法,这个方法默认为空,应该没啥用

neutron.agent.dhcp.agent.DhcpAgentWithStateReport.__init__

neutron.agent.dhcp.agent.DhcpAgent._populate_networks_cache

DhcpAgent初始化时从neutron 拿数据放入cache

然后调Dnsmasq的existing_dhcp_networks,实际获取/var/lib/neutron/dhcp底下的形如uuid的文件名作为已存在网络id,然后用id创dhcp对象,塞到cache

neutron.agent.dhcp.agent.DhcpAgentWithStateReport.init_host

实际调用了sync_state方法

neutron.agent.dhcp.agent.DhcpAgentWithStateReport.sync_state

从cache获取已存在的网络id,cache的东西初始从/var/lib/neutron/dhcp读取目录下所有形如uuid的文件名

DhcpAgent.plugin_rpc.get_active_networks_info

plugin_rpc传入target和transport,封装了一个oslo_messaging的RPCClient,topic从neutron_lib的topics常量文件读取,是q-plugin,transport用默认的rabbit,最后通过transport发消息到target

看了下rpc可能是core_plugins启的,不知道谁调core_plugins,后面再看

neutron-l3-agent

概述

主要在after_start,init_host没啥东西

流程

neutron.cmd.eventlet.agents.l3:main ->

neutron.agent.l3_agent.main ->

neutron.agent.l3.agent.L3NATAgentWithStateReport.after_start

neutron.agent.l3.agent.L3NATAgentWithStateReport._process_routers_loop

neutron.agent.l3.agent.L3NATAgentWithStateReport._report_state

neutron.agent.l3.agent.L3NATAgentWithStateReport.pd.after_start

neutron-linuxbridge-agent

流程

neutron.cmd.eventlet.plugins.linuxbridge_neutron_agent:main ->

neutron.plugins.ml2.drivers.linuxbridge.agent.linuxbridge_neutron_agent.main ->

neutron.plugins.ml2.drivers.agent._common_agent.CommonAgentLoop.start ->

neutron.plugins.ml2.drivers.linuxbridge.agent.linuxbridge_neutron_agent.main

physical_interface_mappings和bridge_mappings从配置文件读取,冒号分隔,可能是配的,返回一个mapping

neutron.plugins.ml2.drivers.agent._common_agent.CommonAgentLoop.start

report_interval默认是30

self.setup_rpc

创建队列监听,约10来个队列,均是q-plugin-agent开头的一些队列

self.daemon_loop

周期扫描主机所有tap口,默认周期30秒,提前扫完了则sleep

self.scan_devices

self.process_network_devices

扫描完新设备后,和上一周期设备信息对比,如果设备信息无变更或不需要刷新防火墙,则不处理等待下一周期,否则则集中处理:刷防火墙、处理安全组、更新网络信息,处理端口、清理arp,调用rpc接口处理设备等操作

self.ext_manager.names

names应该是配置文件对应的extensions的名称,可以是qos,local_ip,qos_linux等

太难了

self.mgr.get_agent_configurations

两个mapping从配置读取

vxlan_mode可以是none,ucast或mcast

self.mgr.__init__

enable_vxlan默认为True

self.mgr.check_vxlan_support

self.vxlan_ucast_supported

l2_population默认False,实际可为true或false。如果false则不支持,如果true则找一个空闲vxlan号,创vxlan,然后将创的vxlan加到fdb表,然后删vxlan

neutron.agent.linux.ip_lib.device_exists

调接口查interface是否存在,最后好像socket通信,调用栈太深不看了,外面给device_exists传各种vxlan-xx,检查interface是否存在,返回True或False

neutron.privileged.agent.linux.interface_exists ->

neutron.privileged.agent.linux.get_link_id

namespace默认None,返回pyroute2.IPRoute()

最后是socket通信,不看了

self.ensure_vxlan

确认vxlan不存在,不存在则创建,创完了disable这个vxlan的ipv6,通过sysctl修改变量来disable,然后up此vxlan

cfg.CONF.VXLAN.tos deprecated,默认应该是None

dscp_inherit默认False

1 ip.add_vxlan

self.ip是:

self.local_int:

最后返回第一个device的网卡名赋值给self.local_int

self.local_ip配的是overlay network endpoint

arp_responder默认false

更新fdb表

支持ucast的话,把创的vxlan加到fdb表,然后删除vxlan

neutron-linuxbridge-cleanup

不以服务形式工作 ,运行命令会清理无用bridge和bridge相关的vxlan,会便利bridge下的tap口,清理无tap口的bridge,tap口在bridge/brif目录下,遍历即可

neutron-metadata-agent

agent worker数期望是cpu数的一半,从配置读取,没有默认配置,读取不到则调neutron_lib获取,调multiprocessing.cpu_count()获取

socket mode默认deduce,可选项,deduce、user、group、all

metadata_proxy_socket默认是/var/lib/neutron/metadata_proxy

最后调用eventlet.wsgi.server启动服务,服务封装在MetadataProxyHandler,handerl作用类似一个转发器,自己做些操作,然后转发出去,代码好像没有存储改动等操作,感觉只是加header,cert,发给nova,需要确认监听哪个端口,是否从socket对象获取端口

neutron-server

加载配置文件,默认是neutron.conf, plugins/ml2/ml2_conf.ini     

最后加载完配置文件,没有太多操作,调用oslo_service,加载api_paste.ini加载server

逻辑封装

initialize_all注册接口对应的controller

route时,controller会找在initialize_all中注册的controller

startup.initialize_all(路由规则加载)

1 manager.init创建一个neutron.manager.NeutronManager实例,如果是首次运行,再创建_PluginDirectory实例。neutronmanager实例和_PluginDirectory实例应该都是单例模式,首次运行会加载,加载NeutronManager时会加载_PluginDirectory。

2 extensions.PluginAwareExtensionManager.get_instance是静态方法,创建一个自身实例并返回

创建实例时,创建一个全局的_PluginDirectory,其plugins属性包含extensions,默认为空

获取_PluginDirectory的plugins的路径,plugin空时路径只有一个目录的path

创PluginAwareExtensionManager实例时,将_PluginDirectory的plugins的路径和plugins作为初始化参数传入,初始化会加载plugin路径(extension目录,无子文件,因为是初始)下所有extension,每个extension是neutron/extensions下一个脚本,alias是neutron_lib仓库里同名脚本里对应的alias字段,加载脚本里对应的类,然后PluginAwareExtensionManager实例以map[alias] = extensions的形式保存extensions

3 NeutronManager.__init__

判断配置的core_plugin是否为空,如果空则异常,默认是ml2

加载core_plugin,将plugin加载到_PluginDirectory的plugin和NeutronManager的_loaded_plugin

判断core_plugin是否有支持的service类型,如果有则将支持的service对应的plugin也设为core_plugin,加到directory和neturonmanager的plugin

从配置获取服务plugin名称,如果neutron支持local存储则再获取默认service plugin名称,再看这些默认service plugin是否有必须plugin,如果有则将这些service plugin的必须plugin也加载

创建PluginAwareExtensionManager,将neutron.extensions下的plugin都加到PluginAwareExtensionManager的extensions字典中,键是extension的alias

neutron-api(接口)

net-create

走到neutron.pecan_wsgi.controllers.resource.CollectionsController处理:根据initialize_all加载的plugin,从plugin获取对应的方法,创network会调用ml2的create_network方法

request.context['resources']的生成

ML2Plugin.create_networks

_before_create_network

创建安全组

_create_network_db

在db创:net、net对应的rbac、net对应的segment,

_after_create_network

neutron hooks

pecan

有很多hook,request里一些参数会在各hook里赋值

body_validation

python库网络操作

ip link

ip相关命令用pyroute2.IPRoute().link等实现

添加vxlan:ip link add vxlan-xxx type vxlan id xxx dstport 5678

bridge

bridge show

bridge fdb show dev vxlan-666 #查看某个vxlan fdb转发表

brctl

Linux下的虚拟Bridge实现 - zmkeil - 博客园 (cnblogs.com)

Linux Bridge 基本原理-CSDN博客

linux网桥bridge详解_linux网桥、-CSDN博客

Linux 虚拟网络设备详解之 Bridge 网桥 - bakari - 博客园 (cnblogs.com)

ip -> arp(ip地址和mac地址) -> fdb(物理地址和端口) -> bridge ?

brctl show

brctl addbr testbr0

brctl addif testbr0 eth0

brctl addif testbr0 eth1

ifconfig testbr0 up

ifconfig testbr0 ip_addr netmask mask_addr/ ip addr add ip_addr/mask_addr dev testbr0

vlan和vxlan

浅谈VLAN和VXLAN-CSDN博客

VLAN与VXLAN网络原理与实践 - 知乎 (zhihu.com)、

其他操作

/sys/class/et存放网络网卡和接口相关消息

好用的方法

socket.gethostname

multiprocessing.cpu_count()

这篇关于neutron学习小结的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1037961

相关文章

C#中lock关键字的使用小结

《C#中lock关键字的使用小结》在C#中,lock关键字用于确保当一个线程位于给定实例的代码块中时,其他线程无法访问同一实例的该代码块,下面就来介绍一下lock关键字的使用... 目录使用方式工作原理注意事项示例代码为什么不能lock值类型在C#中,lock关键字用于确保当一个线程位于给定实例的代码块中时

flask库中sessions.py的使用小结

《flask库中sessions.py的使用小结》在Flask中Session是一种用于在不同请求之间存储用户数据的机制,Session默认是基于客户端Cookie的,但数据会经过加密签名,防止篡改,... 目录1. Flask Session 的基本使用(1) 启用 Session(2) 存储和读取 Se

Python获取浏览器Cookies的四种方式小结

《Python获取浏览器Cookies的四种方式小结》在进行Web应用程序测试和开发时,获取浏览器Cookies是一项重要任务,本文我们介绍四种用Python获取浏览器Cookies的方式,具有一定的... 目录什么是 Cookie?1.使用Selenium库获取浏览器Cookies2.使用浏览器开发者工具

Kotlin Map映射转换问题小结

《KotlinMap映射转换问题小结》文章介绍了Kotlin集合转换的多种方法,包括map(一对一转换)、mapIndexed(带索引)、mapNotNull(过滤null)、mapKeys/map... 目录Kotlin 集合转换:map、mapIndexed、mapNotNull、mapKeys、map

Redis中Stream详解及应用小结

《Redis中Stream详解及应用小结》RedisStreams是Redis5.0引入的新功能,提供了一种类似于传统消息队列的机制,但具有更高的灵活性和可扩展性,本文给大家介绍Redis中Strea... 目录1. Redis Stream 概述2. Redis Stream 的基本操作2.1. XADD

SpringSecurity整合redission序列化问题小结(最新整理)

《SpringSecurity整合redission序列化问题小结(最新整理)》文章详解SpringSecurity整合Redisson时的序列化问题,指出需排除官方Jackson依赖,通过自定义反序... 目录1. 前言2. Redission配置2.1 RedissonProperties2.2 Red

C++中NULL与nullptr的区别小结

《C++中NULL与nullptr的区别小结》本文介绍了C++编程中NULL与nullptr的区别,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编... 目录C++98空值——NULLC++11空值——nullptr区别对比示例 C++98空值——NUL

C++ Log4cpp跨平台日志库的使用小结

《C++Log4cpp跨平台日志库的使用小结》Log4cpp是c++类库,本文详细介绍了C++日志库log4cpp的使用方法,及设置日志输出格式和优先级,具有一定的参考价值,感兴趣的可以了解一下... 目录一、介绍1. log4cpp的日志方式2.设置日志输出的格式3. 设置日志的输出优先级二、Window

Python中反转字符串的常见方法小结

《Python中反转字符串的常见方法小结》在Python中,字符串对象没有内置的反转方法,然而,在实际开发中,我们经常会遇到需要反转字符串的场景,比如处理回文字符串、文本加密等,因此,掌握如何在Pyt... 目录python中反转字符串的方法技术背景实现步骤1. 使用切片2. 使用 reversed() 函

C#中Guid类使用小结

《C#中Guid类使用小结》本文主要介绍了C#中Guid类用于生成和操作128位的唯一标识符,用于数据库主键及分布式系统,支持通过NewGuid、Parse等方法生成,感兴趣的可以了解一下... 目录前言一、什么是 Guid二、生成 Guid1. 使用 Guid.NewGuid() 方法2. 从字符串创建