Add script to extract AZs from juju to Landscape

This commit is contained in:
Arif Ali 2022-03-23 15:29:01 +00:00
parent 4210a3b9e9
commit f1d511a082
Signed by: arif
GPG Key ID: 369608FBA1353A70

30
do_lds_azs.sh Executable file
View File

@ -0,0 +1,30 @@
#!/bin/bash
juju_status=$(mktemp)
juju status --format json > "${juju_status}"
for phys_mach in $(jq -rc ".machines | keys[]" "${juju_status}")
do
az=$(jq -rc ".machines.\"${phys_mach}\".hardware" "${juju_status}" | sed 's/.*availability-zone=//g')
hostname=$(jq -r ".machines.\"${phys_mach}\".hostname" "${juju_status}")
landscape-api add-tags-to-computers title:"${hostname}" "${az}"
containers=$(jq -rc ".machines.\"${phys_mach}\" | (select(.containers != null ) | .containers | to_entries[] | .value.hostname)" "${juju_status}")
for container in ${containers}
do
landscape-api add-tags-to-computers title:"${container}" "${az}"
if [[ "${container}" == *"lxd"* ]] ; then
landscape-api add-tags-to-computers title:"${container}" lxd
fi
if [[ "${container}" == *"kvm"* ]] ; then
landscape-api add-tags-to-computers title:"${container}" kvm
fi
done
done