#!/bin/bash
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# <http://www.gnu.org/licenses/>.
#
function delete_instance() {
Q=`cat <<EOF
DELETE FROM nova.instance_faults WHERE instance_faults.instance_uuid = '$1';
DELETE FROM nova.instance_id_mappings WHERE instance_id_mappings.uuid = '$1';
DELETE FROM nova.instance_info_caches WHERE instance_info_caches.instance_uuid = '$1';
DELETE FROM nova.instance_system_metadata WHERE instance_system_metadata.instance_uuid = '$1';
DELETE FROM nova.security_group_instance_association WHERE security_group_instance_association.instance_uuid = '$1';
DELETE FROM nova.instances WHERE instances.uuid = '$1';
EOF`
RQ=`mysql --batch --skip-column-names -e "$Q"`
echo "$RQ"
}
Q=`cat <<EOF
SELECT uuid FROM nova.instances;
EOF`
RQ=`mysql --batch --skip-column-names -e "$Q"`
arr=$(echo $RQ | tr " " "\n")
count=1
for i in $arr
do
echo "[ $count ] : $i"
count=$(( $count+1 ))
delete_instance $i
done