Cinder API源码分析

Cinder API相关源码位于cinder/api目录
--contrib
--middleware
--openstack
--schemas
--v1
--v2
--view
contrib目录下存放的即是所有的扩展资源,而核心资源的实现则又有v1和v2两个版本,分别位于v1与v2两个目录。这些API的实现主要涵盖了对Volume、Volume类型(Volume Type)以及Snapshot的管理操作。
Volume类型是用户自定义的卷的一种标识,Cinder提供了相关的API可以自由地创建删除Volume类型。
Snapshot是一个Volume在特定时间点的一个快照,因此,Snapshot是只读的,不可以被改变。Snapshot可以被用来创建一个新的Volume。
对于Cinder API,无论是v1还是v2,都是对应目录,发现所有的资源,并进行依次加载。
但是在加载所有的扩展资源时,Cinder根据配置文件/etc/cinder/cinder.conf的选项进行配置
# Specify list of extensions to load when using
# osapi_volume_extension option with
# cinder.api.contrib.select_extensions (list value)
#osapi_volume_ext_list=
# osapi volume extension to load (multi valued)
#osapi_volume_extension=cinder.api.contrib.standard_extensions
osapi_volume_extension的值分为两种情况:stand_extionsions与select_extensions。
standard_extensions指加载contrib目录下实现的所有资源,select_extensions则可以指定加载哪些资源。stand_extionsions为默认的设置。
如果stand_extionsions选择值为cinder.api.contrib.select_extensions,则可以在osapi_volume_ext_list选项中指定加载资源的列表。
Cinder API采用了类似Nova API的实现方式,Cinder API的执行过程同样类似与Nova API,从cinderclient开始算起包括三个阶段:cinderclient将用户命令转换为标准HTTP请求的阶段;Paste Deploy将请求路由到具体的WSGI Application的阶段;以及Routes将请求路由到具体函数并执行阶段。
Cinder API服务cinder-api在第二阶段开始参与,会创建一个WSGI Server去监听用户的HTTP请求,Paste Deploy路由的过程主要依赖于配置文件/etc/cinder/api-paste.ini
[composite:osapi_volume]
use = call:cinder.api:root_app_factory
/: apiversions
/v1: openstack_volume_api_v1
v2: openstack_volume_api_v2
[composite:openstack_volume_api_v1]
use = call:cinder.api.middleware.auth:pipeline_factory
noauth = request_id faultwrap sizelimit osprofiler noauth apiv1
keystone = request_id faultwrap sizelimit osprofiler authtoken keystonecontext apiv1
keystone_nolimit = request_id faultwrap sizelimit osprofiler authtoken keystonecontext apiv1
[composite:openstack_volume_api_v2]
use = call:cinder.api.middleware.auth:pipeline_factory
noauth = request_id faultwrap sizelimit osprofiler noauth apiv2
keystone = request_id faultwrap sizelimit osprofiler authtoken keystonecontext apiv2
keystone_nolimit = request_id faultwrap sizelimit osprofiler authtoken keystonecontext apiv2
[filter:request_id]
paste.filter_factory = cinder.openstack.common.middleware.request_id:RequestIdMiddleware.factory
[filter:faultwrap]
paste.filter_factory = cinder.api.middleware.fault:FaultWrapper.factory
[filter:osprofiler]
paste.filter_factory = osprofiler.web:WsgiMiddleware.factory
hmac_keys = SECRET_KEY
enabled = yes
[filter:noauth]
paste.filter_factory = cinder.api.middleware.auth:NoAuthMiddleware.factory
[filter:sizelimit]
paste.filter_factory = cinder.api.middleware.sizelimit:RequestBodySizeLimiter.factory
[app:apiv1]
paste.app_factory = cinder.api.v1.router:APIRouter.factory
[app:apiv2]
paste.app_factory = cinder.api.v2.router:APIRouter.factory
有两个WSGI Application,包括apiv1和apiv2会被加载,它们的对应分别是cinder.api.v1.router:APIRouter和cinder.api.v2.router:APIRouter,这两个类继承自cinder.api.openstack.APIRouter
# cinder / api / openstack / __init__.py
class APIRouter(base_wsgi.Router):
    """Routes requests on the API to the appropriate controller and method."""
    ExtensionManager = None # override in subclasses
    @classmethod
    def factory(cls, global_config, **local_config):
        """Simple paste factory, :class:`cinder.wsgi.Router` doesn't have."""
        return cls()
    def __init__(self, ext_mgr=None):
        if ext_mgr is None:
            if self.ExtensionManager:
                ext_mgr = self.ExtensionManager()
            else:
                raise Exception(_("Must specify an ExtensionManager class"))
        mapper = ProjectMapper()
        self.resources = {}
        self._setup_routes(mapper, ext_mgr)
        self._setup_ext_routes(mapper, ext_mgr)
        self._setup_extensions(ext_mgr)
        super(APIRouter, self).__init__(mapper)
类APIRoute初始化时,会调用_setup_routes()、_setup_ext_routes()、_setup_extensions()分别建立核心资源和扩展资源路由。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值