Ask Your Question

Revision history [back]

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()
print(list)

[root@ip-192-169-142-127 test(keystone_admin)]# python usersList.py

[<User {u'username': u'admin', u'id': u'fedcf0b4ceb0468da33ed2f34460e173', u'enabled': True, u'name': u'admin', u'email': u'root@localhost'}>, <User {u'username': u'neutron', u'id': u'b570520c2df24d2884b0a5b910ac4909', u'enabled': True, u'name': u'neutron', u'email': u'neutron@localhost'}>, <User {u'username': u'gnocchi', u'id': u'777dcf03bc664b27a599df743e37ad2d', u'enabled': True, u'name': u'gnocchi', u'email': u'gnocchi@localhost'}>, <User {u'username': u'aodh', u'id': u'dea68bb6ff7f4172a40cb184c2fe9bcb', u'enabled': True, u'name': u'aodh', u'email': u'aodh@localhost'}>, <User {u'username': u'nova', u'id': u'0ad7f8397d4f4bd1b3fdac43856221d3', u'enabled': True, u'name': u'nova', u'email': u'nova@localhost'}>, <User {u'username': u'glance', u'id': u'8be0e52578c448b689a150308d4ef5e9', u'enabled': True, u'name': u'glance', u'email': u'glance@localhost'}>, <User {u'username': u'ceilometer', u'id': u'a1d879f2163849a199816974dd93e6eb', u'enabled': True, u'name': u'ceilometer', u'email': u'ceilometer@localhost'}>, <User {u'username': u'cinder', u'id': u'0c92af840c374d0eb8b9f0caf16c3b0d', u'enabled': True, u'name': u'cinder', u'email': u'cinder@localhost'}>, <User {u'username': u'swift', u'id': u'36c4b19251834c418749a120def8578d', u'enabled': True, u'name': u'swift', u'email': u'swift@localhost'}>, <User {u'username': u'demo', u'enabled': True, u'name': u'demo', u'id': u'ba77bbbe75b0408a997fa8b30ce49632'}>]

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()
print(list)

[root@ip-192-169-142-127 test(keystone_admin)]# python usersList.py

[<User {u'username': u'admin', u'id': u'fedcf0b4ceb0468da33ed2f34460e173', u'enabled': True, u'name': u'admin', u'email': u'root@localhost'}>, <User {u'username': u'neutron', u'id': u'b570520c2df24d2884b0a5b910ac4909', u'enabled': True, u'name': u'neutron', u'email': u'neutron@localhost'}>, <User {u'username': u'gnocchi', u'id': u'777dcf03bc664b27a599df743e37ad2d', u'enabled': True, u'name': u'gnocchi', u'email': u'gnocchi@localhost'}>, <User {u'username': u'aodh', u'id': u'dea68bb6ff7f4172a40cb184c2fe9bcb', u'enabled': True, u'name': u'aodh', u'email': u'aodh@localhost'}>, <User {u'username': u'nova', u'id': u'0ad7f8397d4f4bd1b3fdac43856221d3', u'enabled': True, u'name': u'nova', u'email': u'nova@localhost'}>, <User {u'username': u'glance', u'id': u'8be0e52578c448b689a150308d4ef5e9', u'enabled': True, u'name': u'glance', u'email': u'glance@localhost'}>, <User {u'username': u'ceilometer', u'id': u'a1d879f2163849a199816974dd93e6eb', u'enabled': True, u'name': u'ceilometer', u'email': u'ceilometer@localhost'}>, <User {u'username': u'cinder', u'id': u'0c92af840c374d0eb8b9f0caf16c3b0d', u'enabled': True, u'name': u'cinder', u'email': u'cinder@localhost'}>, <User {u'username': u'swift', u'id': u'36c4b19251834c418749a120def8578d', u'enabled': True, u'name': u'swift', u'email': u'swift@localhost'}>, <User {u'username': u'demo', u'enabled': True, u'name': u'demo', u'id': u'ba77bbbe75b0408a997fa8b30ce49632'}>]


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()
print(list)
[root@ip-192-169-142-127 test(keystone_admin)]# python  userListV3.py
[<User domain_id=default, email=gnocchi@localhost, enabled=True, id=16ed61e121ec4fcdac8c516f2bebb4de, links={u'self': u'http://192.169.142.127:35357/v3/users/16ed61e121ec4fcdac8c516f2bebb4de'}, name=gnocchi>, <User domain_id=default, email=neutron@localhost, enabled=True, id=378b049484674a1589ab53f9033cd06a, links={u'self': u'http://192.169.142.127:35357/v3/users/378b049484674a1589ab53f9033cd06a'}, name=neutron>, <User domain_id=default, email=swift@localhost, enabled=True, id=3946109d4a354b80bef87f90568d1a98, links={u'self': u'http://192.169.142.127:35357/v3/users/3946109d4a354b80bef87f90568d1a98'}, name=swift>, <User domain_id=default, email=glance@localhost, enabled=True, id=4805e1fc63eb4e4e9a0a43436034bf33, links={u'self': u'http://192.169.142.127:35357/v3/users/4805e1fc63eb4e4e9a0a43436034bf33'}, name=glance>, <User default_project_id=052b16e56537467d8161266b52a43b54, domain_id=default, enabled=True, id=564cae19ba3745878b014ca3cc46a082, links={u'self': u'http://192.169.142.127:35357/v3/users/564cae19ba3745878b014ca3cc46a082'}, name=demo>, <User domain_id=default, email=nova@localhost, enabled=True, id=85d8493fc8574515acb404ec6a99ecff, links={u'self': u'http://192.169.142.127:35357/v3/users/85d8493fc8574515acb404ec6a99ecff'}, name=nova>, <User default_project_id=16b92f34d350480f9ab2a98a1960ceb8, domain_id=default, email=root@localhost, enabled=True, id=b6f2f511caa44f4e94ce5b2a5809dc50, links={u'self': u'http://192.169.142.127:35357/v3/users/b6f2f511caa44f4e94ce5b2a5809dc50'}, name=admin>, <User domain_id=default, email=aodh@localhost, enabled=True, id=ed30b02e39ba4ecfafc0910a3e123fcc, links={u'self': u'http://192.169.142.127:35357/v3/users/ed30b02e39ba4ecfafc0910a3e123fcc'}, name=aodh>, <User domain_id=default, email=ceilometer@localhost, enabled=True, id=ff46b7f16ece4cdcb88a0c150a52df65, links={u'self': u'http://192.169.142.127:35357/v3/users/ff46b7f16ece4cdcb88a0c150a52df65'}, name=ceilometer>]

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()
print(list)

