40ae6edd9829a47cf316ba67ce734ee447a333b8
[apex.git] / ci / clean.sh
1 #!/usr/bin/env bash
2 ##############################################################################
3 # Copyright (c) 2015 Tim Rozet (Red Hat), Dan Radez (Red Hat) and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 #Clean script to uninstall provisioning server for Apex
12 #author: Dan Radez (dradez@redhat.com)
13 #author: Tim Rozet (trozet@redhat.com)
14 CONFIG=/var/opt/opnfv
15
16 ##LIBRARIES
17 source $CONFIG/lib/common-functions.sh
18
19 vm_index=4
20 ovs_bridges="br-admin br-private br-public br-storage"
21
22 # Clean off instack/undercloud VM
23 for vm in instack undercloud; do
24     virsh destroy $vm 2> /dev/null || echo -n ''
25     virsh undefine $vm 2> /dev/null || echo -n ''
26     if ! virsh vol-delete ${vm}.qcow2 --pool default 2> /dev/null; then
27         if [ ! -e /var/lib/libvirt/images/${vm}.qcow2 ]; then
28         /usr/bin/touch /var/lib/libvirt/images/${vm}.qcow2
29         virsh vol-delete ${vm}.qcow2 --pool default
30         fi
31     fi
32 done
33
34 rm -f /var/lib/libvirt/images/undercloud.qcow2 2> /dev/null
35
36 # Clean off baremetal VMs in case they exist
37 for i in $(seq 0 $vm_index); do
38   virsh destroy baremetal$i 2> /dev/null || echo -n ''
39   virsh undefine baremetal$i 2> /dev/null || echo -n ''
40   /usr/bin/touch /var/lib/libvirt/images/baremetal${i}.qcow2
41   virsh vol-delete baremetal${i}.qcow2 --pool default 2> /dev/null
42   rm -f /var/lib/libvirt/images/baremetal${i}.qcow2 2> /dev/null
43 done
44
45 # Clean off created bridges
46 for bridge in ${ovs_bridges}; do
47   virsh net-destroy ${bridge} 2> /dev/null
48   virsh net-undefine ${bridge} 2> /dev/null
49   if detach_interface_from_ovs ${bridge} 2> /dev/null; then
50     ovs-vsctl del-br ${bridge} 2> /dev/null
51   fi
52 done
53
54 # clean pub keys from root's auth keys
55 sed -i '/stack@undercloud.localdomain/d' /root/.ssh/authorized_keys
56 sed -i '/virtual-power-key/d' /root/.ssh/authorized_keys
57
58
59 echo "Cleanup Completed"