I'm trying to set up a nova client and ensure that there are no authentication errors on client creation. My attempt is below:
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
However, the nova.authenticate()
call throws a novaclient.exceptions.InvalidUsage
which tells me to authenticate the Session object. The Session object doesn't seem to have a way to authenticate, though.
While OpenStack will attempt to authenticate on the first request and cache the authentication, I'd prefer to know immediately if the user is authorized to make requests based on the credentials provided.
How can I authenticate the session object on-demand?