Skip to content

Instantly share code, notes, and snippets.

@haneefs
Last active August 29, 2015 14:19
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 haneefs/5d1365ed1a6af11ff663 to your computer and use it in GitHub Desktop.
Save haneefs/5d1365ed1a6af11ff663 to your computer and use it in GitHub Desktop.
Keystoneclient session usage
from keystoneclient.auth.identity import v3
from keystoneclient import client
from keystoneclient import session
from keystoneclient.v3 import client as v3client
def get_client(auth_url=None, token=None, username=None, password=None, project_name=None,
project_domain_name=None, user_domain_name=None, domain_name=None,
insecure=False, ca_cert=None):
"""Return a ks_client client object"""
auth_plugin = None
if token:
auth_plugin = v3.Token(token=token)
else:
auth_plugin = v3.Password (auth_url=auth_url, username=username, password=password,
project_name=project_name, project_domain_name=project_domain_name,
user_domain_name=user_domain_name, domain_name=domain_name)
auth_session = session.Session(auth= auth_plugin, verify=verify, cert=ca_cert)
return v3client.Client(auth_url=auth_url, session=auth_session)
if __name__ == '__main__':
client = get_client(username="admin1", project_name="admin",
user_domain_name="Default", project_domain_name="Default",
password="password", auth_url="http://localhost:35357/v3")
client.authenticate()
print client.auth_token
print client.tokens.validate(client.auth_token)
print client.users.list()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment