作为Neutron中的唯一服务进程,neutron-server承担着接收用户RESTful API请求并分发处理的任务。
根据setup.cfg中的配置,neutron-server的入口位于neutron/server/__init__.py,Paste Deploy会在这个WSGI Server创建时参与进来,基于Paste配置文件/etc/nova/api-paste.ini去加载WSGI Application。
[composite:neutronapi_v2_0]
use = call:neutron.auth:pipeline_factory
noauth = request_id catch_errors extensions neutronapiapp_v2_0
keystone = request_id catch_errors authtoken keystonecontext extensions neutronapiapp_v2_0
[app:neutronapiapp_v2_0]
paste.app_factory = neutron.api.v2.router:APIRouter.factory
类APIRouter会完成所有Core API与Extension API的加载与路由规则的创建。
从收到用户的HTTP请求到具体Controller中操作的过程与其他项目基本类似。
Controller中具体执行时,会根据请求的资源和Action,拼接出应该调用的接口交由Plugin处理。
比如所请求的资源是network,Action是“CREATE”,则应该调用的Plugin接口即为“create_network”。
# neutron/api/v2/base.py
class Controller(object):
def create(self, request, body=None, **kwargs):
"""Creates a new instance of the requested entity."""
parent_id = kwargs.get(self._parent_id_name)
self._notifier.info(request.context,
self._resource + '.create.start',
body)
body = Controller.prepare_request_body(request.context, body, True,
self._resource, self._attr_info,
allow_bulk=self._allow_bulk)
action = self._plugin_handlers[self.CREATE]