summaryrefslogtreecommitdiffstats
path: root/ci/clean.sh
blob: 4cf6b64a7f4c960c335ceae4e36561851e1c083a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
##############################################################################
# Copyright (c) 2015 Tim Rozet (Red Hat), Dan Radez (Red Hat) and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

#Clean script to uninstall provisioning server for Apex
#author: Dan Radez (dradez@redhat.com)
#author: Tim Rozet (trozet@redhat.com)

# Use default if no param passed
CONFIG=${CONFIG:-'/var/opt/opnfv'}
RESOURCES=${RESOURCES:-"$CONFIG/images"}
LIB=${LIB:-"$CONFIG/lib"}

##LIBRARIES
if ! source $LIB/common-functions.sh; then
  echo "Failed to source $LIB/common-functions.sh"
  exit 1
fi

vm_index=4
ovs_bridges="br-admin br-private br-public br-storage"
OPNFV_NETWORK_TYPES="admin_network private_network public_network storage_network api_network"

# Clean off instack/undercloud VM
for vm in instack undercloud; do
  virsh destroy $vm 2> /dev/null | xargs echo -n
  virsh undefine $vm 2> /dev/null | xargs echo -n
  /usr/bin/touch /var/lib/libvirt/images/${vm}.qcow2
  virsh vol-delete ${vm}.qcow2 --pool default 2> /dev/null | xargs echo -n
  rm -f /var/lib/libvirt/images/${vm}.qcow2 2> /dev/null
done

# Clean off baremetal VMs in case they exist
for i in $(seq 0 $vm_index); do
  virsh destroy baremetal$i 2> /dev/null | xargs echo -n
  virsh undefine baremetal$i 2> /dev/null | xargs echo -n
  /usr/bin/touch /var/lib/libvirt/images/baremetal${i}.qcow2
  virsh vol-delete baremetal${i}.qcow2 --pool default 2> /dev/null | xargs echo -n
  rm -f /var/lib/libvirt/images/baremetal${i}.qcow2 2> /dev/null
done

for network in ${OPNFV_NETWORK_TYPES}; do
  virsh net-destroy ${network} 2> /dev/null
  virsh net-undefine ${network} 2> /dev/null
done

# Clean off created bridges
for bridge in ${ovs_bridges}; do
  if detach_interface_from_ovs ${bridge} 2> /dev/null; then
    ovs-vsctl del-br ${bridge} 2> /dev/null
    rm -f /etc/sysconfig/network-scripts/ifcfg-${bridge}
  fi
done

# clean pub keys from root's auth keys
sed -i '/stack@undercloud.localdomain/d' /root/.ssh/authorized_keys
sed -i '/virtual-power-key/d' /root/.ssh/authorized_keys


# force storage cleanup
virsh pool-refresh default

# remove temporary files
rm -f /tmp/network-environment.yaml

echo "Cleanup Completed"