-
Notifications
You must be signed in to change notification settings - Fork 283
/
with-vdi
executable file
·53 lines (47 loc) · 1.11 KB
/
with-vdi
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
#!/bin/sh
function usage
{
echo
echo Usage:
echo $0 "<VDI uuid> [ command to execute, defaults to /bin/sh ]"
echo
echo Block attaches a VDI to the control domain, executes a command \(typically a shell\),
echo detaches and destroys the VBD when the command finishes.
}
VDI=$1
# check that the VDI actually exists
if [ -z "$(xe vdi-list params=uuid uuid=${VDI})" ]; then
echo Failed to find VDI with UUID: ${VDI}
usage
exit 1
fi
COMMAND=$2
if [ -n "$COMMAND" ]; then
if ! which "$COMMAND" > /dev/null ; then
echo Failed to find command: ${COMMAND}
usage
exit 1
else
shift 1
COMMAND=$*
fi
fi
. @INVENTORY@
if [ `xe vdi-param-get uuid=${VDI} param-name=read-only` = "true" ] ; then
MODE=RO
else
MODE=RW
fi
VBD=`xe vbd-create vm-uuid=${CONTROL_DOMAIN_UUID} vdi-uuid=${VDI} device=autodetect mode=${MODE} unpluggable=true`
xe vbd-plug uuid=${VBD}
DEVICE=`xe vbd-param-get uuid=${VBD} param-name=device`
export DEVICE
if [ -z "$COMMAND" ]; then
echo DEVICE=${DEVICE}
COMMAND=/bin/sh
fi
${COMMAND}
RC=$?
xe vbd-unplug uuid=${VBD} timeout=15
xe vbd-destroy uuid=${VBD}
exit ${RC}