From bd52a83713725a58ebc807caf8fa730e6f7b274b Mon Sep 17 00:00:00 2001 From: Roger Luethi Date: Tue, 19 Aug 2014 14:55:52 +0200 Subject: [PATCH] labs: new cmd syntax for config/scripts.* This changeset introduces a new syntax for commands in the config/scripts.* files. Command lines start with "cmd " followed by a command (such as boot or snapshot) and its arguments (if any). This allows us to easily recognize command lines anywhere without having to keep a complete command list. Implements: blueprint openstack-training-labs Change-Id: I7a52476f5b9ba24c2746667b5a0b23b4b73d2e87 --- labs/config/scripts.compute | 6 ++--- labs/config/scripts.controller | 8 +++--- labs/config/scripts.network | 6 ++--- labs/config/scripts.nodeinit_osbash | 6 ++--- labs/lib/osbash/functions.host | 40 +++++++++++++++++++++-------- labs/scripts/vagrant/run_scripts.sh | 2 +- 6 files changed, 43 insertions(+), 25 deletions(-) diff --git a/labs/config/scripts.compute b/labs/config/scripts.compute index 808262ce..7c3ac071 100644 --- a/labs/config/scripts.compute +++ b/labs/config/scripts.compute @@ -2,6 +2,6 @@ scripts setup_nova_compute.sh scripts setup_neutron_compute.sh scripts shutdown.sh -boot -wait_for_shutdown -snapshot "pre-installed" +cmd boot +cmd wait_for_shutdown +cmd snapshot "pre-installed" diff --git a/labs/config/scripts.controller b/labs/config/scripts.controller index 122a9279..a09782cf 100644 --- a/labs/config/scripts.controller +++ b/labs/config/scripts.controller @@ -12,7 +12,7 @@ scripts config_external_network.sh scripts config_demo_user.sh scripts config_tenant_network.sh scripts shutdown.sh -boot -wait_for_shutdown -snapshot "pre-installed" -boot +cmd boot +cmd wait_for_shutdown +cmd snapshot "pre-installed" +cmd boot diff --git a/labs/config/scripts.network b/labs/config/scripts.network index 032eb6ed..f651807b 100644 --- a/labs/config/scripts.network +++ b/labs/config/scripts.network @@ -1,6 +1,6 @@ # Scripts for network node scripts setup_neutron_network.sh scripts shutdown.sh -boot -wait_for_shutdown -snapshot "pre-installed" +cmd boot +cmd wait_for_shutdown +cmd snapshot "pre-installed" diff --git a/labs/config/scripts.nodeinit_osbash b/labs/config/scripts.nodeinit_osbash index 64c5f579..2b6969e5 100644 --- a/labs/config/scripts.nodeinit_osbash +++ b/labs/config/scripts.nodeinit_osbash @@ -3,6 +3,6 @@ scripts etc_hosts.sh osbash enable_vagrant_ssh_keys.sh #osbash wait_debug.sh scripts shutdown.sh -boot -wait_for_shutdown -snapshot "network_configured" +cmd boot +cmd wait_for_shutdown +cmd snapshot "network_configured" diff --git a/labs/lib/osbash/functions.host b/labs/lib/osbash/functions.host index 48a040a9..477e8a1c 100644 --- a/labs/lib/osbash/functions.host +++ b/labs/lib/osbash/functions.host @@ -252,6 +252,33 @@ function autostart { done } +# Parse command and arguments after a "cmd" token in config/scripts.* +function command_from_config { + local cmd_string=( $1 ) + local cmd=${cmd_string[0]} + case "$cmd" in + boot) + # 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" + ;; + snapshot) + # Format: snapshot + local shot_name=${cmd_string[1]} + echo >&2 vm_snapshot "$NODE_NAME" "$shot_name" + vm_snapshot "$NODE_NAME" "$shot_name" + ;; + wait_for_shutdown) + echo >&2 vm_wait_for_shutdown "$NODE_NAME" + vm_wait_for_shutdown "$NODE_NAME" + ;; + *) + echo >&2 "Error: invalid cmd: $cmd" + exit 1 + ;; + esac +} + # Parse config/scripts.* configuration files function autostart_from_config { local config_file=$1 @@ -271,17 +298,8 @@ function autostart_from_config { 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 - echo >&2 vm_snapshot "$NODE_NAME" "$field_2" - vm_snapshot "$NODE_NAME" "$field_2" - elif [ "$field_1" == "wait_for_shutdown" ]; then - echo >&2 vm_wait_for_shutdown "$NODE_NAME" - vm_wait_for_shutdown "$NODE_NAME" + elif [ "$field_1" == "cmd" ]; then + command_from_config "$field_2" else # Queue a script for autostart # Format: diff --git a/labs/scripts/vagrant/run_scripts.sh b/labs/scripts/vagrant/run_scripts.sh index 9be19b3a..3f1e37f4 100755 --- a/labs/scripts/vagrant/run_scripts.sh +++ b/labs/scripts/vagrant/run_scripts.sh @@ -24,7 +24,7 @@ function vagrant_start_from_config { if [[ $field_1 =~ ^# ]]; then # Skip lines that are commented out continue - elif [[ "$field_1" == "boot" || "$field_1" == "snapshot" ]]; then + elif [[ "$field_1" = cmd ]]; then # Skip osbash commands, Vagrant ignores them continue else