blob: a82f3a05fb3622c10941aea0b13ef05733d297d8 [file] [log] [blame]
Anthony Youngb62b4ca2011-10-26 22:29:08 -07001#!/bin/bash
2#
3# Copyright (c) 2011 Citrix Systems, Inc.
4# Copyright 2011 OpenStack LLC.
Anthony Youngb62b4ca2011-10-26 22:29:08 -07005# All Rights Reserved.
6#
7# Licensed under the Apache License, Version 2.0 (the "License"); you may
8# not use this file except in compliance with the License. You may obtain
9# a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16# License for the specific language governing permissions and limitations
17# under the License.
18#
19
20remove_data=
21if [ "$1" = "--remove-data" ]
22then
23 remove_data=1
24fi
25
26set -eu
27
28xe_min()
29{
30 local cmd="$1"
31 shift
32 /opt/xensource/bin/xe "$cmd" --minimal "$@"
33}
34
35destroy_vdi()
36{
37 local vbd_uuid="$1"
38 local type=$(xe_min vbd-list uuid=$vbd_uuid params=type)
39 local dev=$(xe_min vbd-list uuid=$vbd_uuid params=userdevice)
40 local vdi_uuid=$(xe_min vbd-list uuid=$vbd_uuid params=vdi-uuid)
41
42 if [ "$type" = 'Disk' ] && [ "$dev" != 'xvda' ] && [ "$dev" != '0' ]
43 then
44 echo -n "Destroying data disk... "
45 xe vdi-destroy uuid=$vdi_uuid
46 echo "done."
47 fi
48}
49
50uninstall()
51{
52 local vm_uuid="$1"
53 local power_state=$(xe_min vm-list uuid=$vm_uuid params=power-state)
54
55 if [ "$power_state" != "halted" ]
56 then
57 echo -n "Shutting down VM... "
58 xe vm-shutdown vm=$vm_uuid force=true
59 echo "done."
60 fi
61
62 if [ "$remove_data" = "1" ]
63 then
64 for v in $(xe_min vbd-list vm-uuid=$vm_uuid | sed -e 's/,/ /g')
65 do
66 destroy_vdi "$v"
67 done
68 fi
69
70 echo -n "Deleting VM... "
71 xe vm-uninstall vm=$vm_uuid force=true >/dev/null
72 echo "done."
73}
74
75uninstall_template()
76{
77 local vm_uuid="$1"
78
79 if [ "$remove_data" = "1" ]
80 then
81 for v in $(xe_min vbd-list vm-uuid=$vm_uuid | sed -e 's/,/ /g')
82 do
83 destroy_vdi "$v"
84 done
85 fi
86
87 echo -n "Deleting template... "
88 xe template-uninstall template-uuid=$vm_uuid force=true >/dev/null
89 echo "done."
90}
91
92
93for u in $(xe_min vm-list other-config:os-vpx=true | sed -e 's/,/ /g')
94do
95 uninstall "$u"
96done
97
98for u in $(xe_min template-list other-config:os-vpx=true | sed -e 's/,/ /g')
99do
100 uninstall_template "$u"
101done