Oleksandr Savatieiev | 91355c8 | 2018-09-07 12:14:34 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | export OS_INTERFACE='admin' |
Ievgeniia Zadorozhna | 6d6cb29 | 2022-01-11 17:26:48 +0300 | [diff] [blame] | 3 | mask='rally_\|tempest_\|tempest-\|spt-' |
Oleksandr Savatieiev | 91355c8 | 2018-09-07 12:14:34 +0200 | [diff] [blame] | 4 | |
| 5 | echo "Starting. Using mask '$mask'" |
| 6 | |
| 7 | echo "Delete users" |
| 8 | for i in `openstack user list | grep $mask | awk '{print $2}'`; do openstack user delete $i; echo deleted $i; done |
| 9 | |
| 10 | echo "Delete roles" |
| 11 | for i in `openstack role list | grep $mask | awk '{print $2}'`; do openstack role delete $i; echo deleted $i; done |
| 12 | |
| 13 | #echo "Delete projects" |
| 14 | #for i in `openstack project list | grep $mask | awk '{print $2}'`; do openstack project delete $i; echo deleted $i; done |
| 15 | |
| 16 | echo "Delete servers" |
| 17 | for i in `openstack server list --all | grep $mask | awk '{print $2}'`; do openstack server delete $i; echo deleted $i; done |
| 18 | |
| 19 | echo "Reset snapshot state and delete" |
| 20 | for i in `openstack volume snapshot list --all | grep $mask | awk '{print $2}'`; do openstack snapshot set --state available $i; echo snapshot reset state is done for $i; done |
| 21 | for i in `openstack volume snapshot list --all | grep $mask | awk '{print $2}'`; do openstack snapshot set --state available $i; echo deleted $i; done |
| 22 | |
| 23 | echo "Reset volume state and delete" |
| 24 | for i in `openstack volume list --all | grep $mask | awk '{print $2}'`; do openstack volume set --state available $i; echo reset state is done for $i; done |
| 25 | for i in `openstack volume list --all | grep $mask | awk '{print $2}'`; do openstack volume delete $i; echo deleted $i; done |
| 26 | |
| 27 | echo "Delete volume types" |
| 28 | for i in `openstack volume type list | grep $mask | awk '{print $2}'`; do openstack volume type delete $i; done |
| 29 | |
| 30 | echo "Delete images" |
| 31 | for i in `openstack image list | grep $mask | awk '{print $2}'`; do openstack image delete $i; echo deleted $i; done |
| 32 | |
| 33 | echo "Delete sec groups" |
| 34 | for i in `openstack security group list --all | grep $mask | awk '{print $2}'`; do openstack security group delete $i; echo deleted $i; done |
| 35 | |
| 36 | echo "Delete keypairs" |
| 37 | for i in `openstack keypair list | grep $mask | awk '{print $2}'`; do openstack keypair delete $i; echo deleted $i; done |
| 38 | |
| 39 | echo "Delete ports" |
| 40 | for i in `openstack port list | grep $mask | awk '{print $2}'`; do openstack port delete $i; done |
| 41 | |
| 42 | echo "Delete Router ports (experimental)" |
| 43 | neutron router-list|grep $mask|awk '{print $2}'|while read line; do echo $line; neutron router-port-list $line|grep subnet_id|awk '{print $11}'|sed 's/^\"//;s/\",//'|while read interface; do neutron router-interface-delete $line $interface; done; done |
| 44 | |
| 45 | echo "Delete subnets" |
| 46 | for i in `openstack subnet list | grep $mask | awk '{print $2}'`; do openstack subnet delete $i; done |
| 47 | |
| 48 | echo "Delete nets" |
| 49 | for i in `openstack network list | grep $mask | awk '{print $2}'`; do openstack network delete $i; done |
| 50 | |
| 51 | echo "Delete routers" |
| 52 | for i in `openstack router list | grep $mask | awk '{print $2}'`; do openstack router delete $i; done |
| 53 | |
| 54 | echo "Delete regions" |
| 55 | for i in `openstack region list | grep $mask | awk '{print $2}'`; do openstack region delete $i; echo deleted $i; done |
| 56 | |
| 57 | echo "Delete stacks" |
| 58 | for i in `openstack stack list | grep $mask | awk '{print $2}'`; do openstack stack check $i; done |
| 59 | for i in `openstack stack list | grep $mask | awk '{print $2}'`; do openstack stack delete -y $i; echo deleted $i; done |
| 60 | |
| 61 | #echo "Delete containers" |
| 62 | #for i in `openstack container list --all | grep $mask | awk '{print $2}'`; do openstack container delete $i; echo deleted $i; done |
| 63 | echo "Done" |
| 64 | |
| 65 | # It is not recommended to remove projects until you are sure that there are no other leftovers. |
| 66 | #echo "Delete projects" |
| 67 | #for i in `openstack project list | grep $mask | awk '{print $2}'`; do openstack project delete $i; echo deleted $i; done |