devstack/tools/xen/scripts/manage-vdi
Renuka Apte 83f8b1abce XenServer: Add script to mount OS domU in dom0
Change-Id: I1ad3d63c55b95f2588007c5e88704022f54e1c06
2012-04-14 14:49:10 -05:00

53 lines
993 B
Bash
Executable File

#!/bin/bash
set -eux
action="$1"
vm="$2"
device="${3-0}"
part="${4-}"
xe_min()
{
local cmd="$1"
shift
xe "$cmd" --minimal "$@"
}
vm_uuid=$(xe_min vm-list name-label="$vm")
vdi_uuid=$(xe_min vbd-list params=vdi-uuid vm-uuid="$vm_uuid" \
userdevice="$device")
dom0_uuid=$(xe_min vm-list is-control-domain=true)
open_vdi()
{
vbd_uuid=$(xe vbd-create vm-uuid="$dom0_uuid" vdi-uuid="$vdi_uuid" \
device=autodetect)
mp=$(mktemp -d)
xe vbd-plug uuid="$vbd_uuid"
udevsettle
dev=$(xe_min vbd-list params=device uuid="$vbd_uuid")
mount "/dev/$dev$part" "$mp"
echo "Your vdi is mounted at $mp"
}
close_vdi()
{
vbd_uuid=$(xe_min vbd-list vm-uuid="$dom0_uuid" vdi-uuid="$vdi_uuid")
dev=$(xe_min vbd-list params=device uuid="$vbd_uuid")
umount "/dev/$dev$part"
xe vbd-unplug uuid=$vbd_uuid
xe vbd-destroy uuid=$vbd_uuid
}
if [ "$action" == "open" ]
then
open_vdi
elif [ "$action" == "close" ]
then
close_vdi
fi