blob: db66dda76e3358fb3dd8e0347ded128c03e90b8e [file] [log] [blame]
Matteo Scandoloaca86652017-08-08 13:05:27 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
AyumuUeha76a01bc2017-05-18 13:34:13 +090017#!/bin/bash
18#************************************************************/
19#** File: nova_pppoe_cleanup.sh */
20#** Contents: Contains shell script to clean up */
21#** nova-compute VM */
22#************************************************************/
23
24date
25echo "nova_pppoe_cleanup.sh: Begin"
26
27HOME_DIR=`pwd`; export HOME_DIR
28vsg_monitor_script="nova_vsg_monitor.sh"
29vsg_cleanup_script="vsg_pppoe_cleanup.sh"
30vsg_gwbr_name=vsg_gwbr
31vsg_home_dir=/home/ubuntu
32vsg_env_file=vsg_env.txt
33# Read the temp_id.txt file and fill the array named "array"
34
35getArray() {
36 array=() # Create array
37 while IFS= read -r line # Read a line
38 do
39 array+=("$line") # Append line to the array
40 done < "$1"
41}
42
43get_vsg_gwbr_ifaces() {
44 ifacesArray=() # Create array
45 while IFS= read -r line # Read a line
46 do
47 ifacesArray+=("$line") # Append line to the array
48 done < "$1"
49}
50
51function cleanup_vsg_dockers() {
52
53 source ${HOME_DIR}/admin-openrc.sh
54
55 echo "Checking for active VSG..."
56
57 file_temp="${HOME_DIR}/temp_id.txt"
58
59 nova list --all-tenants|grep mysite_vsg|grep ACTIVE|awk '{print $2}' > $file_temp
60
61 getArray $file_temp
62
63 for id in "${array[@]}"
64 do
65 echo "VSG ID=$id"
66 vsgIp=$( nova interface-list $id|grep 172.27|awk '{print $8}' )
67 echo "Cleaning up VSG: vsgIp: $vsgIp"
68 scp $HOME_DIR/$vsg_cleanup_script "ubuntu@$vsgIp:/tmp"
69 scp $HOME_DIR/$vsg_env_file "ubuntu@$vsgIp:/tmp"
70 ssh ubuntu@$vsgIp "chmod +x /tmp/$vsg_cleanup_script"
71 ssh ubuntu@$vsgIp "/tmp/$vsg_cleanup_script $vsgIp $vsg_home_dir"
72 echo "VSG Instance $vsgIp cleanup is complete"
73 done
74}
75
76function cleanup_vsg_gwbr() {
77
78 echo "Entering function_cleanup_vsg_gwbridge "
79 source ${HOME_DIR}/admin-openrc.sh
80
81 file_temp="${HOME_DIR}/vsg_id.txt"
82 file_ifaces="${HOME_DIR}/gwbr_ifaces.txt"
83
84 sudo virsh list|awk '{print $1}' > $file_temp
85
86 getArray $file_temp
87
88 for id in "${array[@]}"
89 do
90 len=${#id}
91 if [ $len -eq 0 ] || echo $id|grep [^0-9]; then
92 echo "Not a valid virsh ID: $id"
93 else
94 echo "Cleaning up VSG instance: $id"
95 sudo virsh domiflist $id|grep $vsg_gwbr_name|awk '{print $NF}' > $file_ifaces
96 get_vsg_gwbr_ifaces $file_ifaces
97 for mac in "${ifacesArray[@]}"
98 do
99 echo "Detaching interface $mac in VSG instance: $id"
100 sudo virsh detach-interface $id bridge $mac
101 done
102 echo "VSG Instance $id cleanup is complete"
103 fi
104 done
105 if ifconfig -a |grep $vsg_gwbr_name; then
106 sudo ifconfig $vsg_gwbr_name down
107 sudo brctl delbr $vsg_gwbr_name
108 fi
109}
110
111function remove_temp_files () {
112 sudo rm -f $HOME_DIR/*.txt
113}
114
115function remove_apps() {
116 echo "Removing Apps"
117 sudo rm -rf /usr/local/pppoe/utils/
118 sudo rm -rf /usr/local/pppoe
119}
120
121function stop_vsg_monitor() {
122 echo "Stopping pppoe_check_vsg_status.sh script"
123 pid=`ps -ef | grep $vsg_monitor_script| grep -v grep | awk '{print $2}'`
124 if [ -n $pid ]; then
125 sudo kill -9 $pid
126 fi
127 rm -rf $HOME_DIR/nova_vsg_monitor.log
128}
129
130function stop_nova_consolidator() {
131 echo "Stopping nova consolidation app"
132 $HOME_DIR/nova_consolidator_stop.sh
133 sudo rm -f /usr/local/lib/node_modules/*.json
134}
135
136#remove_vsg_entry_from_proxy_file
137#delete_vsg_id
138stop_vsg_monitor
139remove_apps
140cleanup_vsg_dockers
141cleanup_vsg_gwbr
142stop_nova_consolidator
143remove_temp_files
144echo "nova_pppoe_cleanup.sh: End"
145date