Reputation: 10962
I am using openstack
keystoneclient api v3
with python bindings
What is the way to add an existing user to a project with certain role.
Upvotes: 1
Views: 853
Reputation: 264
You can add a user to a project with a role as below:
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)
Reference link - https://docs.openstack.org/python-keystoneclient/latest/api/keystoneclient.v3.html#module-keystoneclient.v3.roles
Upvotes: 4