blob: a0a27e8a8f9ccbeb81f0d858fbfe3cb59a2ef894 [file] [log] [blame]
Renuka Apte83f8b1a2012-04-02 15:45:27 -07001#!/bin/bash
2
3set -eux
4
5action="$1"
6vm="$2"
7device="${3-0}"
8part="${4-}"
9
10xe_min()
11{
12 local cmd="$1"
13 shift
14 xe "$cmd" --minimal "$@"
15}
16
17vm_uuid=$(xe_min vm-list name-label="$vm")
18vdi_uuid=$(xe_min vbd-list params=vdi-uuid vm-uuid="$vm_uuid" \
19 userdevice="$device")
20
21dom0_uuid=$(xe_min vm-list is-control-domain=true)
22
23open_vdi()
24{
25 vbd_uuid=$(xe vbd-create vm-uuid="$dom0_uuid" vdi-uuid="$vdi_uuid" \
26 device=autodetect)
27 mp=$(mktemp -d)
28 xe vbd-plug uuid="$vbd_uuid"
29
30 udevsettle
31 dev=$(xe_min vbd-list params=device uuid="$vbd_uuid")
32 mount "/dev/$dev$part" "$mp"
33 echo "Your vdi is mounted at $mp"
34}
35
36close_vdi()
37{
38 vbd_uuid=$(xe_min vbd-list vm-uuid="$dom0_uuid" vdi-uuid="$vdi_uuid")
39 dev=$(xe_min vbd-list params=device uuid="$vbd_uuid")
40 umount "/dev/$dev$part"
41
42 xe vbd-unplug uuid=$vbd_uuid
43 xe vbd-destroy uuid=$vbd_uuid
44}
45
46if [ "$action" == "open" ]
47then
48 open_vdi
49elif [ "$action" == "close" ]
50then
51 close_vdi
52fi