Skip to content

Instantly share code, notes, and snippets.

@kojiwell
Last active December 16, 2015 21:59
Show Gist options
  • Save kojiwell/5503473 to your computer and use it in GitHub Desktop.
Save kojiwell/5503473 to your computer and use it in GitHub Desktop.
There is an example to get user by USER_ID on the keystone-api documentation.(https://keystoneclient.readthedocs.org/en/latest/api.html) But usually we want to get user by USER_NAME. Here's the way to do that.
#!/usr/bin/env python
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
from keystoneclient.v2_0 import client
from keystoneclient import utils
keystone = client.Client(username='admin',
password='admin_password',
tenant_name='admin_tenant',
cacert='/path/to/cacert.pem',
auth_url='https://keystone.domain.org:35357/v2.0/')
# Get user by USER_NAME instead of USER_ID
user = utils.find_resource(keystone.users, USER_NAME)
# Referred links
# https://keystoneclient.readthedocs.org/en/latest/api.html
# http://stackoverflow.com/questions/15525297/openstack-keystoneclient-get-user-by-name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment