training-guides/labs/lib/osbash/virtualbox.install_node
Roger Luethi 7e1864c7ba labs: add init_node command
This changeset adds a new init_node command for config/scripts.* and
uses it to merge scripts.nodeinit_osbash and scripts.nodeinit_vagrant
into the node specific config/scripts.*.

This results in some redundancy, but it (hopefully) makes the script
configuration easier to follow. It also makes the initial creation and
configuration of the VM just another step that can be picked or omitted
from script configuration.

Implements: blueprint openstack-training-labs
Change-Id: Ieadfe2b9540710556100051723e3e6f08855efa3
2014-08-20 13:02:29 +02:00

86 lines
2.6 KiB
Bash

# This bash library contains the main function that creates a node VM.
# Configure VirtualBox network interfaces
function _vbox_configure_ifs {
# Iterate over all NET_IF_? variables
local NET_IFS=( "${!NET_IF_@}" )
local NET_IF=""
for NET_IF in "${NET_IFS[@]}"; do
local IF_NUM=${NET_IF##*_}
if [ "${!NET_IF}" = "nat" ]; then
echo "interface $IF_NUM: NAT"
vm_nic_nat "$NODE_NAME" "$IF_NUM"
else
# Host-only network: NET_IF is net name (e.g. API_NET)
# Use corresponding VirtualBox interface (e.g. API_NET_IF)
local HOST_IF="${!NET_IF}_IF"
echo "interface $IF_NUM: host-only ${!HOST_IF}"
vm_nic_hostonly "$NODE_NAME" "$IF_NUM" "${!HOST_IF}"
fi
done
}
# Boot node VM; wait until autostart files are processed and VM is shut down
function _vbox_boot_with_autostart {
local VM=$1
local SSH_PORT=$2
vbox_boot "$VM"
# Wait for ssh connection and execute scripts in autostart directory
# (for wbatch, osbashauto does the processing instead)
${WBATCH:+:} ssh_process_autostart "$SSH_PORT" &
wait_for_autofiles
echo >&2 "VM \"$VM\": autostart files executed"
}
# Create a new node VM and run basic configuration scripts
function vm_init_node {
NODE_NAME=$1
vm_create "$NODE_NAME"
# Set VM_MEM in config/config.NODE_NAME to override
vm_mem "$NODE_NAME" "${VM_MEM:-512}"
# Set VM_CPUS in config/config.NODE_NAME to override
vm_cpus "$NODE_NAME" "${VM_CPUS:-1}"
_vbox_configure_ifs
# Port forwarding
if [ -n "${VM_SSH_PORT:-}" ]; then
vm_port "$NODE_NAME" ssh "$VM_SSH_PORT" 22
fi
if [ -n "${VM_WWW_PORT:-}" ]; then
vm_port "$NODE_NAME" http "$VM_WWW_PORT" 80
fi
vm_add_share "$NODE_NAME" "$SHARE_DIR" "$SHARE_NAME"
vm_attach_disk_multi "$NODE_NAME" "$BASE_DISK"
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Rename to pass the node name to the script
autostart_and_rename osbash init_xxx_node.sh "init_${NODE_NAME}_node.sh"
}
function vm_build_node {
# XXX Run this function in sub-shell to protect our caller's environment
# (which might be _our_ enviroment if we get called again)
(
NODE_NAME=$1
source "$CONFIG_DIR/config.$NODE_NAME"
${WBATCH:-:} wbatch_begin_node "$NODE_NAME"
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
autostart_reset
autostart_from_config "scripts.$NODE_NAME"
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
${WBATCH:-:} wbatch_end_file
)
}
# vim: set ai ts=4 sw=4 et ft=sh: