Created
April 21, 2021 01:15
-
-
Save flannon/b9d2fb798d2d7939c4e63e06bdf53da0 to your computer and use it in GitHub Desktop.
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 | |
set -euo pipefail | |
DOMAIN="<domain name>" | |
LOG=./osp_project_resources.log | |
list_resources () { | |
OIFS=$IFS | |
IFS=$'\n' | |
local resources=( $(openstack project purge --project $1 --dry-run 2>&1 | awk -F "[[:space:]]" -v name=$1 '{one = $1; $1 = ""; print name, $0, first; }') ) | |
IFS=${OIFS} | |
for i in "${resources[@]}"; do | |
printf "${i}" | awk -v name=$1 -v id=$2 '$2 == "server" { $1 = ""; printf "%s%s%-10s%s%s %s%s %s\n", ",", ",", name, $1, ",", $2, ",", $4; }' >> $LOG | |
printf "${i}" | awk -v name=$1 -v id=$2 '$2 == "image" { $1 = ""; printf "%s%s%-10s%s%s %s%s %s\n", ",", ",", name, $1, ",", $2, ",", $4; }' >>$LOG | |
printf "${i}" | awk -v name=$1 -v id=$2 '($2 == "volume") && ($3 != "snapshot") { $1 = ""; printf "%s%s%-10s%s%s %s%s %s\n", ",", ",", name, $1, ",",$2, ",", $4; }' >> $LOG | |
printf "${i}" | awk -v name=$1 -v id=$2 '($2 == "volume") && ($3 == "snapshot") { $1 = ""; printf "%s%s%-10s%s%s %s%s%s%s %s\n", ",", ",", name, $1, ",", $2, "-", $3, ",", $5; }' >> $LOG | |
printf "${i}" | awk -v name=$1 -v id=$2 'id == $3 { $1 = ""; printf "%s%s%-10s%s%s %s\n", ",", ",", name, $2, ",", $3; }' >> $LOG | |
done | |
} | |
get_projects () { | |
local count=0 | |
local id=undef | |
local name=undef | |
printf "'Name', 'Project_ID', 'Project_name', 'Type', 'ID'" > $LOG | |
for i in $(openstack project list --domain $DOMAIN -f value); do | |
[[ $(( $count % 2 )) -eq 0 ]] && id="$i" || name="$i" | |
[[ $name != "undef" ]] && [[ $id != "undef" ]] && printf "%-30s%33s\n" $name $id >> $LOG | |
[[ $name != "undef" ]] && [[ $id != "undef" ]] && list_resources $name $id && name=undef id=undef | |
let "count=count+1" | |
done | |
} | |
get_projects |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment