-
Notifications
You must be signed in to change notification settings - Fork 0
/
vmsnap-rollback.scenario
146 lines (125 loc) · 3.92 KB
/
vmsnap-rollback.scenario
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# This file can be used directly by 'phd', see 'build-all.sh' in this
# directory for how it can be invoked. The only requirement is a list
# of nodes you'd like it to modify.
#
# The scope of each command-block is controlled by the preceeding
# 'target' line.
#
# - target=all
# The commands are executed on evey node provided
#
# - target=local
# The commands are executed from the node hosting phd. When not
# using phd, they should be run from some other independant host
# (such as the puppet master)
#
# - target=$PHD_ENV_nodes{N}
# The commands are executed on the Nth node provided.
# For example, to run on only the first node would be target=$PHD_ENV_nodes1
#
# We start with 3 (or more, up to 16) nodes running a minimal CentOS 6
#
# Tasks to be performed include:
# - setting up the required repositories from which to download Openstack and the HA-Addon
# - disabling firewalls and SElinux. This is a necessary evil until the proper policies can be written.
# - creating network bridges for use by VMs hosting OpenStack services
# - normalizing network interface names
# - fixing multicast
# - removing /home and making the root partition as large as possible to maximumize the amount of space available to openstack
#################################
# Scenario Requirements Section #
#################################
= VARIABLES =
PHD_ENV_snapshot_name
PHD_VAR_osp_configdir
#################################
# Scenario Requirements Section #
#################################
= REQUIREMENTS =
nodes: 3
######################
# Deployment Scripts #
######################
= SCRIPTS =
target=all
....
# get list of all VMs configured on a given host
vmlist=$(virsh list --all --name)
for vm in $vmlist; do
# if the requested snapshot doesn't exist, don't continue with
# disruptive actions
if [ ! -f /localvms/${vm}-${PHD_ENV_snapshot_name}.cow ]; then
echo "ERROR: Snapshot ${PHD_ENV_snapshot_name} does not exists"
exit 1
fi
current=$(virsh snapshot-current --name $vm)
if [ "$current" = ${PHD_ENV_snapshot_name} ]; then
echo "ERROR: We are already at snapshot: ${PHD_ENV_snapshot_name}"
exit 1
fi
# make sure that the we are rolling back to a snap
# that is parent of the current
snaplist=$(virsh snapshot-list --tree $vm | sed -e 's#.*|.*##g' -e 's#.*+- ##g')
for snap in $snaplist; do
if [ "$snap" = "${PHD_ENV_snapshot_name}" ]; then
# we found requested snap before current and we are good
echo "found snap ${PHD_ENV_snapshot_name}"
break;
fi
if [ "$snap" = "$current" ]; then
# current is before the requested snap, error
echo "ERROR: Requested snap ${PHD_ENV_snapshot_name} is not a parent of current $current snap"
exit 1
fi
done
done
....
target=all
....
# to roll back we need to kill hard the VMs but we want to make
# sure that the other nodes won't fence before we get to
# revert properly
systemctl stop fence_virtd
vmlist=$(virsh list --all --name)
for vm in $vmlist; do
rollback=""
virsh destroy $vm
snaplist=$(virsh snapshot-list --tree $vm | sed -e 's#.*|.*##g' -e 's#.*+- ##g')
# we need to proceed from the bottom of the list
for snap in $snaplist; do
rollback="$snap $rollback"
done
# kill all disks
for snap in $rollback; do
if [ "$snap" = "${PHD_ENV_snapshot_name}" ]; then
break;
fi
rm -f /localvms/${vm}-${snap}.cow
# needs extra cleaning
case $snap in
cinder)
rm -rf $PHD_VAR_osp_configdir/cinder
;;
glance)
rm -rf $PHD_VAR_osp_configdir/glance
;;
esac
done
# drop all childs
virsh snapshot-delete --domain $vm ${PHD_ENV_snapshot_name} --metadata --children-only
virsh detach-disk $vm vda --config
virsh attach-disk $vm /localvms/$vm-${PHD_ENV_snapshot_name}.cow vda \
--sourcetype file --type disk \
--driver qemu --subdriver qcow2 \
--config
done
....
target=all
....
systemctl start fence_virtd
# get list of all VMs configured on a given host
vmlist=$(virsh list --all --name)
for vm in $vmlist; do
virsh start $vm
done
....