我正在尝试设置一个nova客户端,并确保在创建客户端时没有身份验证错误。我的尝试如下:
from novaclient import client
from keystoneauth1 import session
from keystoneauth1.identity import v3
def setup_nova(creds):
"""
Creates a nova instance with which we can leverage the OpenStack virtualization
platform.
:param creds: A dictionary containing the authorization url, username,
password, version, and project ID associated with the OpenStack
cluster.
:type creds: dict
"""
password = v3.PasswordMethod(username=creds['USERNAME'],
password=creds['PASSWORD'],
user_domain_name='default')
auth = v3.Auth(auth_url=creds['AUTH_URL'],
auth_methods=[password],
project_id=creds['PROJECT_ID'])
sess = session.Session(auth=auth)
nova = client.Client(creds['VERSION'], session=sess)
nova.authenticate()
return nova
但是,nova.authenticate()
调用抛出一个novaclient.exceptions.InvalidUsage
,它告诉我对会话对象进行身份验证。不过,Session对象似乎没有进行身份验证的方法。在
虽然OpenStack将尝试在第一次请求时进行身份验证并缓存身份验证,但我更希望立即知道用户是否有权根据所提供的凭据发出请求。在
如何按需验证会话对象?在
也许您可以尝试使用下面显示的keystoneclient document示例来验证nova会话:
我参考上面的例子来修改您的代码:
^{pr2}$相关问题 更多 >
编程相关推荐