labs: move VM export function from osbash.sh into lib

This patch moves export_appliance in osbash.sh to vm_export_ova in
virtualbox.functions.

Change-Id: I80178fe647f1e76a2790b319a0abacd39428a9e0
This commit is contained in:
Roger Luethi 2014-08-25 13:15:59 +02:00
parent e00c0077bd
commit 8e697a119b
2 changed files with 35 additions and 27 deletions

View File

@ -380,6 +380,38 @@ function vm_create {
echo >&2 "Created VM \"$VM_NAME\""
}
#-------------------------------------------------------------------------------
# VM export
#-------------------------------------------------------------------------------
# Export node VMs to OVA package file
function vm_export_ova {
local ova_file=$1
local nodes=$2
echo >&2 "Removing shared folders for export"
local -a share_paths
local node
for node in $nodes; do
local share_path=$(vm_get_share_path "$node")
share_paths+=("$share_path")
if [ -n "$share_path" ]; then
vm_rm_share "$node" "$SHARE_NAME"
fi
done
rm -f "$ova_file"
mkdir -pv "$IMG_DIR"
$VBM export $nodes --output "$ova_file"
echo >&2 "Appliance exported"
echo >&2 "Reattaching shared folders"
local ii=0
for node in $nodes; do
if [ -n "${share_paths[$ii]}" ]; then
vm_add_share "$node" "$SHARE_DIR" "$SHARE_NAME"
fi
ii=$(($ii + 1))
done
}
#-------------------------------------------------------------------------------
# VM unregister, remove, delete
#-------------------------------------------------------------------------------

View File

@ -161,32 +161,8 @@ for node in $nodes; do
vm_build_node "$node"
done
#-------------------------------------------------------------------------------
function export_appliance {
if [ -n "${EXPORT_OVA:-}" ]; then
echo >&2 "Removing shared folders for export"
local -a share_paths
local node
for node in $nodes; do
local share_path=$(vm_get_share_path "$node")
share_paths+=("$share_path")
if [ -n "$share_path" ]; then
vm_rm_share "$node" "$SHARE_NAME"
fi
done
rm -f "$EXPORT_OVA"
mkdir -pv "$IMG_DIR"
$VBM export $nodes --output "$EXPORT_OVA"
echo >&2 "Appliance exported"
echo >&2 "Reattaching shared folders"
local ii=0
for node in $nodes; do
if [ -n "${share_paths[$ii]}" ]; then
vm_add_share "$node" "$SHARE_DIR" "$SHARE_NAME"
fi
ii=$(($ii + 1))
done
fi
}
export_appliance
if [ -n "${EXPORT_OVA:-}" ]; then
vm_export_ova "$EXPORT_OVA" "$nodes"
fi
#-------------------------------------------------------------------------------
echo >&2 "$(date) osbash finished successfully"