这里没有 去详细考虑neutron server怎么初始化的,而是直接从加载插件的地方开始分析。首先我们看下下面这个文件。

Neutron/api/v2/router.py

  1. class APIRouter(base_wsgi.Router):
  2. @classmethod
  3. def factory(cls, global_config, **local_config):
  4. return cls(**local_config)
  5. def __init__(self, **local_config):
  6. #用来构造了URL和对应controller映射,根据不同的URL路由给不同的controller处理。
  7. mapper = routes_mapper.Mapper()
  8. #获取NeutornManage的core_plugin,这个定义在/etc/neutron/neutron.conf,比如我的是
  9. #core_plugin = neutron.plugins.ml2.plugin.Ml2Plugin
  10. plugin = manager.NeutronManager.get_plugin()
  11. # 扫描特定路径下的extensions
  12. ext_mgr = extensions.PluginAwareExtensionManager.get_instance()

上面给出了根据配置文件要加载哪些插件,下面正式加载插件。

neutron/manager.py

  1. class NeutronManager(object):
  2. """Neutron's Manager class.
  3. Neutron's Manager class is responsible for parsing a config file and
  4. instantiating the correct plugin that concretely implements
  5. neutron_plugin_base class.
  6. The caller should make sure that NeutronManager is a singleton.
  7. """
  8. _instance = None
  9. def __init__(self, options=None, config_file=None):
  10. # If no options have been provided, create an empty dict
  11. if not options:
  12. options = {}
  13. # 验证是否配置了cor_plugin
  14. msg = validate_pre_plugin_load()
  15. if msg:
  16. LOG.critical(msg)
  17. raise Exception(msg)
  18. # NOTE(jkoelker) Testing for the subclass with the __subclasshook__
  19. # breaks tach monitoring. It has been removed
  20. # intentionally to allow v2 plugins to be monitored
  21. # for performance metrics.
  22. plugin_provider = cfg.CONF.core_plugin
  23. #ml2 namespace: neutron.core_plugins class: neutron.plugins.ml2.plugin.Ml2Plugin(benzhang)
  24. LOG.info(_LI("Loading core plugin: %s"), plugin_provider)
  25. # 加载核心插件
  26. self.plugin = self._get_plugin_instance(CORE_PLUGINS_NAMESPACE,
  27. plugin_provider)

正式加载插件并初始化。

neutron/manager.py

  1. def _get_plugin_instance(self, namespace, plugin_provider):
  2. plugin_class = self.load_class_for_provider(namespace, plugin_provider)
  3. return plugin_class() #初始化ml2plugin

核心插件ML2的初始化

