本文将介绍Neutron的HTTP API的内部实现,以及Neutron中,可以用来创建Neutron API扩展的类。
Python网页应用通过Python Web Server Gateway Interface (WSGI) 与 web服务器交互,WSGI定义在文档 PEP 333 中。
建立 Startup
Neutron的WSGI服务器由 server module 启动,入口点serve_wsgi被调用创建NeutronApiService实例,其随后返回给了_server module_,其生产一个Eventlet GreenPool 将允许WSGI应用,并响应来自客户端的请求。
-
NeutronApiService: http://git.openstack.org/cgit/openstack/neutron/tree/neutron/service.py
-
Eventlet: http://eventlet.net/
WSGI 应用
在NeutronApiService建立期间,函数_run_wsgi使用config.py文件中的load_paste_app函数创建一个WSGI应用,load_paste_app解析api-paste.ini文件,以便使用Paste 的 deploy 创建WSGI应用。
api-paste.ini文件使用Paste INI 文件格式定义了WSGI应用和routes。
INI文件控制paste去实例化Neutron的APIRouter类,其包含多个方法,可映射Neutron资源(如:Ports, Networks, Subnets)到URL,及每个资源的控制器。
-
config.py: http://git.openstack.org/cgit/openstack/neutron/tree/neutron/common/config.py
-
api-paste.ini: http://git.openstack.org/cgit/openstack/neutron/tree/etc/api-paste.ini
-
APIRouter: http://git.openstack.org/cgit/openstack/neutron/tree/neutron/api/v2/router.py
-
Paste: http://pythonpaste.org/
-
Deploy: http://pythonpaste.org/deploy/
-
Paste INI file format: http://pythonpaste.org/deploy/#applications