[root@ip-192-169-142-127 test(keystone_admin)]# python usersList.py

[<User {u'username': u'admin', u'id': u'fedcf0b4ceb0468da33ed2f34460e173', u'enabled': True, u'name': u'admin', u'email': u'root@localhost'}>, <User {u'username': u'neutron', u'id': u'b570520c2df24d2884b0a5b910ac4909', u'enabled': True, u'name': u'neutron', u'email': u'neutron@localhost'}>, <User {u'username': u'gnocchi', u'id': u'777dcf03bc664b27a599df743e37ad2d', u'enabled': True, u'name': u'gnocchi', u'email': u'gnocchi@localhost'}>, <User {u'username': u'aodh', u'id': u'dea68bb6ff7f4172a40cb184c2fe9bcb', u'enabled': True, u'name': u'aodh', u'email': u'aodh@localhost'}>, <User {u'username': u'nova', u'id': u'0ad7f8397d4f4bd1b3fdac43856221d3', u'enabled': True, u'name': u'nova', u'email': u'nova@localhost'}>, <User {u'username': u'glance', u'id': u'8be0e52578c448b689a150308d4ef5e9', u'enabled': True, u'name': u'glance', u'email': u'glance@localhost'}>, <User {u'username': u'ceilometer', u'id': u'a1d879f2163849a199816974dd93e6eb', u'enabled': True, u'name': u'ceilometer', u'email': u'ceilometer@localhost'}>, <User {u'username': u'cinder', u'id': u'0c92af840c374d0eb8b9f0caf16c3b0d', u'enabled': True, u'name': u'cinder', u'email': u'cinder@localhost'}>, <User {u'username': u'swift', u'id': u'36c4b19251834c418749a120def8578d', u'enabled': True, u'name': u'swift', u'email': u'swift@localhost'}>, <User {u'username': u'demo', u'enabled': True, u'name': u'demo', u'id': u'ba77bbbe75b0408a997fa8b30ce49632'}>]


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()
print(list)
for user in list:
    print(user.name)
