examples/surreal/deploy.sh

43 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd $script_dir
set -e
export FORMAT=YAML
vms=()
vm_count=0
new_vm() {
local vm_name="$1"
local vm_id="vm$vm_count"
(( vm_count++ )) || true
local vm_install_data="tmp/vms/${vm_name}_install.yaml"
local vm_inspect_data="tmp/vms/${vm_name}_inspect.yaml"
vm_node_ip=$(grep 'ip: ' $vm_install_data | awk '{ print $2 }')
vm_port=$(grep 'port: ' $vm_install_data | cut -d "'" -f2)
declare -gA "$vm_id"
eval "$vm_id[id]=$1"
eval "$vm_id[name]=$vm_name"
eval "$vm_id[port]=$vm_port"
eval "$vm_id[node_ip]=$vm_node_ip"
eval "$vm_id[private_ip]=10.254.254.$vm_count"
vms+=("$vm_id")
}
for vm_install_file in tmp/vms/*_install.yaml; do
vm_name=$(echo $vm_install_file | cut -d '/' -f3 | cut -d '_' -f1)
new_vm $vm_name
done
for vm_object in "${vms[@]}"; do
declare -n vm_ref="$vm_object"
printf 'id=%s name=%s port=%s node_ip=%s private_ip=%s\n' \
"${vm_ref[id]}" "${vm_ref[name]}" "${vm_ref[port]}" \
"${vm_ref[node_ip]}" "${vm_ref[private_ip]}"
done