Ask Your Question
0

users list in python sdk

asked 2016-04-30 22:43:52 -0500

daryana gravatar image

I wrote the following code in python script:

# List Images
  images = conn.list_images()
  for image in images:
     print(image)

#List Users
 users = conn.identity_users()
 for user in users:
    print(user)

It lists Images corroctly, but when I try to list users I get this error:

AttributeError: 'Connection' object has no attribute 'identity_users'

what is the problem? I have to import anything? or other way to list users? Thanks.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-05-01 03:43:37 -0500

dbaxps gravatar image

updated 2016-05-01 05:19:02 -0500

For keystone api v2

[root@ip-192-169-142-127 test(keystone_admin)]# cat  usersList.py 
#!/usr/bin/env python
import os
import keystoneclient.v2_0.client as ksclient

def get_keystone_creds():
    d = {}
    d['username'] = os.environ['OS_USERNAME']
    d['password'] = os.environ['OS_PASSWORD']
    d['auth_url'] = os.environ['OS_AUTH_URL']
    d['tenant_name'] = os.environ['OS_TENANT_NAME']
    return d

creds = get_keystone_creds()
keystone = ksclient.Client(**creds)
list = keystone.users.list()
for user in list:
    print(user.name)
[root@ip-192-169-142-127 test(keystone_admin)]# python  usersList.py
admin
neutron
gnocchi
aodh
nova
glance
ceilometer
cinder
swift
demo


Keystone API v3
[root@ip-192-169-142-127 test(keystone_admin)]# cat userListV3.py

#!/usr/bin/env python

from keystoneclient.auth.identity import v3
from keystoneclient import session
from keystoneclient.v3 import client
auth = v3.Password(auth_url='http://192.169.142.127:5000/v3',
               user_id='b6f2f511caa44f4e94ce5b2a5809dc50',
               password='7049f834927e4468',
               project_id='16b92f34d350480f9ab2a98a1960ceb8')
sess = session.Session(auth=auth)
keystone = client.Client(session=sess)
list = keystone.users.list()
for user in list:
    print(user.name)
[root@ip-192-169-142-127 test(keystone_admin)]# python userListV3.py
gnocchi
neutron
swift
glance
demo
nova
admin
aodh
ceilometer
edit flag offensive delete link more

Comments

thanks. I try your first script and get this error:

     d['username'] = os.environ['admin']
     File "/usr/lib64/python2.7/UserDict.py", line 23, in __getitem__
        raise KeyError(key)
      KeyError: 'admin'
daryana gravatar imagedaryana ( 2016-05-01 05:48:54 -0500 )edit

You didn't source keystonerc_admin (RH) or it's analog on Ubuntu.

dbaxps gravatar imagedbaxps ( 2016-05-01 07:03:32 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2016-04-30 22:43:52 -0500

Seen: 343 times

Last updated: May 01 '16