标签:openstack neutron 源码 server
本文是在学习Openstack的过程中整理和总结,由于时间和个人能力有限,错误之处在所难免,欢迎指正!
在Neutron-server服务加载与启动源码分析(二)中搞定模块功能的扩展和加载,我们就回到Neutron-server服务加载与启动源码分析(一)中的_run_wsgi函数
<span style="font-size:14px;">def _run_wsgi(app_name): app = config.load_paste_app(app_name) ifnot app: LOG.error(_('No known API applications configured.')) return server = wsgi.Server("Neutron") server.start(app, cfg.CONF.bind_port, cfg.CONF.bind_host, workers=cfg.CONF.api_workers) # Dump all option values here after all options are parsed cfg.CONF.log_opt_values(LOG, std_logging.DEBUG) LOG.info(_("Neutron service started, listening on%(host)s:%(port)s"), {'host': cfg.CONF.bind_host, 'port': cfg.CONF.bind_port}) return server</span>
app =config.load_paste_app(app_name)在这里就完成模块功能的扩展和加载,接下来看
<span style="font-size:14px;">server = wsgi.Server("Neutron") server.start(app, cfg.CONF.bind_port, cfg.CONF.bind_host, workers=cfg.CONF.api_workers)</span>
创建一个neutron的服务端,然后启动这个server
这边配置文件中默认的api_workers为0
<span style="font-size:14px;">def start(self, application, port, host='0.0.0.0', workers=0): """Run a WSGI server with the givenapplication.""" self._host = host self._port = port backlog = CONF.backlog #获取socket信息 self._socket = self._get_socket(self._host, self._port, backlog=backlog) self._launch(application, workers)</span>
<span style="font-size:14px;">def _launch(self, application, workers=0): service = WorkerService(self, application) if workers <1: # workers小于1直接运行在当前的进程 self._server = service service.start() systemd.notify_once() else: # API服务运行一定数量的子进程 # 等待间隔时间默认0.01s self._server = common_service.ProcessLauncher(wait_interval=1.0) self._server.launch_service(service, workers=workers)</span>
执行完_run_wsgi函数,就完成service.start()的执行,也就完成neutron_api= service.serve_wsgi(service.NeutronApiService)的工作。
<span style="font-size:14px;">def main(): …… try: pool = eventlet.GreenPool() neutron_api = service.serve_wsgi(service.NeutronApiService) api_thread = pool.spawn(neutron_api.wait) try: neutron_rpc = service.serve_rpc()</span>
我们启动了一个wsgi的服务,并且把资源加载和扩展等等准备工作都做好了,“万事具备只欠东风”,现在就从线程池中spawn一个线程来监听neutron api命令,这里再啰嗦一句neutron api命令到来之后,最后是路由到neutron.api.v2.base中的Controller中进行处理。
main函数最后就是执行neutron_rpc =service.serve_rpc())是通过plugin实现的,开始一个或者多个Rpcworker,并监听请求,监听topics中消息队列。我的理解是这个是用来监听neutron内部组件之间的通信。
至此Openstack neutron服务启动过程中的资源加载和扩展的源码简单解析完成了。
Openstack学习笔记之——Neutron-server服务加载与启动源码分析(三)
标签:openstack neutron 源码 server
原文地址:http://blog.csdn.net/canxinghen/article/details/40978887