-
Notifications
You must be signed in to change notification settings - Fork 9
/
report-user-quotas.sh
executable file
·38 lines (33 loc) · 1.23 KB
/
report-user-quotas.sh
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
#!/bin/bash
#
# Report quotas for all users or a single user in a tenant
#
# Arguments: tenant [username]
#
# Author: Steven Nemetz
# snemetz@hotmail.com
openstack_env='/root/keystonerc_admin'
tenant_name=$1
user_name=$2
if [ -z "$tenant_name" ]; then
echo "Usage: $0 <Tenant name> [<user name>]"
exit 1
fi
source $openstack_env
tenant_id=$(keystone tenant-list | grep $tenant_name | awk '{ print $2 }')
if [ -n "$user_name" ]; then
# Get user quotas
user_id=$(keystone user-list | grep " ${user_name} " | awk '{ print $2 }')
nova quota-show --tenant $tenant_id --user $user_id
else
# Get quotas for all users in tenant
while read bar uuid bar2 name rest; do
if [ -n "$(keystone user-role-list --user ${uuid} --tenant $tenant_id | grep 'Member')" ]; then
user_quota=$(nova quota-show --user ${uuid} --tenant $tenant_id)
cores=$(echo "$user_quota" | grep cores | awk '{print $4}')
ram=$(echo "$user_quota" | grep ram | awk '{print $4}')
instances=$(echo "$user_quota" | grep instances | awk '{print $4}')
echo "User ${name} is setup with the following quotas (cores=${cores}, ram=${ram}, instances=${instances} )"
fi
done < <(keystone user-list --tenant-id $tenant_id | sort -k4 -u | grep 'True')
fi