forked from arainho/openstack-manage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd-users-2-tenant
More file actions
executable file
·48 lines (33 loc) · 901 Bytes
/
add-users-2-tenant
File metadata and controls
executable file
·48 lines (33 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# VARs
USER_ID=""
TENANT_ID=""
USER_NAME=""
TENANT_NAME=""
ROLE_NAME=" _member_"
# LOGIN as admin
#source /root/admin-openrc.sh
echo 'enter tenant name'
read -r TENANT_NAME
echo 'enter users separated by space, to add them to ${TENANT_NAME}'
read -r USER_NAME
# CHECK tenant
TENANT_ID=$(keystone tenant-list | grep ${TENANT_NAME} | awk '{print $2}')
keystone tenant-get $TENANT_ID > /dev/null 2>&1
if [[ $? -eq 0 ]]; then
echo "tenant $TENANT_NAME exits :-)"
else
echo ' ALERT ... tenant not found !'
echo ''
exit
fi
echo ''
for myuser in ${USER_NAME[@]}
do
# FIND user ID
USER_ID=$(keystone user-list | grep ${myuser} | awk '{print $2}')
# ASSIGN a role to a user-tenant pair.
keystone user-role-add --user ${myuser} --tenant ${TENANT_ID} --role ${ROLE_NAME}
# Verify the role assignment:
keystone user-role-list --user ${myuser} --tenant ${TENANT_ID}
done