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
This commit is contained in:
parent
2d8e2be5a4
commit
06fe3a3e84
@ -113,30 +113,5 @@ function src_dir_code_to_dir {
|
||||
;;
|
||||
esac
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
# Returns list of enabled scripts (to disable, comment out with #)
|
||||
|
||||
function get_script_paths_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
|
||||
local DIR_CODE=""
|
||||
local NAME=""
|
||||
while read -r DIR_CODE NAME; do
|
||||
if [[ $DIR_CODE =~ ^# ]]; then
|
||||
# Skip lines that are commented out
|
||||
continue
|
||||
else
|
||||
local DIR="$(src_dir_code_to_dir "$DIR_CODE")"
|
||||
local SCR_PATH=$DIR/$NAME
|
||||
echo "$SCR_PATH"
|
||||
fi
|
||||
done < "$CONFIG_PATH"
|
||||
}
|
||||
|
||||
# vim: set ai ts=4 sw=4 et ft=sh:
|
||||
|
@ -251,13 +251,37 @@ function autostart {
|
||||
done
|
||||
}
|
||||
|
||||
# Parse config/scripts.* configuration files
|
||||
function autostart_from_config {
|
||||
local CONFIG_FILE=$1
|
||||
local config_file=$1
|
||||
local config_path=$CONFIG_DIR/$config_file
|
||||
|
||||
log_autostart_source "$CONFIG_FILE"
|
||||
get_script_paths_from_config "$CONFIG_FILE" | while read SCR_PATH; do
|
||||
_autostart_queue "$SCR_PATH"
|
||||
done
|
||||
if [ ! -f "$config_path" ]; then
|
||||
echo >&2 "Config file not found: $config_file"
|
||||
return 1
|
||||
fi
|
||||
|
||||
log_autostart_source "$config_file"
|
||||
while read -r field_1 field_2; do
|
||||
if [[ $field_1 =~ ^# ]]; then
|
||||
# Skip lines that are commented out
|
||||
continue
|
||||
elif [ "$field_1" == "boot" ]; then
|
||||
# Boot with queued autostart files now, wait for shutdown
|
||||
echo >&2 _vbox_boot_with_autostart "$NODE_NAME" "$VM_SSH_PORT"
|
||||
_vbox_boot_with_autostart "$NODE_NAME" "$VM_SSH_PORT"
|
||||
elif [ "$field_1" == "snapshot" ]; then
|
||||
# Format: snapshot "Description for snapshot"
|
||||
echo >&2 vm_snapshot "$NODE_NAME" "$field_2"
|
||||
vm_snapshot "$NODE_NAME" "$field_2"
|
||||
else
|
||||
# Queue a script for autostart
|
||||
# Format: <dircode> <script_name>
|
||||
# Note: _autostart_queue takes care of dircode
|
||||
echo >&2 _autostart_queue "$field_1/$field_2"
|
||||
_autostart_queue "$field_1/$field_2"
|
||||
fi
|
||||
done < "$config_path"
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
@ -82,9 +82,6 @@ function vm_snapshot {
|
||||
local VM_NAME=$1
|
||||
local SHOT_NAME=$2
|
||||
|
||||
# Blanks would fail in Windows batch files; space becomes underscore
|
||||
SHOT_NAME="${SHOT_NAME// /_}"
|
||||
|
||||
$VBM snapshot "$VM_NAME" take "$SHOT_NAME"
|
||||
# VirtualBox VM needs a break before taking new commands
|
||||
vbox_sleep 1
|
||||
|
@ -11,11 +11,33 @@ clean_dir "$LOG_DIR"
|
||||
|
||||
exec_logpath "$LOG_DIR/$HOSTNAME.log"
|
||||
|
||||
# The Vagrantfile uses precise, so we know it's Ubuntu
|
||||
for CONFIG_FILE in "scripts.nodeinit_vagrant" "scripts.ubuntu" "scripts.$HOSTNAME"; do
|
||||
echo "Config file $CONFIG_FILE"
|
||||
get_script_paths_from_config "$CONFIG_FILE" | while read SCR_PATH; do
|
||||
echo "$SCR_PATH"
|
||||
as_root_exec_script "$SCR_PATH"
|
||||
done
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user