理解 openstack 中的 service catalog

来源:互联网 发布:百度的域名值多少钱 编辑:程序博客网 时间:2024/06/07 05:55

1.  请求上下文中的 service catalog

一般情况下,我们可以很方便的从context中获取keystone 所知的全部service catalog。 但它是怎么设置到context中的呢?过程如下:

一个请求通过 wsgi 服务器下发到应用之前,一般需要经过keystone-middle-ware 的认证。在校验 user token 时,如果应用配置了

‘include_service_catalog = True’  的选项,则在向 keystone 校验token时返回service catalog信息,并设置到request 类对象中。


具体可以参考代码:keystonemiddleware/auth_token/__init__.py 的  process_request 方法。

include_service_catalog 配置项在 keystonemiddleware/auth_token/_opts.py 定义。其默认值为True,因此一般情况下下发给应用的

请求中都有service catalog信息,可通过request.environ.get('keystone.token_info') 获取。


2.通过keystone client 来获取服务的 endpoint

这个过程实际上是通过keystoneauth1 中的auth plugin 的get_endpoint方法来获取,如 keystoneauth1/identity/v3/password.py。

该方法会调用get_auth_ref 来获取一个新的token信息,在构建请求 token 的url时会判断是否要添加nocatalog参数,该参数是在创建

auth plugin 实例时传入的,默认值为True,因此请求的token信息中会有service catalog数据。


具体可以参考代码:keystoneauth1/identity/v3/password.py 的get_endpoint方法。

0 0
原创粉丝点击