Skip to content

Instantly share code, notes, and snippets.

@the2hill
Created April 20, 2015 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save the2hill/6fb8ff1d06905d98d0bb to your computer and use it in GitHub Desktop.
Save the2hill/6fb8ff1d06905d98d0bb to your computer and use it in GitHub Desktop.
from keystoneclient import session
from keystoneclient.v2_0 import client as v2_client
from keystoneclient.v3 import client as v3_client
global _SESSION
if not _SESSION:
if cfg.CONF.keystone_authtoken.auth_version == '2':
client = v2_client
elif cfg.CONF.keystone_authtoken.auth_version == '3':
client = v3_client
else:
raise Exception('Unknown keystone version!')
try:
kc = client.Client(
auth_url=cfg.CONF.keystone_authtoken.auth_uri,
username=cfg.CONF.keystone_authtoken.admin_user,
password=cfg.CONF.keystone_authtoken.admin_password,
tenant_name=cfg.CONF.keystone_authtoken.admin_tenant_name
)
_SESSION = session.Session(auth=kc)
except Exception:
with excutils.save_and_reraise_exception():
LOG.exception(_LE("Error creating Keystone session."))
return client.Client(session=_SESSION)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment