File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ set -eux
4+
5+ action=" $1 "
6+ vm=" $2 "
7+ device=" ${3-0} "
8+ part=" ${4-} "
9+
10+ xe_min ()
11+ {
12+ local cmd=" $1 "
13+ shift
14+ xe " $cmd " --minimal " $@ "
15+ }
16+
17+ vm_uuid=$( xe_min vm-list name-label=" $vm " )
18+ vdi_uuid=$( xe_min vbd-list params=vdi-uuid vm-uuid=" $vm_uuid " \
19+ userdevice=" $device " )
20+
21+ dom0_uuid=$( xe_min vm-list is-control-domain=true)
22+
23+ open_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+
36+ close_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+
46+ if [ " $action " == " open" ]
47+ then
48+ open_vdi
49+ elif [ " $action " == " close" ]
50+ then
51+ close_vdi
52+ fi
You can’t perform that action at this time.
0 commit comments