blob: 6532ecfe6d54b8b5b89b0fecb8de70219329b9c0 [file] [log] [blame]
AyumuUeha76a01bc2017-05-18 13:34:13 +09001#!/bin/bash
2#************************************************************/
3#** File: nova_pppoe_cleanup.sh */
4#** Contents: Contains shell script to clean up */
5#** nova-compute VM */
6#************************************************************/
7
8date
9echo "nova_pppoe_cleanup.sh: Begin"
10
11HOME_DIR=`pwd`; export HOME_DIR
12vsg_monitor_script="nova_vsg_monitor.sh"
13vsg_cleanup_script="vsg_pppoe_cleanup.sh"
14vsg_gwbr_name=vsg_gwbr
15vsg_home_dir=/home/ubuntu
16vsg_env_file=vsg_env.txt
17# Read the temp_id.txt file and fill the array named "array"
18
19getArray() {
20 array=() # Create array
21 while IFS= read -r line # Read a line
22 do
23 array+=("$line") # Append line to the array
24 done < "$1"
25}
26
27get_vsg_gwbr_ifaces() {
28 ifacesArray=() # Create array
29 while IFS= read -r line # Read a line
30 do
31 ifacesArray+=("$line") # Append line to the array
32 done < "$1"
33}
34
35function cleanup_vsg_dockers() {
36
37 source ${HOME_DIR}/admin-openrc.sh
38
39 echo "Checking for active VSG..."
40
41 file_temp="${HOME_DIR}/temp_id.txt"
42
43 nova list --all-tenants|grep mysite_vsg|grep ACTIVE|awk '{print $2}' > $file_temp
44
45 getArray $file_temp
46
47 for id in "${array[@]}"
48 do
49 echo "VSG ID=$id"
50 vsgIp=$( nova interface-list $id|grep 172.27|awk '{print $8}' )
51 echo "Cleaning up VSG: vsgIp: $vsgIp"
52 scp $HOME_DIR/$vsg_cleanup_script "ubuntu@$vsgIp:/tmp"
53 scp $HOME_DIR/$vsg_env_file "ubuntu@$vsgIp:/tmp"
54 ssh ubuntu@$vsgIp "chmod +x /tmp/$vsg_cleanup_script"
55 ssh ubuntu@$vsgIp "/tmp/$vsg_cleanup_script $vsgIp $vsg_home_dir"
56 echo "VSG Instance $vsgIp cleanup is complete"
57 done
58}
59
60function cleanup_vsg_gwbr() {
61
62 echo "Entering function_cleanup_vsg_gwbridge "
63 source ${HOME_DIR}/admin-openrc.sh
64
65 file_temp="${HOME_DIR}/vsg_id.txt"
66 file_ifaces="${HOME_DIR}/gwbr_ifaces.txt"
67
68 sudo virsh list|awk '{print $1}' > $file_temp
69
70 getArray $file_temp
71
72 for id in "${array[@]}"
73 do
74 len=${#id}
75 if [ $len -eq 0 ] || echo $id|grep [^0-9]; then
76 echo "Not a valid virsh ID: $id"
77 else
78 echo "Cleaning up VSG instance: $id"
79 sudo virsh domiflist $id|grep $vsg_gwbr_name|awk '{print $NF}' > $file_ifaces
80 get_vsg_gwbr_ifaces $file_ifaces
81 for mac in "${ifacesArray[@]}"
82 do
83 echo "Detaching interface $mac in VSG instance: $id"
84 sudo virsh detach-interface $id bridge $mac
85 done
86 echo "VSG Instance $id cleanup is complete"
87 fi
88 done
89 if ifconfig -a |grep $vsg_gwbr_name; then
90 sudo ifconfig $vsg_gwbr_name down
91 sudo brctl delbr $vsg_gwbr_name
92 fi
93}
94
95function remove_temp_files () {
96 sudo rm -f $HOME_DIR/*.txt
97}
98
99function remove_apps() {
100 echo "Removing Apps"
101 sudo rm -rf /usr/local/pppoe/utils/
102 sudo rm -rf /usr/local/pppoe
103}
104
105function stop_vsg_monitor() {
106 echo "Stopping pppoe_check_vsg_status.sh script"
107 pid=`ps -ef | grep $vsg_monitor_script| grep -v grep | awk '{print $2}'`
108 if [ -n $pid ]; then
109 sudo kill -9 $pid
110 fi
111 rm -rf $HOME_DIR/nova_vsg_monitor.log
112}
113
114function stop_nova_consolidator() {
115 echo "Stopping nova consolidation app"
116 $HOME_DIR/nova_consolidator_stop.sh
117 sudo rm -f /usr/local/lib/node_modules/*.json
118}
119
120#remove_vsg_entry_from_proxy_file
121#delete_vsg_id
122stop_vsg_monitor
123remove_apps
124cleanup_vsg_dockers
125cleanup_vsg_gwbr
126stop_nova_consolidator
127remove_temp_files
128echo "nova_pppoe_cleanup.sh: End"
129date