Keystone客户端项目列表不显示所有项目

时间:2016-06-06 03:25:49

标签: openstack keystone

我正在尝试列出我设置中存在的所有keystone项目。我使用的代码段只显示其中的一小部分。

CODE-1:

from keystoneclient.auth.identity import v3
from keystoneclient import session
from keystoneclient.v3 import client as ksclient3
auth_url = "http://192.16.66.10:5000/v3"
token = '0112efcb75e9411b965b423edb321827'
auth = v3.Token(auth_url=auth_url, token=token, unscoped=True)
sess = session.Session(auth=auth)
ks = ksclient3.Client(session=sess);
project_list = [t.name for t in ks.projects.list(user=sess.get_user_id())]
print project_list

输出

[A', B', C']

CODE-2

from keystoneclient import session
from keystoneclient.v3 import client
from keystoneclient.auth.identity import v3
auth = v3.Password(auth_url='http://127.0.0.1:5000/v3',user_id='idm',password='idm',project_id='2545070293684905b9623095768b019d')
sess = session.Session(auth=auth)
keystone = client.Client(session=sess)
keystone.users.list()

输出

keystoneclient.exceptions.Unauthorized: The request you have made requires authentication. (HTTP 401)

预期输出

openstack project list
+----------------------------------+----------------+
| ID                               | Name           |
+----------------------------------+----------------+
| 3efabc809570458180b2e20ce099ef1a | A        |
| 546636e4532246f9a440e44deaad82d6 | B |
| 63494b0b0e164e7e82281c94efc709e4 | C         |
| 71dbcec67a3e49979a9a9f519409785d | D   |
| 8699a715c6834ac1a42350e593879695 | E   |
| af88b7d76ab44e13ba73b80b39d2644b | F          |
| b431f905a52448298980a0fe0b7751be | G           |
| ba3053eb5c534052914f133aa065865d | H       |
+----------------------------------+----------------+

我想了解的事情:

  • 为什么CODE-1在列表中显示少数
  • 为什么CODE-2失败
  • 如何从keystone客户端获取 keystone项目IDS

1 个答案:

答案 0 :(得分:1)

  

为什么CODE-1在列表中显示少数

如果您希望所有租户列表都不按以下方式过滤,您的代码会对租户进行过滤:

ks.projects.list()

您的过滤器" user = sess.get_user_id()"返回当前用户创建的所有租户。

  

为什么CODE-2失败

我认为错误是在args中,你给user_id =' idm',如果你使用用户名,那么参数应该是username =' idm',如果你传入arg user_id,那么你需要传递用户ID,例如user_id =' 56d88dd0a3ab4c4c8d1d15534352d7de'

你可以从地平线中获取id http://localhost/horizon/identity/users/

在源代码中有客户端创建的示例:

    from keystoneauth1.identity import v3
    from keystoneauth1 import session
    from keystoneclient.v3 import client
    auth = v3.Password(user_domain_name=DOMAIN_NAME,
                        username=USER,
                        password=PASS,
                        project_domain_name=PROJECT_DOMAIN_NAME,
                        project_name=PROJECT_NAME,
                        auth_url=KEYSTONE_URL)
    sess = session.Session(auth=auth)
    keystone = client.Client(session=sess)
    keystone.projects.list()

    user = keystone.users.get(USER_ID)
    user.delete()
  

如何从keystone客户端获取keystone项目IDS

如果您想查看所有租户ID(假设管理员凭据)

project_list = [proj.id for proj in ks.projects.list(all_tenants=True)]