AyumuUeha | 76a01bc | 2017-05-18 13:34:13 +0900 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | #************************************************************/ |
| 3 | #** File: nova_pppoe_cleanup.sh */ |
| 4 | #** Contents: Contains shell script to clean up */ |
| 5 | #** nova-compute VM */ |
| 6 | #************************************************************/ |
| 7 | |
| 8 | date |
| 9 | echo "nova_pppoe_cleanup.sh: Begin" |
| 10 | |
| 11 | HOME_DIR=`pwd`; export HOME_DIR |
| 12 | vsg_monitor_script="nova_vsg_monitor.sh" |
| 13 | vsg_cleanup_script="vsg_pppoe_cleanup.sh" |
| 14 | vsg_gwbr_name=vsg_gwbr |
| 15 | vsg_home_dir=/home/ubuntu |
| 16 | vsg_env_file=vsg_env.txt |
| 17 | # Read the temp_id.txt file and fill the array named "array" |
| 18 | |
| 19 | getArray() { |
| 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 | |
| 27 | get_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 | |
| 35 | function 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 | |
| 60 | function 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 | |
| 95 | function remove_temp_files () { |
| 96 | sudo rm -f $HOME_DIR/*.txt |
| 97 | } |
| 98 | |
| 99 | function remove_apps() { |
| 100 | echo "Removing Apps" |
| 101 | sudo rm -rf /usr/local/pppoe/utils/ |
| 102 | sudo rm -rf /usr/local/pppoe |
| 103 | } |
| 104 | |
| 105 | function 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 | |
| 114 | function 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 |
| 122 | stop_vsg_monitor |
| 123 | remove_apps |
| 124 | cleanup_vsg_dockers |
| 125 | cleanup_vsg_gwbr |
| 126 | stop_nova_consolidator |
| 127 | remove_temp_files |
| 128 | echo "nova_pppoe_cleanup.sh: End" |
| 129 | date |