2 ##############################################################################
3 # Copyright (c) 2015 Tim Rozet (Red Hat), Dan Radez (Red Hat) and others.
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 ##############################################################################
11 #Clean script to uninstall provisioning server for Apex
12 #author: Dan Radez (dradez@redhat.com)
13 #author: Tim Rozet (trozet@redhat.com)
15 # Use default if no param passed
16 CONFIG=${CONFIG:-'/var/opt/opnfv'}
17 RESOURCES=${RESOURCES:-"$CONFIG/images"}
18 LIB=${LIB:-"$CONFIG/lib"}
19 reset=$(tput sgr0 || echo "")
20 blue=$(tput setaf 4 || echo "")
21 red=$(tput setaf 1 || echo "")
22 green=$(tput setaf 2 || echo "")
25 for lib in common-functions parse-functions; do
26 if ! source $LIB/${lib}.sh; then
27 echo "Failed to source $LIB/${lib}.sh"
33 ovs_bridges="br-admin br-tenant br-public br-storage"
34 ovs_bridges+=" br-private br-external" # Legecy names, remove in E river
36 #OPNFV_NETWORK_TYPES=$(python3 -c 'from apex.common.constants import OPNFV_NETWORK_TYPES; print(" ".join(OPNFV_NETWORK_TYPES))')
37 OPNFV_NETWORK_TYPES+=" admin tenant external storage api"
38 OPNFV_NETWORK_TYPES+=" admin_network private_network public_network storage_network api_network" # Legecy names, remove in E river
42 echo -e "Usage:\n$0 [arguments] \n"
43 echo -e " -i|--inventory : Full path to inventory yaml file. Required only for baremetal node clean"
46 ##translates the command line parameters into variables
47 ##params: $@ the entire command line is passed
48 ##usage: parse_cmd_line() "$@"
50 echo -e "\n\n${blue}This script is used to deploy the Apex Installer and Provision OPNFV Target System${reset}\n\n"
51 echo "Use -h to display help"
54 while [ "${1:0:1}" = "-" ]
72 if [[ ! -z "$INVENTORY_FILE" && ! -f "$INVENTORY_FILE" ]]; then
73 echo -e "{$red}ERROR: Inventory File: ${INVENTORY_FILE} does not exist! Exiting...${reset}"
80 if [ -n "$INVENTORY_FILE" ]; then
81 echo -e "${blue}INFO: Parsing inventory file...${reset}"
82 if ! python3 -B $LIB/python/apex_python_utils.py clean -f ${INVENTORY_FILE}; then
83 echo -e "${red}WARN: Unable to shutdown all nodes! Please check /var/log/apex.log${reset}"
85 echo -e "${blue}INFO: Node shutdown complete...${reset}"
89 # Clean off instack/undercloud VM
90 for vm in instack undercloud; do
91 virsh destroy $vm 2> /dev/null | xargs echo -n
92 virsh undefine $vm 2> /dev/null | xargs echo -n
93 /usr/bin/touch /var/lib/libvirt/images/${vm}.qcow2
94 virsh vol-delete ${vm}.qcow2 --pool default 2> /dev/null | xargs echo -n
95 rm -f /var/lib/libvirt/images/${vm}.qcow2 2> /dev/null
98 # Clean off baremetal VMs in case they exist
99 for i in $(seq 0 $vm_index); do
100 virsh destroy baremetal$i 2> /dev/null | xargs echo -n
101 virsh undefine baremetal$i 2> /dev/null | xargs echo -n
102 /usr/bin/touch /var/lib/libvirt/images/baremetal${i}.qcow2
103 virsh vol-delete baremetal${i}.qcow2 --pool default 2> /dev/null | xargs echo -n
104 rm -f /var/lib/libvirt/images/baremetal${i}.qcow2 2> /dev/null
107 for network in ${OPNFV_NETWORK_TYPES}; do
108 virsh net-destroy ${network} 2> /dev/null
109 virsh net-undefine ${network} 2> /dev/null
112 # Clean off created bridges
113 for bridge in ${ovs_bridges}; do
114 if detach_interface_from_ovs ${bridge} 2> /dev/null; then
115 ovs-vsctl del-br ${bridge} 2> /dev/null
116 rm -f /etc/sysconfig/network-scripts/ifcfg-${bridge}
120 # clean pub keys from root's auth keys
121 sed -i '/stack@undercloud.localdomain/d' /root/.ssh/authorized_keys
122 sed -i '/virtual-power-key/d' /root/.ssh/authorized_keys
125 # force storage cleanup
126 virsh pool-refresh default
128 # remove temporary files
129 rm -f /tmp/network-environment.yaml
131 echo "Cleanup Completed"