Merge "Add API network support"
[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
15 # Use default if no param passed
16 CONFIG=${CONFIG:-'/var/opt/opnfv'}
17 RESOURCES=${RESOURCES:-"$CONFIG/images"}
18 LIB=${LIB:-"$CONFIG/lib"}
19
20 ##LIBRARIES
21 if ! source $LIB/common-functions.sh; then
22   echo "Failed to source $LIB/common-functions.sh"
23   exit 1
24 fi
25
26 vm_index=4
27 ovs_bridges="br-admin br-private br-public br-storage"
28 OPNFV_NETWORK_TYPES="admin_network private_network public_network storage_network api_network"
29
30 # Clean off instack/undercloud VM
31 for vm in instack undercloud; do
32   virsh destroy $vm 2> /dev/null | xargs echo -n
33   virsh undefine $vm 2> /dev/null | xargs echo -n
34   /usr/bin/touch /var/lib/libvirt/images/${vm}.qcow2
35   virsh vol-delete ${vm}.qcow2 --pool default 2> /dev/null | xargs echo -n
36   rm -f /var/lib/libvirt/images/${vm}.qcow2 2> /dev/null
37 done
38
39 # Clean off baremetal VMs in case they exist
40 for i in $(seq 0 $vm_index); do
41   virsh destroy baremetal$i 2> /dev/null | xargs echo -n
42   virsh undefine baremetal$i 2> /dev/null | xargs echo -n
43   /usr/bin/touch /var/lib/libvirt/images/baremetal${i}.qcow2
44   virsh vol-delete baremetal${i}.qcow2 --pool default 2> /dev/null | xargs echo -n
45   rm -f /var/lib/libvirt/images/baremetal${i}.qcow2 2> /dev/null
46 done
47
48 for network in ${OPNFV_NETWORK_TYPES}; do
49   virsh net-destroy ${network} 2> /dev/null
50   virsh net-undefine ${network} 2> /dev/null
51 done
52
53 # Clean off created bridges
54 for bridge in ${ovs_bridges}; do
55   if detach_interface_from_ovs ${bridge} 2> /dev/null; then
56     ovs-vsctl del-br ${bridge} 2> /dev/null
57     rm -f /etc/sysconfig/network-scripts/ifcfg-${bridge}
58   fi
59 done
60
61 # clean pub keys from root's auth keys
62 sed -i '/stack@undercloud.localdomain/d' /root/.ssh/authorized_keys
63 sed -i '/virtual-power-key/d' /root/.ssh/authorized_keys
64
65
66 # force storage cleanup
67 virsh pool-refresh default
68
69 # remove temporary files
70 rm -f /tmp/network-environment.yaml
71
72 echo "Cleanup Completed"