Add function for creating basedisk
The function introduced with this changeset creates a base disk that can be used to create custom node VMs. Partial-Bug: 1312764 Implements: blueprint openstack-training-labs Change-Id: Ib736b65ec0f87decd81866a60ed82d6f8b5aa0f1
This commit is contained in:
parent
a17aa7c02a
commit
8691fc7e15
117
labs/lib/osbash/virtualbox.install_base
Normal file
117
labs/lib/osbash/virtualbox.install_base
Normal file
@ -0,0 +1,117 @@
|
||||
# This bash library contains the main function that creates the base disk.
|
||||
|
||||
function vm_install_base {
|
||||
local BASE_DISK=$1
|
||||
local BASE_BUILD_DISK=$DISK_DIR/tmp-disk.vdi
|
||||
|
||||
# Port used for ssh forwarding when building base disk
|
||||
: ${VM_BASE_SSH_PORT:=2229}
|
||||
|
||||
echo >&2 "$(date) osbash vm_install starts."
|
||||
|
||||
${WBATCH:-:} wbatch_begin_base
|
||||
|
||||
# Don't remove BASE_BUILD_DISK if we are just faking it for wbatch
|
||||
${OSBASH:-:} rm -f "$BASE_BUILD_DISK"
|
||||
${WBATCH:-:} wbatch_delete_disk "$BASE_BUILD_DISK"
|
||||
|
||||
vm_create "$VM_BASE_NAME"
|
||||
vm_mem "$VM_BASE_NAME" "${VM_BASE_MEM:=512}"
|
||||
|
||||
if [ -z "${INSTALL_ISO-}" ]; then
|
||||
local ISO_NAME="$(get_iso_name)"
|
||||
|
||||
if [ -z "$ISO_NAME" ]; then
|
||||
echo >&2 "Either ISO URL or name needed (ISO_URL, INSTALL_ISO)."
|
||||
exit 1
|
||||
fi
|
||||
INSTALL_ISO=$ISO_DIR/$ISO_NAME
|
||||
find_install-iso "$ISO_NAME"
|
||||
fi
|
||||
|
||||
echo >&2 -e "Install ISO:\n\t$INSTALL_ISO"
|
||||
$VBM storageattach "$VM_BASE_NAME" \
|
||||
--storagectl IDE \
|
||||
--port 0 \
|
||||
--device 0 \
|
||||
--type dvddrive \
|
||||
--medium "$INSTALL_ISO"
|
||||
|
||||
vm_attach_guestadd-iso "$VM_BASE_NAME"
|
||||
|
||||
${OSBASH:-:} mkdir -pv "$DISK_DIR"
|
||||
create_vdi "$BASE_BUILD_DISK" 8000
|
||||
vm_attach_disk "$VM_BASE_NAME" "$BASE_BUILD_DISK"
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Set up communication with base VM: ssh port forwarding by default,
|
||||
# VirtualBox shared folders for wbatch
|
||||
|
||||
# wbatch runs cannot use ssh, so skip port forwarding in that case
|
||||
${WBATCH:+:} vm_port "$VM_BASE_NAME" ssh "$VM_BASE_SSH_PORT" 22
|
||||
|
||||
# Automounted on /media/sf_bootstrap for first boot
|
||||
${WBATCH:-:} vm_add_share_automount "$VM_BASE_NAME" "$SHARE_DIR" bootstrap
|
||||
# Mounted on /$SHARE_NAME after first boot
|
||||
${WBATCH:-:} vm_add_share "$VM_BASE_NAME" "$SHARE_DIR" "$SHARE_NAME"
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
$VBM modifyvm "$VM_BASE_NAME" --boot1 dvd
|
||||
|
||||
# Configure autostart
|
||||
autostart_reset
|
||||
|
||||
# For wbatch, install osbashauto as a boot service
|
||||
${WBATCH:-:} autostart osbash activate_autostart.sh
|
||||
|
||||
autostart osbash base_fixups.sh
|
||||
|
||||
# By default, set by lib/osbash/lib.* to something like scripts.ubuntu
|
||||
autostart_from_config "$BASE_INSTALL_SCRIPTS"
|
||||
|
||||
autostart scripts zero_empty.sh shutdown.sh
|
||||
|
||||
# Boot VM into distribution installer
|
||||
vbox_boot "$VM_BASE_NAME"
|
||||
|
||||
local DELAY=5
|
||||
echo >&2 "Waiting $DELAY seconds for VM \"$VM_BASE_NAME\" to come up"
|
||||
vbox_sleep "$DELAY"
|
||||
|
||||
vbox_distro_start_installer "$VM_BASE_NAME"
|
||||
|
||||
echo >&2 "Installing operating system; waiting for reboot"
|
||||
|
||||
# Wait for ssh connection and execute scripts in autostart directory
|
||||
# (for wbatch, osbashauto does the processing instead)
|
||||
${WBATCH:+:} ssh_process_autostart "$VM_BASE_SSH_PORT" &
|
||||
# After reboot
|
||||
wait_for_autofiles
|
||||
echo >&2 "Installation done for VM $VM_BASE_NAME"
|
||||
|
||||
vm_wait_for_shutdown "$VM_BASE_NAME"
|
||||
|
||||
# Detach disk from VM now or it will be deleted by vm_unregister_del
|
||||
vm_detach_disk "$VM_BASE_NAME"
|
||||
|
||||
vm_unregister_del "$VM_BASE_NAME"
|
||||
|
||||
echo >&2 "Compacting $BASE_BUILD_DISK"
|
||||
$VBM modifyhd "$BASE_BUILD_DISK" --compact
|
||||
|
||||
# This disk will be moved to a new name, and this name will be used for
|
||||
# a new disk next time the script runs.
|
||||
disk_unregister "$BASE_BUILD_DISK"
|
||||
|
||||
echo >&2 "Base disk created"
|
||||
|
||||
echo >&2 "Moving base disk to $BASE_DISK"
|
||||
${OSBASH:-:} mv -vf "$BASE_BUILD_DISK" "$BASE_DISK"
|
||||
${WBATCH:-:} wbatch_rename_disk "$BASE_BUILD_DISK" "$BASE_DISK"
|
||||
|
||||
${WBATCH:-:} wbatch_end_file
|
||||
|
||||
echo >&2 -e "$(date) osbash vm_install ends\n"
|
||||
}
|
||||
|
||||
# vim: set ai ts=4 sw=4 et ft=sh:
|
Loading…
Reference in New Issue
Block a user