Oleksii Zhurba | 1580fc5 | 2017-11-14 15:20:44 -0600 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | #mask='rally_' |
| 3 | #mask='tempest' |
| 4 | export OS_ENDPOINT_TYPE=internal |
| 5 | #export OS_ENDPOINT_TYPE='adminURL' |
| 6 | export OS_INTERFACE='admin' |
| 7 | #export OS_INSECURE=True |
| 8 | mask='rally_\|tempest_\|tempest-' |
| 9 | echo "Starting. Using mask '$mask'" |
| 10 | echo "Delete users" |
| 11 | for i in `openstack user list | grep $mask | awk '{print $2}'`; do openstack user delete $i; echo deleted $i; done |
| 12 | echo "Delete roles" |
| 13 | for i in `openstack role list | grep $mask | awk '{print $2}'`; do openstack role delete $i; echo deleted $i; done |
| 14 | echo "Delete servers" |
| 15 | for i in `openstack server list --all | grep $mask | awk '{print $2}'`; do openstack server delete $i; echo deleted $i; done |
| 16 | echo "Delete snapshot" |
| 17 | #[--force] |
| 18 | for i in `cinder snapshot-list --all | grep $mask | awk '{print $2}'`; do cinder snapshot-reset-state $i; echo snapshot reset state is done for $i; done |
| 19 | for i in `cinder snapshot-list --all | grep $mask | awk '{print $2}'`; do cinder snapshot-delete $i; echo deleted $i; done |
| 20 | echo "Delete volumes" |
| 21 | for i in `openstack volume list --all | grep $mask | awk '{print $2}'`; do cinder reset-state $i --state available; echo reset state is done for $i; done |
| 22 | for i in `openstack volume list --all | grep $mask | awk '{print $2}'`; do openstack volume delete $i; echo deleted $i; done |
| 23 | echo "Delete volume types" |
| 24 | for i in `cinder type-list | grep $mask | awk '{print $2}'`; do cinder type-delete $i; done |
| 25 | echo "Delete images" |
| 26 | for i in `openstack image list | grep $mask | awk '{print $2}'`; do openstack image delete $i; echo deleted $i; done |
| 27 | echo "Delete sec groups" |
| 28 | for i in `openstack security group list --all | grep $mask | awk '{print $2}'`; do openstack security group delete $i; echo deleted $i; done |
| 29 | echo "Delete keypairs" |
| 30 | for i in `openstack keypair list | grep $mask | awk '{print $2}'`; do openstack keypair delete $i; echo deleted $i; done |
| 31 | echo "Delete ports" |
| 32 | for i in `neutron port-list --all | grep $mask | awk '{print $2}'`; do neutron port-delete $i; done |
| 33 | echo "Delete Router ports (experimental)" |
| 34 | 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 |
| 35 | echo "Delete subnets" |
| 36 | for i in `neutron subnet-list --all | grep $mask | awk '{print $2}'`; do neutron subnet-delete $i; done |
| 37 | echo "Delete nets" |
| 38 | for i in `neutron net-list --all | grep $mask | awk '{print $2}'`; do neutron net-delete $i; done |
| 39 | echo "Delete routers" |
| 40 | for i in `neutron router-list --all | grep $mask | awk '{print $2}'`; do neutron router-delete $i; done |
| 41 | echo "Delete regions" |
| 42 | for i in `openstack region list | grep $mask | awk '{print $2}'`; do openstack region delete $i; echo deleted $i; done |
| 43 | echo "Delete stacks" |
| 44 | for i in `openstack stack list | grep $mask | awk '{print $2}'`; do openstack stack check $i; done |
| 45 | for i in `openstack stack list | grep $mask | awk '{print $2}'`; do openstack stack delete -y $i; echo deleted $i; done |
| 46 | #echo "Delete containers" |
| 47 | #for i in `openstack container list --all | grep $mask | awk '{print $2}'`; do openstack container delete $i; echo deleted $i; done |
| 48 | echo "Done" |
| 49 | # It is not recommended to remove projects until you are sure that there are no other leftovers. |
| 50 | #echo "Delete projects" |
| 51 | #for i in `openstack project list | grep $mask | awk '{print $2}'`; do openstack project delete $i; echo deleted $i; done |