[root@ip-192-169-142-127 test(keystone_admin)]# python  userListV3.py
[<User domain_id=default, email=gnocchi@localhost, enabled=True, id=16ed61e121ec4fcdac8c516f2bebb4de, links={u'self': u'http://192.169.142.127:35357/v3/users/16ed61e121ec4fcdac8c516f2bebb4de'}, name=gnocchi>, <User domain_id=default, email=neutron@localhost, enabled=True, id=378b049484674a1589ab53f9033cd06a, links={u'self': u'http://192.169.142.127:35357/v3/users/378b049484674a1589ab53f9033cd06a'}, name=neutron>, <User domain_id=default, email=swift@localhost, enabled=True, id=3946109d4a354b80bef87f90568d1a98, links={u'self': u'http://192.169.142.127:35357/v3/users/3946109d4a354b80bef87f90568d1a98'}, name=swift>, <User domain_id=default, email=glance@localhost, enabled=True, id=4805e1fc63eb4e4e9a0a43436034bf33, links={u'self': u'http://192.169.142.127:35357/v3/users/4805e1fc63eb4e4e9a0a43436034bf33'}, name=glance>, <User default_project_id=052b16e56537467d8161266b52a43b54, domain_id=default, enabled=True, id=564cae19ba3745878b014ca3cc46a082, links={u'self': u'http://192.169.142.127:35357/v3/users/564cae19ba3745878b014ca3cc46a082'}, name=demo>, <User domain_id=default, email=nova@localhost, enabled=True, id=85d8493fc8574515acb404ec6a99ecff, links={u'self': u'http://192.169.142.127:35357/v3/users/85d8493fc8574515acb404ec6a99ecff'}, name=nova>, <User default_project_id=16b92f34d350480f9ab2a98a1960ceb8, domain_id=default, email=root@localhost, enabled=True, id=b6f2f511caa44f4e94ce5b2a5809dc50, links={u'self': u'http://192.169.142.127:35357/v3/users/b6f2f511caa44f4e94ce5b2a5809dc50'}, name=admin>, <User domain_id=default, email=aodh@localhost, enabled=True, id=ed30b02e39ba4ecfafc0910a3e123fcc, links={u'self': u'http://192.169.142.127:35357/v3/users/ed30b02e39ba4ecfafc0910a3e123fcc'}, name=aodh>, <User domain_id=default, email=ceilometer@localhost, enabled=True, id=ff46b7f16ece4cdcb88a0c150a52df65, links={u'self': u'http://192.169.142.127:35357/v3/users/ff46b7f16ece4cdcb88a0c150a52df65'}, name=ceilometer>]
gnocchi
neutron
swift
glance
demo
nova
admin
aodh
ceilometer

For keystone api v2
[root@ip-192-169-142-127 test(keystone_admin)]# cat usersList.py

[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()
print(list)

for user in list: print(user.name) [root@ip-192-169-142-127 test(keystone_admin)]# python usersList.py

[<User {u'username': u'admin', u'id': u'fedcf0b4ceb0468da33ed2f34460e173', u'enabled': True, u'name': u'admin', u'email': u'root@localhost'}>, <User {u'username': u'neutron', u'id': u'b570520c2df24d2884b0a5b910ac4909', u'enabled': True, u'name': u'neutron', u'email': u'neutron@localhost'}>, <User {u'username': u'gnocchi', u'id': u'777dcf03bc664b27a599df743e37ad2d', u'enabled': True, u'name': u'gnocchi', u'email': u'gnocchi@localhost'}>, <User {u'username': u'aodh', u'id': u'dea68bb6ff7f4172a40cb184c2fe9bcb', u'enabled': True, u'name': u'aodh', u'email': u'aodh@localhost'}>, <User {u'username': u'nova', u'id': u'0ad7f8397d4f4bd1b3fdac43856221d3', u'enabled': True, u'name': u'nova', u'email': u'nova@localhost'}>, <User {u'username': u'glance', u'id': u'8be0e52578c448b689a150308d4ef5e9', u'enabled': True, u'name': u'glance', u'email': u'glance@localhost'}>, <User {u'username': u'ceilometer', u'id': u'a1d879f2163849a199816974dd93e6eb', u'enabled': True, u'name': u'ceilometer', u'email': u'ceilometer@localhost'}>, <User {u'username': u'cinder', u'id': u'0c92af840c374d0eb8b9f0caf16c3b0d', u'enabled': True, u'name': u'cinder', u'email': u'cinder@localhost'}>, <User {u'username': u'swift', u'id': u'36c4b19251834c418749a120def8578d', u'enabled': True, u'name': u'swift', u'email': u'swift@localhost'}>, <User {u'username': u'demo', u'enabled': True, u'name': u'demo', u'id': u'ba77bbbe75b0408a997fa8b30ce49632'}>]
 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