Roger Luethi 06fe3a3e84 labs: add snapshot/boot commands to config/scripts.* handler
This patch adds the ability for osbash to understand boot and
snapshot commands in config/scripts.* files.

The syntax for running scripts within the VM remains:

<dircode> <script_name>

For the new commands, it is:
boot
snapshot "Description for snapshot"

The Vagrant-side of the code will simply ignore these commands.

get_script_paths_from_config has been removed and merged into the
execution routine for osbash and Vagrant, respectively.

This changeset puts only the functionality in place. It is going to be
used by a subsequent patch.

Implements: blueprint openstack-training-labs
Change-Id: I2213125715e4cdf4cd2b4f501f3c216e2474b465
2014-08-09 17:48:52 +02:00

44 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -o errexit
# Shell provisioning script is renamed and copied to /tmp before being run as
# root
TOP_DIR=/vagrant
source "$TOP_DIR/config/paths"
source "$LIB_DIR/functions.guest"
clean_dir "$LOG_DIR"
exec_logpath "$LOG_DIR/$HOSTNAME.log"
function vagrant_start_from_config {
local config_file=$1
local config_path=$CONFIG_DIR/$config_file
if [ ! -f "$config_path" ]; then
echo >&2 "Config file not found: $config_file"
return 1
fi
while read -r field_1 field_2; do
if [[ $field_1 =~ ^# ]]; then
# Skip lines that are commented out
continue
elif [[ "$field_1" == "boot" || "$field_1" == "snapshot" ]]; then
# Skip osbash commands, Vagrant ignores them
continue
else
local dir="$(src_dir_code_to_dir "$field_1")"
local scr_path=$dir/$field_2
echo "$scr_path"
as_root_exec_script "$scr_path"
fi
done < "$config_path"
}
# The Vagrantfile uses Ubuntu
for config_file in "scripts.nodeinit_vagrant" "scripts.ubuntu" "scripts.$HOSTNAME"; do
echo "Config file $config_file"
vagrant_start_from_config "$config_file"
done