Skip to content

Instantly share code, notes, and snippets.

@ThinGuy
Created March 22, 2018 00:35
Show Gist options
  • Save ThinGuy/01c5c0633bd7c633485a859b649910ce to your computer and use it in GitHub Desktop.
Save ThinGuy/01c5c0633bd7c633485a859b649910ce to your computer and use it in GitHub Desktop.
Rolling Openstack Upgrade with Juju
juju-upgrade-openstack() {
export SERIES=xenial
export RELEASE=pike
export CURRENT_MODEL=$(juju models|awk '/*/{gsub(/*/,"");print $1}')
printf "\e[2GGetting list of applications from juju model \"${CURRENT_MODEL}\" \n"
declare -ag JUJU_APPS=($(juju 2>/dev/null status --format=json|jq 2>/dev/null -r '.applications | to_entries[].key'))
printf "%s\n" ${JUJU_APPS[@]}
printf "\e[2GGetting list of openstack applications from juju model \"${CURRENT_MODEL}\" \n"
declare -ag UPGRADE_APPS=($(for APP in ${JUJU_APPS[@]};do [[ -n $(juju 2>/dev/null config ${APP} action-managed-upgrade) ]] && echo ${APP};done))
printf "%s\n" ${UPGRADE_APPS[@]}
for APP in ${UPGRADE_APPS[@]};do
printf "\e[2G - Setting action-managed-upgrade True for ${APP}\n"
juju 2>/dev/null config ${APP} action-managed-upgrade=true
done
for APP in ${UPGRADE_APPS[@]};do
printf "\e[2G - Current openstack-origin setting for ${APP}: "
juju 2>/dev/null config ${APP} openstack-origin
printf "\e[4G - Setting openstack-origin to cloud:${SERIES}-${RELEASE} for ${APP}\n"
juju 2>/dev/null config ${APP} openstack-origin="cloud:$SERIES-$RELEASE"
done
declare -ag UPGRADE_UNITS=($(
for APP in ${UPGRADE_APPS[@]};do
juju 2>/dev/null status --format=json|jq 2>/dev/null -r '.applications["'${APP}'"]|.units|to_entries[].key'
done
))
printf "\e[2GStarting rolling upgrade on juju model \"${CURRENT_MODEL}\" \n"
for U in ${UPGRADE_UNITS[@]};do
printf "\e[4G - Upgrading ${U} to ${RELEASE}\n"
juju run-action ${U} openstack-upgrade --wait
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment