如何使用python将用户添加到keystoneclient api v3中的openstack项目中

时间:2017-07-28 07:37:24

标签: python openstack

我正在使用$(Build.ArtifactStagingDirectory) keystoneclient api $(Build.BinariesDirectory)和python绑定 将现有用户添加到具有特定角色的项目的方式是什么。

1 个答案:

答案 0 :(得分:2)

您可以将用户添加到具有以下角色的项目中:

from keystoneauth1.identity import v3
from keystoneauth1 import session
from keystoneclient.v3 import client

# Admin credentials
AUTH_URL = 'http://192.0.0.10:35357/v3'
USER_ID = 'abd78a0b166e47eb8fe40381853f3d90'
PASSWORD = 'password'
PROJECT_ID = '5a56b817ec7342a9a6c0eea26f591621'

auth = v3.Password(auth_url=AUTH_URL,  user_id=USER_ID, password=PASSWORD, project_id=PROJECT_ID)
sess = session.Session(auth=auth)
keystone = client.Client(session=sess)


# User, role and project details
ROLE_ID = '7836dac8513745a6be2c9cf5df4640c9'
USER_ID = '7b96131d69b141be8d8d6749ef0e0168'
PROJECT_ID = '121088df9f364c8a92541f969c971b3e'

keystone.roles.grant(ROLE_ID, USER_ID, PROJECT_ID)

参考链接 - https://docs.openstack.org/python-keystoneclient/latest/api/keystoneclient.v3.html#module-keystoneclient.v3.roles