Created
March 21, 2019 19:56
-
-
Save freyes/0253aac985cff492e218f7eff52bc582 to your computer and use it in GitHub Desktop.
print number of instances running per project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
TOTAL_INSTANCES=0 | |
TMPFILE=`mktemp` | |
nova list --fields tenant_id --all-tenants | tail -n +4 | head -n -2 | cut -d'|' -f3 | tr -d ' ' | sort | uniq -c | sort -n | while read -r LINE; do | |
TENANT_ID=$(echo $LINE | awk -F' ' '{print $2}') | |
TENANT_NAME=$(openstack project show -c name -f value $TENANT_ID) | |
NUM_INSTANCES=$(echo $LINE | awk -F' ' '{print $1}') | |
echo "$NUM_INSTANCES $TENANT_NAME" | |
TOTAL_INSTANCES=$(($TOTAL_INSTANCES+$NUM_INSTANCES)) | |
echo $TOTAL_INSTANCES > $TMPFILE | |
done | |
echo "Total: $(cat $TMPFILE)" | |
rm $TMPFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment