-
Notifications
You must be signed in to change notification settings - Fork 9
/
instance-delete-db.sh
executable file
·64 lines (57 loc) · 2.68 KB
/
instance-delete-db.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/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/>.
#
# From: https://gist.github.com/arxcruz/3a94dee0e64f7ba25c8d
# Notes: http://blog.arxcruz.net/deleting-openstack-instances-directly-from-database
#
# 2015-02-26 Updated with 1 more command for Juno
#
# TODO:
# Add usage
VMNAME=$4
MYSQL_HOST=$1
MYSQL_USER=$2
MYSQL_PASSWORD=$3
if [ -z "$4" ]; then echo "VM Name not given"; exit 1; fi
Q=`cat <<EOF
SELECT id FROM nova.instances WHERE instances.display_name = '$VMNAME';
SELECT uuid FROM nova.instances WHERE instances.display_name = '$VMNAME';
EOF`
RQ=`mysql -h $MYSQL_HOST -u $MYSQL_USER -p$MYSQL_PASSWORD --batch --skip-column-names -e "$Q"`
ID=`echo $RQ | cut -d' ' -f1`
UUID=`echo $RQ | cut -d' ' -f2`
if [ -z "$ID" ]; then echo "ID for $VNAME not found"; exit 1; fi
if [ -z "$UUID" ]; then echo "UUID for $VNAME not found"; exit 1; fi
echo "VMNAME: $VMNAME"
echo "ID: $ID"
echo "UUID: $UUID"
echo "Delete $VMNAME? (y/n)"
read -e YN
if [ "$YN" != 'y' ]; then echo "Exiting...";exit 1;fi
Q=`cat <<EOF
DELETE FROM nova.instance_faults WHERE instance_faults.instance_uuid = '$UUID';
DELETE FROM nova.instance_id_mappings WHERE instance_id_mappings.uuid = '$UUID';
DELETE FROM nova.instance_info_caches WHERE instance_info_caches.instance_uuid = '$UUID';
DELETE FROM nova.instance_system_metadata WHERE instance_system_metadata.instance_uuid = '$UUID';
DELETE FROM nova.instance_extra WHERE extra_instance_uuid = '$UUID';
DELETE FROM nova.security_group_instance_association WHERE security_group_instance_association.instance_uuid = '$UUID';
DELETE FROM nova.block_device_mapping WHERE block_device_mapping.instance_uuid = '$UUID';
DELETE FROM nova.fixed_ips WHERE fixed_ips.instance_uuid = '$UUID';
DELETE FROM nova.instance_actions_events WHERE instance_actions_events.action_id in (SELECT id from nova.instance_actions where instance_actions.instance_uuid = '$UUID');
DELETE FROM nova.instance_actions WHERE instance_actions.instance_uuid = '$UUID';
DELETE FROM nova.virtual_interfaces WHERE virtual_interfaces.instance_uuid = '$UUID';
DELETE FROM nova.instances WHERE instances.uuid = '$UUID';
EOF`
RQ=`mysql -h $MYSQL_HOST -u $MYSQL_USER -p$MYSQL_PASSWORD --batch --skip-column-names -e "$Q"`
echo "$RQ"