neutron/plugins/ml2/plugin.py/ML2Plugin

  1. def __init__(self):
  2. # First load drivers, then initialize DB, then initialize drivers
  3. self.type_manager = managers.TypeManager()
  4. self.extension_manager = managers.ExtensionManager()
  5. self.mechanism_manager = managers.MechanismManager()
  6. super(Ml2Plugin, self).__init__()
  7. # ML2Plugin中的初始化
  8. self.type_manager.initialize()
  9. self.extension_manager.initialize()
  10. self.mechanism_manager.initialize()
  11. self._setup_dhcp()
  12. self._start_rpc_notifiers()
  13. self.add_agent_status_check(self.agent_health_check)
  14. self._verify_service_plugins_requirements()
  15. 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.”“”

  1. def __init__(self):
  2. # Mapping from type name to DriverManager
  3. self.drivers = {}
  4. LOG.info(_LI("Configured type driver names: %s"),
  5. cfg.CONF.ml2.type_drivers)
  6. super(TypeManager, self).__init__('neutron.ml2.type_drivers',
  7. cfg.CONF.ml2.type_drivers,
  8. invoke_on_load=True)
  9. # 此处是根据/etc/neutron/plugins/ml2/ml2_conf.ini中配置的type_drivers,
  10. # 到/usr/lib/python2.7/site-packages/neutron-10.0.1-py2.7.egg-info/ entry_points.txt
  11. # 文件中的neutron.ml2.type_drivers字段读取driver初始化入口,也就是类代码的位置
  12. LOG.info(_LI("Loaded type driver names: %s"), self.names())
  13. # 注册 type driver
  14. self._register_types()
  15. # 校验并注册tenant_network_types
  16. self._check_tenant_network_types(cfg.CONF.ml2.tenant_network_types)
  17. # 校验external_network_type
  18. 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.”“”

  1. def __init__(self):
  2. # Registered mechanism drivers, keyed by name.
  3. self.mech_drivers = {}
  4. # Ordered list of mechanism drivers, defining
  5. # the order in which the drivers are called.
  6. self.ordered_mech_drivers = []
  7. LOG.info(_LI("Configured mechanism driver names: %s"),
  8. cfg.CONF.ml2.mechanism_drivers)
  9. super(MechanismManager, self).__init__('neutron.ml2.mechanism_drivers',
  10. cfg.CONF.ml2.mechanism_drivers,
  11. invoke_on_load=True,
  12. name_order=True)
  13. # 此处是根据/etc/neutron/plugins/ml2/ml2_conf.ini中配置的mechanism_drivers,
  14. # 到/usr/lib/python2.7/site-packages/neutron-10.0.1-py2.7.egg-info/ entry_points.txt
  15. # 文件中的neutron.ml2.mechanism_drivers字段读取driver初始化入口,也就是类代码的位置
  16. LOG.info(_LI("Loaded mechanism driver names: %s"), self.names())
  17. self._register_mechanisms()

初始化 Extension

neutron/plugins/ml2/manager.py

class ExtensionManager(stevedore.named.NamedExtensionManager):

“”“Manage extension drivers using drivers.”“”

  1. def __init__(self):
  2. # Ordered list of extension drivers, defining
  3. # the order in which the drivers are called.
  4. self.ordered_ext_drivers = []
  5. LOG.info(_LI("Configured extension driver names: %s"),
  6. cfg.CONF.ml2.extension_drivers)
  7. super(ExtensionManager, self).__init__('neutron.ml2.extension_drivers',
  8. cfg.CONF.ml2.extension_drivers,
  9. invoke_on_load=True,
  10. name_order=True)
  11. # 此处是根据/etc/neutron/plugins/ml2/ml2_conf.ini中配置的extension_drivers,
  12. # 到/usr/lib/python2.7/site-packages/neutron-10.0.1-py2.7.egg-info/ entry_points.txt
  13. # 文件中的neutron.ml2.extension_drivers字段读取driver初始化入口,也就是类代码的位置
  14. LOG.info(_LI("Loaded extension driver names: %s"), self.names())
  15. self._register_drivers()

待续~

openstack学习之neutron ml2初始化代码分析的更多相关文章

  1. 【DWM1000】 code 解密2一 工程初始化代码分析

    instance_init 函数追下去,绝大多数的代码都在初始化如下结构体 typedef struct { INST_MODE mode; instance_init -ANCHOR //insta ...

  2. ISD9160学习笔记03_ISD9160音频解码代码分析

    录音例程涉及了录音和播放两大块内容,这篇笔记就先来说说播放,暂且先击破解码这部分功能. 我的锤子便签中有上个月记下的一句话,“斯蒂芬·平克说,写作之难,在于把网状思考,用树状结构,体现在线性展开的语句 ...

  3. 【NopCommerce源码架构学习-二】单例模式实现代码分析

    单例模式是是常用经典十几种设计模式中最简单的..NET中单例模式的实现也有很多种方式.下面我来介绍一下NopCommerce中单例模式实现. 我之前的文章就分析了一下nop中EngineContext ...

  4. ISD9160学习笔记04_ISD9160音频编码代码分析

    前言 录音例程涉及了录音和播放两大块内容,上篇笔记说了播放,这篇就来说说录音这块,也就是音频编码这部分功能. 上篇笔记中的这段话太装逼了,我决定再复制下,嘿嘿. “我的锤子便签中有上个月记下的一句话, ...

  5. RT-thread组件初始化代码分析

    RT-thread提供了组件化功能,具体实现是在components/init文件夹下components.c文件中实现的.应用组件化功能首先在rtconfig.h中添加宏定义#define RT_U ...

  6. Linux时间子系统之(十七):ARM generic timer驱动代码分析

    专题文档汇总目录 Notes:ARM平台Clock/Timer架构:System counter.Timer以及两者之间关系:Per cpu timer通过CP15访问,System counter通 ...

  7. Linux kernel的中断子系统之(七):GIC代码分析

    返回目录:<ARM-Linux中断系统>. 总结: 原文地址:<linux kernel的中断子系统之(七):GIC代码分析> 参考代码:http://elixir.free- ...

  8. Linux中断 - GIC代码分析

    一.前言 GIC(Generic Interrupt Controller)是ARM公司提供的一个通用的中断控制器,其architecture specification目前有四个版本,V1-V4(V ...

  9. Linux时间子系统(十七) ARM generic timer驱动代码分析

    一.前言 关注ARM平台上timer driver(clocksource chip driver和clockevent chip driver)的驱动工程师应该会注意到timer硬件的演化过程.在单 ...

随机推荐

  1. Scrapy进阶知识点总结(三)——Items与Item Loaders

    一.Items 抓取的主要目标是从非结构化源(通常是网页)中提取结构化数据.Scrapy蜘蛛可以像Python一样返回提取的数据.虽然方便和熟悉,但Python缺乏结构:很容易在字段名称中输入拼写错误 ...

  2. css3mask淡出文字

    css3mask淡出文字<pre>.p0_11wrap { width: 0.299rem; height: 7.68rem; overflow: hidden; background: ...

  3. SSM整合相关试题

    1.下列关于Spring自动装配的说法中,错误的是() A 在Spring配置文件中,可以通过<bean>元素的autowire属性指定自动装配方式 B autowire属性值可以设置为n ...

  4. Windows对python文件加密

    最近项目需要对部分python文件加密,调研了部分方法都觉得不可行,最后采用了将python转换成so文件.pyd文件的方法.so文件,为liunx下的动态链接库文件,在windows下为dll文件, ...

  5. matlab中的eval函数使用

    matlab中的eval函数使用 在matlab的命令行窗口中输入help eval命令回车就可以看到eval函数的官方解释,大概的意思就是执行matlab中的表达式,计算expression表示的代 ...

  6. 【科创人·独家】MegaEase左耳朵耗子陈皓复盘创业:第一年盈利被当骗子,线下广阔天地大有可为

    [科创人·独家]MegaEase左耳朵耗子陈皓复盘创业:第一年盈利被当骗子,线下广阔天地大有可为 原创: babayage CTO科创圈  与上百位科技创业者共同关注科创人的成长心路. 文末有彩蛋:& ...

  7. css字体图标的制作

    我介绍的这个办法是直接在 "阿里巴巴图标库"中制作的,方便快捷 1. 首先到 "阿里巴巴图标库"中找到你想要的图片,然后选择加入购物车 接着我们点击右上角的购物 ...

  8. java实现两个json的深度对比

    两个json的深度对比 在网上找了好多资料都没有找到想要的,还是自己写个吧! 上代码!!! 1.pom.xml中加入 <dependency> <groupId>com.ali ...

  9. JenKins结合cppcheck及cpplint进行代码风格及静态代码检测

    JenKins结合cppcheck及cpplint 最近公司需要在Jenkins上安装cppcheck及cpplint进行代码风格及静态代码检测,这里记录下过程. 前提条件 安装了Jenkins 步骤 ...

  10. Python 常用模块系列学习(3)--configparser module

    configpaser 模块----用于生成和修改常见配置文档 1. config 对象的创建: import configparser #导入模块 config = configparser.Con ...