blob: 9792873764573bf40fdbb2ece8821387423fd3f7 [file] [log] [blame]
Oleksii Zhurba1580fc52017-11-14 15:20:44 -06001#!/bin/bash
Oleksii Zhurba1580fc52017-11-14 15:20:44 -06002export OS_INTERFACE='admin'
Oleksii Zhurba1580fc52017-11-14 15:20:44 -06003mask='rally_\|tempest_\|tempest-'
Oleksii Zhurba0aa46702018-02-07 16:17:39 -06004
Oleksii Zhurba1580fc52017-11-14 15:20:44 -06005echo "Starting. Using mask '$mask'"
Oleksii Zhurba0aa46702018-02-07 16:17:39 -06006
Oleksii Zhurba1580fc52017-11-14 15:20:44 -06007echo "Delete users"
8for i in `openstack user list | grep $mask | awk '{print $2}'`; do openstack user delete $i; echo deleted $i; done
Oleksii Zhurba0aa46702018-02-07 16:17:39 -06009
Oleksii Zhurba1580fc52017-11-14 15:20:44 -060010echo "Delete roles"
11for i in `openstack role list | grep $mask | awk '{print $2}'`; do openstack role delete $i; echo deleted $i; done
Oleksii Zhurba0aa46702018-02-07 16:17:39 -060012
Valentyn Khalinbdf3ba92018-07-13 18:14:20 +030013#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 Zhurba1580fc52017-11-14 15:20:44 -060016echo "Delete servers"
17for i in `openstack server list --all | grep $mask | awk '{print $2}'`; do openstack server delete $i; echo deleted $i; done
Oleksii Zhurba0aa46702018-02-07 16:17:39 -060018
Valentyn Khalinbdf3ba92018-07-13 18:14:20 +030019echo "Reset snapshot state and delete"
20for 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
21for i in `openstack volume snapshot list --all | grep $mask | awk '{print $2}'`; do openstack snapshot set --state available $i; echo deleted $i; done
Oleksii Zhurba0aa46702018-02-07 16:17:39 -060022
Valentyn Khalinbdf3ba92018-07-13 18:14:20 +030023echo "Reset volume state and delete"
24for 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 Zhurba1580fc52017-11-14 15:20:44 -060025for i in `openstack volume list --all | grep $mask | awk '{print $2}'`; do openstack volume delete $i; echo deleted $i; done
Oleksii Zhurba0aa46702018-02-07 16:17:39 -060026
Oleksii Zhurba1580fc52017-11-14 15:20:44 -060027echo "Delete volume types"
Valentyn Khalinbdf3ba92018-07-13 18:14:20 +030028for i in `openstack volume type list | grep $mask | awk '{print $2}'`; do openstack volume type delete $i; done
Oleksii Zhurba0aa46702018-02-07 16:17:39 -060029
Oleksii Zhurba1580fc52017-11-14 15:20:44 -060030echo "Delete images"
31for i in `openstack image list | grep $mask | awk '{print $2}'`; do openstack image delete $i; echo deleted $i; done
Oleksii Zhurba0aa46702018-02-07 16:17:39 -060032
Oleksii Zhurba1580fc52017-11-14 15:20:44 -060033echo "Delete sec groups"
34for i in `openstack security group list --all | grep $mask | awk '{print $2}'`; do openstack security group delete $i; echo deleted $i; done
Oleksii Zhurba0aa46702018-02-07 16:17:39 -060035
Oleksii Zhurba1580fc52017-11-14 15:20:44 -060036echo "Delete keypairs"
37for i in `openstack keypair list | grep $mask | awk '{print $2}'`; do openstack keypair delete $i; echo deleted $i; done
Oleksii Zhurba0aa46702018-02-07 16:17:39 -060038
Oleksii Zhurba1580fc52017-11-14 15:20:44 -060039echo "Delete ports"
Valentyn Khalinbdf3ba92018-07-13 18:14:20 +030040for i in `openstack port list | grep $mask | awk '{print $2}'`; do openstack port delete $i; done
Oleksii Zhurba0aa46702018-02-07 16:17:39 -060041
Oleksii Zhurba1580fc52017-11-14 15:20:44 -060042echo "Delete Router ports (experimental)"
43neutron 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 Zhurba0aa46702018-02-07 16:17:39 -060044
Oleksii Zhurba1580fc52017-11-14 15:20:44 -060045echo "Delete subnets"
Valentyn Khalinbdf3ba92018-07-13 18:14:20 +030046for i in `openstack subnet list | grep $mask | awk '{print $2}'`; do openstack subnet delete $i; done
Oleksii Zhurba0aa46702018-02-07 16:17:39 -060047
Oleksii Zhurba1580fc52017-11-14 15:20:44 -060048echo "Delete nets"
Valentyn Khalinbdf3ba92018-07-13 18:14:20 +030049for i in `openstack network list | grep $mask | awk '{print $2}'`; do openstack network delete $i; done
Oleksii Zhurba0aa46702018-02-07 16:17:39 -060050
Oleksii Zhurba1580fc52017-11-14 15:20:44 -060051echo "Delete routers"
Valentyn Khalinbdf3ba92018-07-13 18:14:20 +030052for i in `openstack router list | grep $mask | awk '{print $2}'`; do openstack router delete $i; done
Oleksii Zhurba0aa46702018-02-07 16:17:39 -060053
Oleksii Zhurba1580fc52017-11-14 15:20:44 -060054echo "Delete regions"
55for i in `openstack region list | grep $mask | awk '{print $2}'`; do openstack region delete $i; echo deleted $i; done
Oleksii Zhurba0aa46702018-02-07 16:17:39 -060056
Oleksii Zhurba1580fc52017-11-14 15:20:44 -060057echo "Delete stacks"
58for i in `openstack stack list | grep $mask | awk '{print $2}'`; do openstack stack check $i; done
59for i in `openstack stack list | grep $mask | awk '{print $2}'`; do openstack stack delete -y $i; echo deleted $i; done
Oleksii Zhurba0aa46702018-02-07 16:17:39 -060060
Oleksii Zhurba1580fc52017-11-14 15:20:44 -060061#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
63echo "Done"
Oleksii Zhurba0aa46702018-02-07 16:17:39 -060064
Oleksii Zhurba1580fc52017-11-14 15:20:44 -060065# 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