在nova/volume 这个目录下定义了nova访问volume的接口,这个路径下的__init__.py为空文件,因此只关注cinder.py
首先通过def cinderclient(context, microversion=None, skip_version_check=False)函数得到cinder client,而cinderclient 中是通过keystore中保存的
cinder的endpoint拿到cinder的client的
def cinderclient(context, microversion=None, skip_version_check=False):
"""Constructs a cinder client object for making API requests.
:param context: The nova request context for auth.
:param microversion: Optional microversion to check against the client.
This implies that Cinder v3 is required for any calls that require a
microversion. If the microversion is not available, this method will
raise an CinderAPIVersionNotAvailable exception.
:param skip_version_check: If True and a specific microversion is
requested, the version discovery check is skipped and the microversion
is used directly. This should only be used if a previous check for the
same microversion was successful.
"""
global _SESSION
// 这里的ks_loading 赋值为 from keystoneauth1 import loading as ks_loading 可以知道这里的ks_loading 就代表keystore,因此nova是从keystore的endpoint拿到cinder的接口
if not _SESSION:
_SESSION = ks_loading.load_session_from_conf_options(
CONF, nova.conf.cinder.cinder_group.name)
url = None
if CONF.cinder.endpoint_template:
url = CONF.cinder.endpoint_template % context.to_dict()
endpoint_override = url
else:
url = _SESSION.get_endpoint(auth, **service_parameters)
return cinder_client.Client(version,
session=_SESSION,
auth=auth,
endpoint_override=endpoint_override,
connect_retries=CONF.cinder.http_retries,
global_request_id=context.global_id,
**service_parameters)
这个文件中剩下就是的定义了一堆访问cinder的接口,例如:
class API(object):
"""API for interacting with the volume manager."""
@translate_volume_exception
def get(self, context, volume_id):
//原来nova get是通过cinder的clint 访问volume的get函数
item = cinderclient(context).volumes.get(volume_id)
return _untranslate_volume_summary_view(context, item)
@translate_cinder_exception
def get_all(self, context, search_opts=None):
search_opts = search_opts or {}
//原来nova get_all是通过cinder的clint 访问volume的list函数
items = cinderclient(context).volumes.list(detailed=True,
search_opts=search_opts)
rval = []
for item in items:
rval.append(_untranslate_volume_summary_view(context, item))
return rval
nova中的volume接口
最新推荐文章于 2022-04-08 21:02:17 发布