Update lds tag script

This commit is contained in:
Arif Ali 2022-04-01 10:04:25 +01:00
parent b6aeb4571b
commit e2dd85c8d7
Signed by: arif
GPG Key ID: 369608FBA1353A70

View File

@ -1,30 +1,46 @@
#!/bin/bash
juju_status=$(mktemp)
juju_models=$(mktemp)
juju status --format json > "${juju_status}"
juju models --format json > "${juju_models}"
for phys_mach in $(jq -rc ".machines | keys[]" "${juju_status}")
do
models=$(jq -r .models[].\"short-name\" "${juju_models}")
az=$(jq -rc ".machines.\"${phys_mach}\".hardware" "${juju_status}" | sed 's/.*availability-zone=//g')
hostname=$(jq -r ".machines.\"${phys_mach}\".hostname" "${juju_status}")
for model in ${models} ; do
landscape-api add-tags-to-computers title:"${hostname}" "${az}"
juju status -m "${model}" --format json > "${juju_status}"
containers=$(jq -rc ".machines.\"${phys_mach}\" | (select(.containers != null ) | .containers | to_entries[] | .value.hostname)" "${juju_status}")
for phys_mach in $(jq -rc ".machines | keys[]" "${juju_status}") ; do
for container in ${containers}
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:"${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
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
done
done