ldeluca
ldeluca

Reputation: 944

OpenStack keystoneclient get user by name

I know it is possible to get a user by id but all I have available is the name. Anyone know how to get a user by name using the keystone client v 2.0?

from keystoneclient.v2_0 import client
keystone = client.Client(username=USER,
                         password=PASS,
                         tenant_name=TENANT_NAME,
                         auth_url=KEYSTONE_URL)
user = keystone.users.get(USER_ID)

need something like the following ** keystone.users.getByName(USER_NAME)

Upvotes: 2

Views: 1598

Answers (1)

Matt Joyce
Matt Joyce

Reputation: 2010

Figured out a way to do this from keystoneclient. Sort of.

Example:

#!/usr/bin/env python

from keystoneclient.v2_0 import client
from keystoneclient import utils

keystone = client.Client(username='admin',
                         password='stack',
                         tenant_name='demo',
                         auth_url='http://192.168.122.236:5000/v2.0/')


def do_user_get(kc, args):
    """Display user details."""
    user = utils.find_resource(kc.users, args)
    utils.print_dict(user._info)

do_user_get (keystone, 'demo')

Makes use of utils in addition to the client.users

There are some extra parsing functions in util you might want to check out.

Upvotes: 3

Related Questions