Blog
Search…
List all tenants belonging an user
Here is a simple script to list all tenants belonging an user:
1
#!/bin/bash
2
echo -n "Username : " ; read usercheck
3
for userid in $(keystone user-list | grep -w $usercheck | awk '{print$2}')
4
do
5
for tenant in $(keystone tenant-list | awk 'NR>3 && /^|/ {print$2}')
6
do
7
for tenantid in $(keystone user-role-list --user $userid --tenant $tenant | awk 'NR>3 && /^|/ {print$8}')
8
do
9
keystone tenant-list | grep $tenantid | awk '{print$4}'
10
done
11
done
12
done
Copied!
Also you can run all in a simple cmd line
1
echo -n "user name "; read usercheck; for userid in $(keystone user-list | grep $usercheck | awk '{print$2}'); do echo $userid | for tenant in $(keystone tenant-list | awk 'NR>3 && /^|/ {print$2}'); do echo $tenant | for tenantid in $(keystone user-role-list --user $userid --tenant $tenant | awk 'NR>3 && /^|/ {print$8}'); do keystone tenant-list | grep $tenantid | awk '{print$4}'; done ; done ; done
Copied!
If you are a developer, probably you need to list all tenants in a HTTP request, for this purpose you can use the REST API to the port 5000 of keystone
1
curl -i -X GET http://KEYSTONEIP:5000/v2.0/tenants -H "User-Agent: python-keystoneclient" -H "X-Auth-Token: USERTOKEN"
Copied!
I have saved the user token in a OS_VARIABLE called OS_TOKEN, if you don't do that, you should input all the token in the HTTP request.
1
curl -i -X GET http://192.168.1.11:5000/v2.0/tenants -H "User-Agent: python-keystoneclient" -H "X-Auth-Token: $OS_TOKEN"
Copied!
Last modified 1yr ago
Copy link