- 整体结构
- bin
- doc
- etc
- init.d/
- neutron/
- api-paste.ini
- dhcp_agent.ini
- fwaas_driver.ini
- l3_agent.ini
- lbaas_agent.ini
- metadata_agent.ini
- metering_agent.ini
- vpn_agent.ini
- neutron.conf
- policy.json
- rootwrap.conf
- services.conf
- neutron
- agent
- common/
- linux/
- metadata/
- dhcp_agent.py
- firewall.py
- l2population_rpc.py
- l3_agent.py
- l3_ha_agent.py
- netns_cleanup_util.py
- ovs_cleanup_util.py
- rpc.py
- securitygroups_rpc.py
- api
- rpc
- v2
- views
- api_common.py
- extensions.py
- versions.py
- cmd
- common
- config.py
- constants.py
- exceptions.py
- ipv6_utils.py
- log.py
- rpc.py
- test_lib.py
- topics.py
- utils.py
- db
- agents_db.py
- agentschedulers_db.py
- api.py
- common_db_mixin.py
- db_base_plugin_v2.py
- migration
- model_base.py
- models_v2.py
- securitygroups_rpc_base.py
- sqlalchemyutils.py
- 扩展资源和操作类
- allowedaddresspairs_db.py
- dvr_mac_db.py
- external_net_db.py
- extradhcpopt_db.py
- extraroute_db.py
- firewall
- l3_agentschedulers_db.py
- l3_attrs_db.py
- l3_db.py
- l3_dvr_db.py
- l3_gwmode_db.py
- l3_hamode_db.py
- l3_hascheduler_db.py
- loadbalancer
- metering
- portbindings_base.py
- portbindings_db.py
- portsecurity_db.py
- quota_db.py
- routedserviceinsertion_db.py
- routerservicetype_db.py
- securitygroups_db.py
- servicetype_db.py
- vpn
- debug
- commands.py
- debug_agent.py
- shell.py
- extensions
- agent.py
- allowedaddresspairs.py
- dhcpagentscheduler.py
- dvr.py
- external_net.py
- extraroute.py
- extra_dhcp_opt.py
- firewall.py
- flavor.py
- l3.py
- l3agentscheduler.py
- l3_ext_gw_mode.py
- lbaas_agentscheduler.py
- loadbalancer.py
- metering.py
- multiprovidernet.py
- portbindings.py
- portsecurity.py
- providernet.py
- quotasv2.py
- routedserviceinsertion.py
- routerservicetype.py
- securitygroup.py
- servicetype.py
- vpnaas.py
- hacking
- checks.py
- locale
- notifiers
- nova.py
- openstack
- common
- cache
- context.py
- eventlet_backdoor.py
- fileutils.py
- fixture
- local.py
- lockutils.py
- log.py
- loopingcall.py
- middleware
- periodic_task.py
- policy.py
- processutils.py
- service.py
- systemd.py
- threadgroup.py
- uuidutils.py
- versionutils.py
- _i18n.py
- plugins
- bigswitch
- agent
- common
- ibm
- agent
- common
- sdnve_api.py
- sdnve_api_fake.py
- sdnve_neutron_plugin.py
- ml2
- common
- config.py
- db.py
- drivers
- driver_api.py
- driver_context.py
- managers.py
- models.py
- plugin.py
- rpc.py
- ofagent
- agent
- common
- openvswitch
- agent
- common
- ovs_models_v2.py
- scheduler
- dhcp_agent_scheduler.py
- l3_agent_scheduler.py
- server
- services
- firewall
- agents
- drivers
- fwaas_plugin.py
- l3_apic.py
- l3_router_plugin.py
- loadbalancer
- agent
- agent_scheduler.py
- constants.py
- drivers
- plugin.py
- metering
- agents
- drivers
- metering_plugin.py
- provider_configuration.py
- service_base.py
- tests
- auth.py
- context.py
- hooks.py
- i18n.py
- manager.py
- neutron_plugin_base_v2.py
- policy.py
- quota.py
- service.py
- version.py
- wsgi.py
- rally-jobs
- extra
- plugins
- __init__.py
- neutron-neutron.yaml
- tools
- check_bash.sh
- check_i18n.py
- check_i18n_test_case.txt
- clean.sh
- i18n_cfg.py
- install_venv.py
- install_venv_common.py
- pretty_tox.sh
- with_venv.sh
- 理解代码
- REST API 专题
- RPC 专题
- agent RPC
- plugin RPC
- neutron-server RPC
- Plugin 专题
- Extension 专题
- Agent 专题
server
实现neutron-server的主进程。
init.py文件中包括一个main()函数,是WSGI服务器开始的模块,并且通过调用serve_wsgi来创建一个NeutronApiService的实例。然后通过eventlet的greenpool来运行WSGI的应用程序,响应来自客户端的请求。
主要过程为:
eventlet.monkey_patch()
绿化各个模块为支持协程(通过打补丁的方式让本地导入的库都支持协程)。
config.parse(sys.argv[1:])
if not cfg.CONF.config_file:
sys.exit(_("ERROR: Unable to find configuration file via the default"
" search paths (~/.neutron/, ~/, /etc/neutron/, /etc/) and"
" the '--config-file' option!"))
通过解析命令行传入的参数,获取配置文件所在。
pool = eventlet.GreenPool()
创建基于协程的线程池。
neutron_api = service.serve_wsgi(service.NeutronApiService)
api_thread = pool.spawn(neutron_api.wait)
serve_wsgi方法创建NeutronApiService实例(作为一个WsgiService),并调用其的start()来启动socket服务器端。
#neutron.service
def serve_wsgi(cls):
try:
service = cls.create()
service.start()
except Exception:
with excutils.save_and_reraise_exception():
LOG.exception(_('Unrecoverable error: please check log '
'for details.'))
return service
neutron.service.NeutronApiService类继承自neutron.service.WsgiService,其create方法返回一个appname默认为“neutron”的WsgiService对象;start方法则调用_run_wsgi方法。
def start(self):
self.wsgi_app = _run_wsgi(self.app_name)
_run_wsgi方法主要是从api-paste.ini文件中读取应用(最后是利用neutron.api.v2.router:APIRouter.factory来构造应用),然后为应用创建一个wsgi的服务端,并启动应用,主要代码为。
def _run_wsgi(app_name):
app = config.load_paste_app(app_name)
if not 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
至此,neutron server启动完成,之后,需要创建rpc服务端。
try:
neutron_rpc = service.serve_rpc()
except NotImplementedError:
LOG.info(_("RPC was already started in parent process by plugin."))
else:
rpc_thread = pool.spawn(neutron_rpc.wait)
rpc_thread.link(lambda gt: api_thread.kill())
api_thread.link(lambda gt: rpc_thread.kill())
这些代码创建plugin的rpc服务端,并将api和rpc的生存绑定到一起,一个死掉,则另外一个也死掉。
pool.waitall()
最后是后台不断等待。
下面的图表总结了neutron-server的核心启动过程。
neutron.server | neutron.service#serve_wsgi() | neutron.service.NeutronApiService | neutron.service.WsgiService | neutron.service#_run_wsgi() |
---|---|---|---|---|
neutron_api = service.serve_wsgi(service.NeutronApiService) | service = cls.create(); service.start() | service = cls(app_name=’neutron’) | self.wsgi_app = _run_wsgi(self.app_name) | app = config.load_paste_app(app_name); server = wsgi.Server("Neutron"); server.start(app, cfg.CONF.bind_port, cfg.CONF.bind_host, workers=cfg.CONF.api_workers) |
下一篇:services

发布评论
需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。