Created
June 2, 2020 22:24
-
-
Save vernhart/2d39b864ec8f60cc5bd72d7089bb63a7 to your computer and use it in GitHub Desktop.
Parse the generated output from the fce magpie layer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# The magpie layer of the fce produces a magpie.json file. | |
# Unfortunately, the file contains the unit numbers, not the hostnames. | |
# And since the model is destroyed at the end, we have to parse logs | |
# to determine what machines had what results. | |
#- name: magpie | |
# type: magpie_maas | |
# parent: juju_maas_controller | |
# config: | |
# juju_model: magpie | |
# oam-space: oam-space | |
if [ ! -e generated/foundation.log ]; then | |
echo ERROR: generated/foundation.log not found. | |
echo Script should be run in deployment directory. | |
fi | |
# find last magpie layer build in log | |
begin=$(awk '/Started building layer: magpie/{print FNR}' generated/foundation.log | tail -1) | |
loglines=$(awk "NR == $begin,/Finished building layer: magpie/" generated/foundation.log) | |
declare -A jujumachines="( $(echo "$loglines" | awk '/^[0-9]* /{print "["$1"]="$4}') )" | |
declare -a order=( $(echo "$loglines" | grep -m 1 Deploying.*to.machines | sed 's/.*\[//; s/[^0-9 ]//g;') ) | |
declare -a magpiemachines | |
for i in ${!order[@]}; do | |
magpiemachines[$i]=${jujumachines[${order[$i]}]} | |
done | |
# change the output of jq to be simpler and tab delimited | |
sedexp='s/^..magpie-\([^\/]*\)\(\/[0-9]*\)","\([^"]*\)"\]/\1\t\2\t\3/;' | |
for (( i=${#magpiemachines[@]}-1; i>=0; i-- )); do | |
# then replace the unit numbers with the machine names | |
sedexp+="s/\\/$i/${magpiemachines[$i]}/;" | |
done | |
jq -rc '.[]| keys[] as $k | [$k, .[$k].iperf]' generated/magpie/magpie.json | | |
sed -e "$sedexp" | sort |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment