任何人都知道如何获取用户的租户列表?我知道我可以获得租户的用户,我可以获得所有租户的列表,所以从技术上讲,我可以遍历所有租户并寻找特定用户,但这似乎是一种麻烦的方法。
答案 0 :(得分:2)
不知道使用keystone-client但是有可能使用keystone API的第3版:
GET / v3 / users / ['USER_ID'] / projects
答案 1 :(得分:1)
这不是由CLI或API实现的。您可以列出令牌可以访问的所有租户,但您无法按用户ID列出租户。
Keystone将用户与租户和角色相关联。所以基本上我们应该能够列出用户的所有角色,从而获得所有租户。但在实践中,你不能:
Keystone客户端确实有user-role-list
子命令,但tenant-id
是强制性的,如下例所示:
$ keystone --token <...> --endpoint http://<...> user-role-list
'Client' object has no attribute 'auth_tenant_id'
$ keystone --token <...> --endpoint http://<...> user-role-list --user-id 0ab2b35d609d4994aa3100b13bcf9cb8
'Client' object has no attribute 'auth_tenant_id'
$ keystone --token <...> --endpoint http://<...> user-role-list --user-id 0ab2b35d609d4994aa3100b13bcf9cb8 --tenant-id 74ece217e4f543c5bd1387786fd9173c
+----------------------------------+-------+----------------------------------+----------------------------------+
| id | name | user_id | tenant_id |
+----------------------------------+-------+----------------------------------+----------------------------------+
| 3ddf15ce213e4fa08f4d5769db4ee30b | admin | 0ab2b35d609d4994aa3100b13bcf9cb8 | 74ece217e4f543c5bd1387786fd9173c |
+----------------------------------+-------+----------------------------------+----------------------------------+
Rest API也是如此:
/ users / {user_id} / roles在端口35357(以及端口5000上的HTTP 404)上返回HTTP 501:
$ curl -H "X-Auth-Token:..." http://localhost:35357/v2.0/users/aa1a4faf337544f8a29eb033fa895eef/roles | jq '.'
{
"error": {
"title": "Not Implemented",
"code": 501,
"message": "User roles not supported: tenant ID required"
}
}
如果您指定了租户ID,则可以:
$ curl -H "X-Auth-Token:..." http://localhost:35357/v2.0/tenants/8e0c523848e645be829c779bb9307290/users/aa1a4faf337544f8a29eb033fa895eef/roles | jq '.'
{
"roles": [
{
"id": "9fe2ff9ee4384b1894a90878d3e92bab",
"name": "_member_",
"description": "Default role for project membership",
"enabled": "True"
},
{
"name": "admin",
"id": "3ddf15ce213e4fa08f4d5769db4ee30b"
}
]
}
为了完整性,您可以通过Rest API
获取令牌的租户:$ curl -H "X-Auth-Token:<token here>" http://localhost:5000/v2.0/tenants/ | jq '.'
{
"tenants": [
{
"name": "Altair",
"id": "51b8b30d4e574899b8fef6d819fda389",
"enabled": true,
"description": ""
},
{
"name": "Aldebaran",
"id": "92b1315b07f44afdaec920a868685b28",
"enabled": true,
"description": ""
}
],
"tenants_links": []
}
答案 2 :(得分:1)
使用user3067622的建议,从Keystone获取我的Auth Token后,以下语法有效:
curl -v http://your.cloud.com:35357/v3/users/<user_UUID>/projects -X GET \
-H 'Content-type: application/json' \
-H 'Accept: application/json' \
-H "X-Auth-Token: 27427040f887440c80ed6a697b294c47" | python -m json.tool | grep name
答案 3 :(得分:-2)
不是真的。但您可以直接从keystone API获取。
示例:
from keystoneclient.v2_0 import client
from keystoneclient.v2_0 import tokens
# keystone = client.Client(username=username, password=password, tenant_name=tenant_name, auth_url=auth_url)
keystone = client.Client(username=username, password=password, auth_url=auth_url)
token = keystone.auth_token
headers = {'X-Auth-Token': token }
tenant_url = auth_url
tenant_url += '/tenants'
r = requests.get(tenant_url, headers=headers)
tenants_raw = r.raw.read(900000)
tenant_data = json.loads(tenants_raw)
success = 0