openstack学习之neutron ml2初始化代码分析
这里没有 去详细考虑neutron server怎么初始化的,而是直接从加载插件的地方开始分析。首先我们看下下面这个文件。
Neutron/api/v2/router.py
class APIRouter(base_wsgi.Router):
@classmethod
def factory(cls, global_config, **local_config):
return cls(**local_config)
def __init__(self, **local_config):
#用来构造了URL和对应controller映射,根据不同的URL路由给不同的controller处理。
mapper = routes_mapper.Mapper()
#获取NeutornManage的core_plugin,这个定义在/etc/neutron/neutron.conf,比如我的是
#core_plugin = neutron.plugins.ml2.plugin.Ml2Plugin
plugin = manager.NeutronManager.get_plugin()
# 扫描特定路径下的extensions
ext_mgr = extensions.PluginAwareExtensionManager.get_instance()
上面给出了根据配置文件要加载哪些插件,下面正式加载插件。
neutron/manager.py
class NeutronManager(object):
"""Neutron's Manager class.
Neutron's Manager class is responsible for parsing a config file and
instantiating the correct plugin that concretely implements
neutron_plugin_base class.
The caller should make sure that NeutronManager is a singleton.
"""
_instance = None
def __init__(self, options=None, config_file=None):
# If no options have been provided, create an empty dict
if not options:
options = {}
# 验证是否配置了cor_plugin
msg = validate_pre_plugin_load()
if msg:
LOG.critical(msg)
raise Exception(msg)
# NOTE(jkoelker) Testing for the subclass with the __subclasshook__
# breaks tach monitoring. It has been removed
# intentionally to allow v2 plugins to be monitored
# for performance metrics.
plugin_provider = cfg.CONF.core_plugin
#ml2 namespace: neutron.core_plugins class: neutron.plugins.ml2.plugin.Ml2Plugin(benzhang)
LOG.info(_LI("Loading core plugin: %s"), plugin_provider)
# 加载核心插件
self.plugin = self._get_plugin_instance(CORE_PLUGINS_NAMESPACE,
plugin_provider)
正式加载插件并初始化。
neutron/manager.py
def _get_plugin_instance(self, namespace, plugin_provider):
plugin_class = self.load_class_for_provider(namespace, plugin_provider)
return plugin_class() #初始化ml2plugin
核心插件ML2的初始化
neutron/plugins/ml2/plugin.py/ML2Plugin
def __init__(self):
# First load drivers, then initialize DB, then initialize drivers
self.type_manager = managers.TypeManager()
self.extension_manager = managers.ExtensionManager()
self.mechanism_manager = managers.MechanismManager()
super(Ml2Plugin, self).__init__()
# ML2Plugin中的初始化
self.type_manager.initialize()
self.extension_manager.initialize()
self.mechanism_manager.initialize()
self._setup_dhcp()
self._start_rpc_notifiers()
self.add_agent_status_check(self.agent_health_check)
self._verify_service_plugins_requirements()
LOG.info(_LI("Modular L2 Plugin initialization complete"))
初始化Type driver
neutron/plugins/ml2/manager.py
class TypeManager(stevedore.named.NamedExtensionManager):
“”“Manage network segment types using drivers.”“”
def __init__(self):
# Mapping from type name to DriverManager
self.drivers = {}
LOG.info(_LI("Configured type driver names: %s"),
cfg.CONF.ml2.type_drivers)
super(TypeManager, self).__init__('neutron.ml2.type_drivers',
cfg.CONF.ml2.type_drivers,
invoke_on_load=True)
# 此处是根据/etc/neutron/plugins/ml2/ml2_conf.ini中配置的type_drivers,
# 到/usr/lib/python2.7/site-packages/neutron-10.0.1-py2.7.egg-info/ entry_points.txt
# 文件中的neutron.ml2.type_drivers字段读取driver初始化入口,也就是类代码的位置
LOG.info(_LI("Loaded type driver names: %s"), self.names())
# 注册 type driver
self._register_types()
# 校验并注册tenant_network_types
self._check_tenant_network_types(cfg.CONF.ml2.tenant_network_types)
# 校验external_network_type
self._check_external_network_type(cfg.CONF.ml2.external_network_type)
neutron/plugins/ml2/manager.py
def initialize(self):
for network_type, driver in six.iteritems(self.drivers):
LOG.info(_LI(“Initializing driver for type ‘%s’”), network_type)
#对配置每一种type进行初始化,例如:flat,vlan
driver.obj.initialize()
初始化 Mechanism
neutron/plugins/ml2/manager.py
class MechanismManager(stevedore.named.NamedExtensionManager):
“”“Manage networking mechanisms using drivers.”“”
def __init__(self):
# Registered mechanism drivers, keyed by name.
self.mech_drivers = {}
# Ordered list of mechanism drivers, defining
# the order in which the drivers are called.
self.ordered_mech_drivers = []
LOG.info(_LI("Configured mechanism driver names: %s"),
cfg.CONF.ml2.mechanism_drivers)
super(MechanismManager, self).__init__('neutron.ml2.mechanism_drivers',
cfg.CONF.ml2.mechanism_drivers,
invoke_on_load=True,
name_order=True)
# 此处是根据/etc/neutron/plugins/ml2/ml2_conf.ini中配置的mechanism_drivers,
# 到/usr/lib/python2.7/site-packages/neutron-10.0.1-py2.7.egg-info/ entry_points.txt
# 文件中的neutron.ml2.mechanism_drivers字段读取driver初始化入口,也就是类代码的位置
LOG.info(_LI("Loaded mechanism driver names: %s"), self.names())
self._register_mechanisms()
初始化 Extension
neutron/plugins/ml2/manager.py
class ExtensionManager(stevedore.named.NamedExtensionManager):
“”“Manage extension drivers using drivers.”“”
def __init__(self):
# Ordered list of extension drivers, defining
# the order in which the drivers are called.
self.ordered_ext_drivers = []
LOG.info(_LI("Configured extension driver names: %s"),
cfg.CONF.ml2.extension_drivers)
super(ExtensionManager, self).__init__('neutron.ml2.extension_drivers',
cfg.CONF.ml2.extension_drivers,
invoke_on_load=True,
name_order=True)
# 此处是根据/etc/neutron/plugins/ml2/ml2_conf.ini中配置的extension_drivers,
# 到/usr/lib/python2.7/site-packages/neutron-10.0.1-py2.7.egg-info/ entry_points.txt
# 文件中的neutron.ml2.extension_drivers字段读取driver初始化入口,也就是类代码的位置
LOG.info(_LI("Loaded extension driver names: %s"), self.names())
self._register_drivers()
待续~
openstack学习之neutron ml2初始化代码分析的更多相关文章
- 【DWM1000】 code 解密2一 工程初始化代码分析
instance_init 函数追下去,绝大多数的代码都在初始化如下结构体 typedef struct { INST_MODE mode; instance_init -ANCHOR //insta ...
- ISD9160学习笔记03_ISD9160音频解码代码分析
录音例程涉及了录音和播放两大块内容,这篇笔记就先来说说播放,暂且先击破解码这部分功能. 我的锤子便签中有上个月记下的一句话,“斯蒂芬·平克说,写作之难,在于把网状思考,用树状结构,体现在线性展开的语句 ...
- 【NopCommerce源码架构学习-二】单例模式实现代码分析
单例模式是是常用经典十几种设计模式中最简单的..NET中单例模式的实现也有很多种方式.下面我来介绍一下NopCommerce中单例模式实现. 我之前的文章就分析了一下nop中EngineContext ...
- ISD9160学习笔记04_ISD9160音频编码代码分析
前言 录音例程涉及了录音和播放两大块内容,上篇笔记说了播放,这篇就来说说录音这块,也就是音频编码这部分功能. 上篇笔记中的这段话太装逼了,我决定再复制下,嘿嘿. “我的锤子便签中有上个月记下的一句话, ...
- RT-thread组件初始化代码分析
RT-thread提供了组件化功能,具体实现是在components/init文件夹下components.c文件中实现的.应用组件化功能首先在rtconfig.h中添加宏定义#define RT_U ...
- Linux时间子系统之(十七):ARM generic timer驱动代码分析
专题文档汇总目录 Notes:ARM平台Clock/Timer架构:System counter.Timer以及两者之间关系:Per cpu timer通过CP15访问,System counter通 ...
- Linux kernel的中断子系统之(七):GIC代码分析
返回目录:<ARM-Linux中断系统>. 总结: 原文地址:<linux kernel的中断子系统之(七):GIC代码分析> 参考代码:http://elixir.free- ...
- Linux中断 - GIC代码分析
一.前言 GIC(Generic Interrupt Controller)是ARM公司提供的一个通用的中断控制器,其architecture specification目前有四个版本,V1-V4(V ...
- Linux时间子系统(十七) ARM generic timer驱动代码分析
一.前言 关注ARM平台上timer driver(clocksource chip driver和clockevent chip driver)的驱动工程师应该会注意到timer硬件的演化过程.在单 ...
随机推荐
- 0911作业-if while循环小练习
输入姑娘的年龄后,进行以下判断: 如果姑娘小于18岁,打印"不接受未成年" 如果姑娘大于18岁小于25岁,打印"心动表白" 如果姑娘大于25岁小于45岁,打印& ...
- 【Go 入门学习】第一篇关于 Go 的博客--Go 爬虫初体验
一.写在前面 其实早就该写这一篇博客了,为什么一直没有写呢?还不是因为忙不过来(实际上只是因为太懒了).不过好了,现在终于要开始写这一篇博客了.在看这篇博客之前,可能需要你对 Go 这门语言有些基本的 ...
- nyoj 92-图像有用区域 (BFS)
92-图像有用区域 内存限制:64MB 时间限制:3000ms 特判: No 通过数:4 提交数:12 难度:4 题目描述: “ACKing”同学以前做一个图像处理的项目时,遇到了一个问题,他需要摘取 ...
- nyoj 263-精 挑 细 选 (sort(P, P+m, cmp); bool cmp(node a, node b)...)
263-精 挑 细 选 内存限制:64MB 时间限制:3000ms 特判: No 通过数:14 提交数:26 难度:1 题目描述: 小王是公司的仓库管理员,一天,他接到了这样一个任务:从仓库中找出一根 ...
- 自动安装 linux 系统
实现自动安装 centos 6 和 centos 7 实现自动安装 Linux 系统需要在虚拟机上安装三个服务:apache .tftp.dhcp 三个服务放在一台虚拟机上即可 一.DHCP 服务器的 ...
- Itellij idea2019.2 激活码,有效期2020.5
Itellij idea2019.2 激活码,有效期2020.5 MNQ043JMTU-eyJsaWNlbnNlSWQiOiJNTlEwNDNKTVRVIiwibGljZW5zZWVOYW1lIjoi ...
- 作业要求20191010-8 alpha week 1/2 Scrum立会报告+燃尽图 06
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2019fall/homework/8751 一.小组情况 队名:扛把子 组长:迟俊文 组员:宋晓丽 梁梦瑶 韩 ...
- Git使用和介绍-基础指令
转载请标明出处:http://blog.csdn.net/shensky711/article/details/52210625 本文出自: [HansChen的博客] 查看已有配置 取消已有的配置 ...
- sql注入问题回顾
(以下语法均为在python中使用mysql语句,部分代码省略,使用python中的pymsql模块获取游标对象即可直接执行sql语句) sql注入:在传入参数的时候做出改变,使得插入数据这条sql语 ...
- 分布式存储Minio集群环境搭建
MinIO 分布式集群搭建 分布式 Minio 可以让你将多块硬盘(甚至在不同的机器上)组成一个对象存储服务.由于硬盘分布在不同的节点上,分布式 Minio 避免了单点故障. Minio 分布式模式可 ...