forked from ntnusky/admintools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-compute-contacts.sh
executable file
·46 lines (39 loc) · 1.35 KB
/
get-compute-contacts.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
38
39
40
41
42
43
44
45
46
#!/bin/bash
if [[ $# -lt 1 ]]; then
echo "Usage: $0 <compute-host>"
exit 1
fi
host=$1
projects=()
echo "For each server, get the project ID" >&2
for server in $(openstack server list --all --host $host -f value -c ID); do
project=$(openstack server show $server -f value -c project_id)
projects=($project ${projects[@]})
echo -n '#' >&2
done
echo >&2
users=()
groups=()
echo "Retrieving usernames and groups affected" >&2
for project in $(echo ${projects[@]} | tr ' ' '\n' | sort | uniq); do
for member in $(openstack role assignment list --project $project --names --role member -f value -c User -c Group | grep NTNU | cut -f 1 -d '@'); do
if [[ $member =~ _ ]]; then # A group will always contain an underscore. Usernames will never have one
groups=($member ${groups[@]})
else
users=($member ${users[@]})
fi
done
echo -n '#' >&2
done
echo >&2
echo "Fetching usernames from groups..."
for group in $(echo ${groups[@]} | tr ' ' '\n' | sort | uniq); do
members="$(ldapsearch -LLL -x -H ldaps://at.ntnu.no -b "ou=Groups,dc=ntnu,dc=no" cn="$group" memberUid | grep memberUid | awk '{print $2}' | tr '\n' ' ')"
users=($members ${users[@]})
done
echo "Retrieving emails" >&2
for user in $(echo ${users[@]} | tr ' ' '\n' | sort | uniq); do
openstack user show --domain NTNU $user -f value -c email
echo -n '' >&2
done
echo >&2