useful_scripts/do_lds_azs.sh

47 lines
1.6 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
juju_status=$(mktemp)
2022-04-01 09:04:25 +00:00
juju_models=$(mktemp)
2022-04-01 09:04:25 +00:00
juju models --format json > "${juju_models}"
2022-04-01 09:04:25 +00:00
models=$(jq -r .models[].\"short-name\" "${juju_models}")
2022-04-01 09:04:25 +00:00
for model in ${models} ; do
2022-04-01 09:04:25 +00:00
juju status -m "${model}" --format json > "${juju_status}"
2022-04-01 09:04:25 +00:00
for phys_mach in $(jq -rc ".machines | keys[]" "${juju_status}") ; do
2022-04-01 09:04:25 +00:00
az=$(jq -rc ".machines.\"${phys_mach}\".hardware" "${juju_status}" | sed 's/.*availability-zone=//g')
hostname=$(jq -r ".machines.\"${phys_mach}\".hostname" "${juju_status}")
2022-04-01 09:04:25 +00:00
landscape-api add-tags-to-computers title:"${hostname}" "${az}"
landscape-api add-tags-to-computers title:"${hostname}" "${model}-model"
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}"
landscape-api add-tags-to-computers title:"${container}" "${model}-model"
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
# Tags that have been grabbed from MAAS
tags=$(jq .machines.\""${phys_mach}"\".hardware "${juju_status}" | sed 's/.*tags=\(.*\)\ .*/\1/g' | tr "," " ")
for tag in ${tags} ; do
landscape-api add-tags-to-computers title:"${hostname}" "${tag}"
done
done
2022-04-01 09:04:25 +00:00
done