Oleksii Zhurba | 1580fc5 | 2017-11-14 15:20:44 -0600 | [diff] [blame] | 1 | #!/bin/bash |
Oleksii Zhurba | 1580fc5 | 2017-11-14 15:20:44 -0600 | [diff] [blame] | 2 | export OS_INTERFACE='admin' |
Oleksii Zhurba | 1580fc5 | 2017-11-14 15:20:44 -0600 | [diff] [blame] | 3 | mask='rally_\|tempest_\|tempest-' |
Oleksii Zhurba | 0aa4670 | 2018-02-07 16:17:39 -0600 | [diff] [blame] | 4 | |
Oleksii Zhurba | 1580fc5 | 2017-11-14 15:20:44 -0600 | [diff] [blame] | 5 | echo "Starting. Using mask '$mask'" |
Oleksii Zhurba | 0aa4670 | 2018-02-07 16:17:39 -0600 | [diff] [blame] | 6 | |
Oleksii Zhurba | 1580fc5 | 2017-11-14 15:20:44 -0600 | [diff] [blame] | 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 |
Oleksii Zhurba | 0aa4670 | 2018-02-07 16:17:39 -0600 | [diff] [blame] | 9 | |
Oleksii Zhurba | 1580fc5 | 2017-11-14 15:20:44 -0600 | [diff] [blame] | 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 |
Oleksii Zhurba | 0aa4670 | 2018-02-07 16:17:39 -0600 | [diff] [blame] | 12 | |
Valentyn Khalin | bdf3ba9 | 2018-07-13 18:14:20 +0300 | [diff] [blame] | 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 | |
Oleksii Zhurba | 1580fc5 | 2017-11-14 15:20:44 -0600 | [diff] [blame] | 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 |
Oleksii Zhurba | 0aa4670 | 2018-02-07 16:17:39 -0600 | [diff] [blame] | 18 | |
Valentyn Khalin | bdf3ba9 | 2018-07-13 18:14:20 +0300 | [diff] [blame] | 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 |
Oleksii Zhurba | 0aa4670 | 2018-02-07 16:17:39 -0600 | [diff] [blame] | 22 | |
Valentyn Khalin | bdf3ba9 | 2018-07-13 18:14:20 +0300 | [diff] [blame] | 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 |
Oleksii Zhurba | 1580fc5 | 2017-11-14 15:20:44 -0600 | [diff] [blame] | 25 | for i in `openstack volume list --all | grep $mask | awk '{print $2}'`; do openstack volume delete $i; echo deleted $i; done |
Oleksii Zhurba | 0aa4670 | 2018-02-07 16:17:39 -0600 | [diff] [blame] | 26 | |
Oleksii Zhurba | 1580fc5 | 2017-11-14 15:20:44 -0600 | [diff] [blame] | 27 | echo "Delete volume types" |
Valentyn Khalin | bdf3ba9 | 2018-07-13 18:14:20 +0300 | [diff] [blame] | 28 | for i in `openstack volume type list | grep $mask | awk '{print $2}'`; do openstack volume type delete $i; done |
Oleksii Zhurba | 0aa4670 | 2018-02-07 16:17:39 -0600 | [diff] [blame] | 29 | |
Oleksii Zhurba | 1580fc5 | 2017-11-14 15:20:44 -0600 | [diff] [blame] | 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 |
Oleksii Zhurba | 0aa4670 | 2018-02-07 16:17:39 -0600 | [diff] [blame] | 32 | |
Oleksii Zhurba | 1580fc5 | 2017-11-14 15:20:44 -0600 | [diff] [blame] | 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 |
Oleksii Zhurba | 0aa4670 | 2018-02-07 16:17:39 -0600 | [diff] [blame] | 35 | |
Oleksii Zhurba | 1580fc5 | 2017-11-14 15:20:44 -0600 | [diff] [blame] | 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 |
Oleksii Zhurba | 0aa4670 | 2018-02-07 16:17:39 -0600 | [diff] [blame] | 38 | |
Oleksii Zhurba | 1580fc5 | 2017-11-14 15:20:44 -0600 | [diff] [blame] | 39 | echo "Delete ports" |
Valentyn Khalin | bdf3ba9 | 2018-07-13 18:14:20 +0300 | [diff] [blame] | 40 | for i in `openstack port list | grep $mask | awk '{print $2}'`; do openstack port delete $i; done |
Oleksii Zhurba | 0aa4670 | 2018-02-07 16:17:39 -0600 | [diff] [blame] | 41 | |
Oleksii Zhurba | 1580fc5 | 2017-11-14 15:20:44 -0600 | [diff] [blame] | 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 |
Oleksii Zhurba | 0aa4670 | 2018-02-07 16:17:39 -0600 | [diff] [blame] | 44 | |
Oleksii Zhurba | 1580fc5 | 2017-11-14 15:20:44 -0600 | [diff] [blame] | 45 | echo "Delete subnets" |
Valentyn Khalin | bdf3ba9 | 2018-07-13 18:14:20 +0300 | [diff] [blame] | 46 | for i in `openstack subnet list | grep $mask | awk '{print $2}'`; do openstack subnet delete $i; done |
Oleksii Zhurba | 0aa4670 | 2018-02-07 16:17:39 -0600 | [diff] [blame] | 47 | |
Oleksii Zhurba | 1580fc5 | 2017-11-14 15:20:44 -0600 | [diff] [blame] | 48 | echo "Delete nets" |
Valentyn Khalin | bdf3ba9 | 2018-07-13 18:14:20 +0300 | [diff] [blame] | 49 | for i in `openstack network list | grep $mask | awk '{print $2}'`; do openstack network delete $i; done |
Oleksii Zhurba | 0aa4670 | 2018-02-07 16:17:39 -0600 | [diff] [blame] | 50 | |
Oleksii Zhurba | 1580fc5 | 2017-11-14 15:20:44 -0600 | [diff] [blame] | 51 | echo "Delete routers" |
Valentyn Khalin | bdf3ba9 | 2018-07-13 18:14:20 +0300 | [diff] [blame] | 52 | for i in `openstack router list | grep $mask | awk '{print $2}'`; do openstack router delete $i; done |
Oleksii Zhurba | 0aa4670 | 2018-02-07 16:17:39 -0600 | [diff] [blame] | 53 | |
Oleksii Zhurba | 1580fc5 | 2017-11-14 15:20:44 -0600 | [diff] [blame] | 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 |
Oleksii Zhurba | 0aa4670 | 2018-02-07 16:17:39 -0600 | [diff] [blame] | 56 | |
Oleksii Zhurba | 1580fc5 | 2017-11-14 15:20:44 -0600 | [diff] [blame] | 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 |
Oleksii Zhurba | 0aa4670 | 2018-02-07 16:17:39 -0600 | [diff] [blame] | 60 | |
Oleksii Zhurba | 1580fc5 | 2017-11-14 15:20:44 -0600 | [diff] [blame] | 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" |
Oleksii Zhurba | 0aa4670 | 2018-02-07 16:17:39 -0600 | [diff] [blame] | 64 | |
Oleksii Zhurba | 1580fc5 | 2017-11-14 15:20:44 -0600 | [diff] [blame] | 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 |