labs: add export via clone VM directory

This changeset introduces a new export method: exporting the named node
VMs as clones to the img directory.

The -e option takes now an argument (ova or dir) to distinguish between
exporting to an OVA package file and exporting to the img directory.

Unlike the OVA package files, this method preserves snapshots.

The resulting vbox files can be imported as VMs via VirtualBox GUI
(Machine->Add).

Change-Id: I7a8801de4b69796f3291a9e3a5896a055859121f
This commit is contained in:
Roger Luethi 2014-08-26 12:28:36 +02:00
parent 1b98a3c44c
commit f210af6952
2 changed files with 46 additions and 2 deletions

View File

@ -412,6 +412,33 @@ function vm_export_ova {
done
}
# Export node VMs by cloning VMs to directory
function vm_export_dir {
local export_dir=$1
local nodes=$2
rm -rvf "$export_dir"
for node in $nodes; do
if vm_is_running "$node"; then
echo "Powering off node VM $node."
echo "$VBM controlvm $node poweroff"
$VBM controlvm "$node" poweroff
fi
sleep 1
vm_rm_share "$node" "$SHARE_NAME"
sleep 1
echo "Exporting VM $node to $export_dir"
# Use all: machineandchildren works only if --snapshot is given as UUID
$VBM clonevm "$node" \
--mode all \
--options keepallmacs,keepdisknames \
--name "$node" \
--groups "/$VM_GROUP" \
--basefolder "$export_dir"
done
}
#-------------------------------------------------------------------------------
# VM unregister, remove, delete
#-------------------------------------------------------------------------------

View File

@ -44,6 +44,8 @@ function print_config {
if [ -n "${EXPORT_OVA:-}" ]; then
echo "Exporting to OVA: ${EXPORT_OVA}"
elif [ -n "${EXPORT_VM_DIR:-}" ]; then
echo "Exporting to directory: ${EXPORT_VM_DIR}"
else
echo -n "Creating Windows batch scripts: "
${WBATCH:-:} echo "yes"
@ -58,10 +60,17 @@ function print_config {
}
while getopts :efhnw opt; do
while getopts :e:fhnw opt; do
case $opt in
e)
EXPORT_OVA=$IMG_DIR/oslabs-$DISTRO.ova
if [ "$OPTARG" = ova ]; then
EXPORT_OVA=$IMG_DIR/oslabs-$DISTRO.ova
elif [ "$OPTARG" = dir ]; then
EXPORT_VM_DIR=$IMG_DIR/oslabs-$DISTRO
else
echo "Error: -e argument must be ova or dir"
exit
fi
;;
f)
source "$LIB_DIR/wbatch/batch_for_windows"
@ -77,6 +86,9 @@ while getopts :efhnw opt; do
w)
source "$LIB_DIR/wbatch/batch_for_windows"
;;
:)
echo "Error: -$OPTARG needs argument"
;;
?)
echo "Error: invalid option -$OPTARG"
echo
@ -120,6 +132,11 @@ if [ -n "${EXPORT_OVA:-}" ]; then
exit
fi
if [ -n "${EXPORT_VM_DIR:-}" ]; then
vm_export_dir "$EXPORT_VM_DIR" "$nodes"
exit
fi
echo >&2 "$(date) osbash starting"
clean_dir "$LOG_DIR"