/etc/nova/api-paste.ini文件中的定义了以下三个composite:
[composite:osapi_compute]
use = call:nova.api.openstack.urlmap:urlmap_factory
/: oscomputeversions
# v21 is an exactly feature match for v2, except it has more stringent
# input validation on the wsgi surface (prevents fuzzing early on the
# API). It also provides new features via API microversions which are
# opt into for clients. Unaware clients will receive the same frozen
# v2 API feature set, but with some relaxed validation
/v2: openstack_compute_api_v21_legacy_v2_compatible
/v2.1: openstack_compute_api_v21
[composite:openstack_compute_api_v21]
use = call:nova.api.auth:pipeline_factory_v21
noauth2 = cors http_proxy_to_wsgi compute_req_id faultwrap request_log sizelimit osprofiler noauth2 osapi_compute_app_v21
keystone = cors http_proxy_to_wsgi compute_req_id faultwrap request_log sizelimit osprofiler authtoken keystonecontext osapi_compute_app_v21
[composite:openstack_compute_api_v21_legacy_v2_compatible]
use = call:nova.api.auth:pipeline_factory_v21
noauth2 = cors http_proxy_to_wsgi compute_req_id faultwrap request_log sizelimit osprofiler noauth2 legacy_v2_compatible osapi_compute_app_v21
keystone = cors http_proxy_to_wsgi compute_req_id faultwrap request_log sizelimit osprofiler authtoken keystonecontext legacy_v2_compatible osapi_compute_app_v21
[app:osapi_compute_app_v21]
paste.app_factory = nova.api.openstack.compute:APIRouterV21.factory
当收到http://xxxxxx/v2和http://xxxxxxx/v2.1的访问请求时,执行一串过滤函数后,如用户身份权限验证,将执行文件nova/api/openstack/compute/routes.py中类APIRouterV21的factory函数。关于WSGI、Paste deploy可以参考文章http://lib.csdn.net/article/openstack/43185。
类APIRouterV21进一步实现了URL到处理函数的映射,以flavor和server为例看一下映射实现:
}),
('/flavors', {
'GET': [flavor_controller, 'index'],
'POST': [flavor_controller, 'create']
}),
('/flavors/detail', {
'GET': [flavor_controller, 'detail']
}),
('/flavors/{id}', {
'GET': [flavor_controller, 'show'],
'DELETE': [flavor_controller, 'delete']
}),
}),
('/servers', {
'GET': [server_controller, 'index'],
'POST': [server_controller, 'create']
}),
('/servers/detail', {
'GET': [server_controller, 'detail']
}),
('/servers/{id}', {
'GET': [server_controller, 'show'],
'PUT': [server_controller, 'update'],
'DELETE': [server_controller, 'delete']
}),
以/flavors结尾的http GET请求,将被映射到flavor_controller中的index函数,以/servers结尾的http GET请求,将被映射到server_controller中的index函数,flavor_controller和server_controller的定义如下:
flavor_controller = functools.partial(_create_controller,
flavors.FlavorsController,
[
flavor_rxtx.FlavorRxtxController,
flavor_access.FlavorActionController
],
[
flavor_manage.FlavorManageController,
flavor_access.FlavorActionController
]
)
server_controller = functools.partial(_create_controller,
servers.ServersController,
[
config_drive.ConfigDriveController,
extended_availability_zone.ExtendedAZController,
extended_server_attributes.ExtendedServerAttributesController,
extended_status.ExtendedStatusController,
extended_volumes.ExtendedVolumesController,
hide_server_addresses.Controller,
keypairs.Controller,
security_groups.SecurityGroupsOutputController,
server_usage.ServerUsageController,
],
最终将分别调用文件nova/api/openstack/compute/flavors.py中类FlavorsController的index()函数和文件nova/api/openstack/compute/servers.py中类ServersController的index()函数,至此,从http的url请求到服务端对应的处理函数之间的调用映射过程就清晰了。