openstack学习之neutron ml2初始化代码分析
2017-03-27 16:33
453 查看
这里没有 去详细考虑neutron server怎么初始化的,而是直接从加载插件的地方开始分析。首先我们看下下面这个文件。
Neutron/api/v2/router.py
上面给出了根据配置文件要加载哪些插件,下面正式加载插件。
neutron/manager.py
正式加载插件并初始化。
neutron/manager.py
核心插件ML2的初始化
neutron/plugins/ml2/plugin.py/ML2Plugin
初始化Type driver
neutron/plugins/ml2/manager.py
class TypeManager(stevedore.named.NamedExtensionManager):
“”“Manage network segment types using drivers.”“”
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.”“”
初始化 Extension
neutron/plugins/ml2/manager.py
class ExtensionManager(stevedore.named.NamedExtensionManager):
“”“Manage extension drivers using drivers.”“”
待续~
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代码分析---(1)neutron初始化流程
- openstack学习之neutron_linuxbridge_agent分析
- BT源代码学习心得(六):跟踪服务器(Tracker)的代码分析(初始化) -- 转贴自 wolfenstein (NeverSayNever)
- openstack学习之neutron_ml2_plugin
- BT源代码学习心得(六):跟踪服务器(Tracker)的代码分析(初始化)
- Coursera deeplearning.ai 深度学习笔记2-1-Practical aspects of deep learning-神经网络实际问题分析(初始化&正则化&训练效率)与代码实现
- OpenStack中网络模块(Neutron)的代码分析
- BT源代码学习心得(六):跟踪服务器(Tracker)的代码分析(初始化) 转自CSDN:gushenghua的专栏
- openstack学习之neutron_运行分析
- USB学习之一 代码分析和学习心得之初始化流程以及读写流程
- BT源代码学习心得(六):跟踪服务器(Tracker)的代码分析(初始化)
- Openstack学习笔记之——Neutron-server服务加载与启动源码分析(三)
- BT源代码学习心得(六):跟踪服务器(Tracker)的代码分析(初始化) -- 转贴自 wolfenstein (NeverSayNever)
- BT源代码学习心得(八):跟踪服务器(Tracker)的代码分析(用户请求的实际处理) - 转贴自 wolfenstein (NeverSayNever)
- MBR分析(1): 代码获取与初始化
- VxWorks系统PCI设备(网卡)初始化代码分析
- BT源代码学习心得(七):跟踪服务器(Tracker)的代码分析(HTTP协议处理对象) -- 转贴自 wolfenstein (NeverSayNever)
- 【学习逆向工程,分析机器代码】(一)(C语言篇)
- BootLoader中PLL的初始化代码分析