Skip to content

Instantly share code, notes, and snippets.

@freyes
Created March 21, 2019 19:56
Show Gist options
  • Save freyes/0253aac985cff492e218f7eff52bc582 to your computer and use it in GitHub Desktop.
Save freyes/0253aac985cff492e218f7eff52bc582 to your computer and use it in GitHub Desktop.
print number of instances running per project
#!/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